Re: Crear los indices adecuados

From: Leonel <lnunez(at)gmail(dot)com>
To: "Vida Luz" <vlal(at)ns(dot)ideay(dot)net(dot)ni>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Crear los indices adecuados
Date: 2007-03-23 02:51:20
Message-ID: 33c54f810703221951j7e5fb951j9336937e75eba47f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

On 3/23/07, Vida Luz <vlal(at)ns(dot)ideay(dot)net(dot)ni> wrote:
> Hola a Todos,
>
> Tengo una tabla con muchos campos, ademas que tiene como 3 millones de
> registros, de esas tabla hay 16 campos
> que se usaran de manera combinada para realizar consulta, como son
> muchos query con distintas combinaciones y condicionales, en base al
> ejemplo que les envio, quisiera una buena sugerencia para crear los
> inidice y que la consulta sea liviana, en estos momentos mis tiempos
> son muy altos, El caso es:
>
> Mi tabla es:
>
> linea | character varying(2) |
> anio | character varying(4) |
> semestre | character varying(1) |
> trimestre | character varying(1) |
> mes | character varying(2) |
> dia | character varying(2) |
> fecha | character varying(8) |
> anio_ser | character varying(4) |
> semestre_ser | character varying(1) |
> trimestre_ser | character varying(1) |
> mes_ser | character varying(2) |
> dpto_cod | character varying(3) |
> dpto_desc | character varying(30) |
> mun_cod | character varying(3) |
> mun_desc | character varying(30) |
> geren_cod | character varying(6) |
> geren_desc | character varying(30) |
> gerente | character varying(30) |
> region_cod | character varying(7) |
> region_desc | character varying(30) |
> super_cod | character varying(8) |
> super_desc | character varying(30) |
> ruta | character varying(20) |
> punto_cod | character varying(3) |
> punto_desc | character varying(30) |
> neg_cod | character varying(3) |
> neg_desc | character varying(30) |
> cliente_cod | integer |
> cliente_desc | character varying(40) |
> grupo_cod | character varying(3) |
> grupo_desc | character varying(30) |
> div_cod | character varying(3) |
> div_desc | character varying(30) |
> marca_cod | character varying(3) |
> marca_desc | character varying(30) |
> pres_cod | character varying(3) |
> pres_desc | character varying(30) |
> tam_cod | character varying(3) |
> tam_desc | character varying(30) |
> prod_cod | character varying(25) |
> prod_desc | character varying(30) |
> vta_cajas | numeric(31,7) |
> vta_divisa | numeric(31,7) |
>
> Necesito consultar por ejemplo
> Query 1
> =======
> SELECT
> V.geren_cod,V.geren_desc,V.ruta,V.ruta,V.cliente_cod,V.cliente_desc,V.anio,V.anio,SUM(V.vta_cajas)
> as
> cajas,SUM(V.vta_divisa) as divisa FROM dm.venta V WHERE V.anio
> IN(2007,2006,2005) GROUP BY
> V.geren_cod,V.geren_desc,V.ruta,V.cliente_cod,V.cliente_desc,V.anio ORDER
> BY
> V.geren_desc,V.geren_cod,V.ruta,V.cliente_desc,V.cliente_cod,V.anio DESC
>
> Query2
> ======
> SELECT
> V.geren_cod,V.geren_desc,V.cliente_cod,V.cliente_desc,V.anio,V.anio,SUM(V.vta_cajas)
> as cajas,SUM(V.vta_divisa) as divisa
> FROM dm.venta V WHERE V.anio IN(2007,2006,2005) GROUP BY
> V.geren_cod,V.geren_desc,V.cliente_cod,V.cliente_desc,V.anio ORDER BY
> V.geren_desc,V.geren_cod,V.cliente_desc,V.cliente_cod,V.anio DESC
>
> Tengo la mas grande donde van casi todos los campos.
>
> explain analyze SELECT
> V.geren_cod,V.geren_desc,V.geren_cod,V.gerente,V.region_cod,V.region_desc,V.super_cod,V.super_desc,V.ruta,V.ruta,V.cliente_cod,V.cliente_desc,V.punto_cod,V.punto_desc,V.neg_cod,V.neg_desc,V.grupo_cod,V.grupo_desc,V.div_cod,V.div_desc,V.marca_cod,V.marca_desc,V.pres_cod,V.pres_desc,V.tam_cod,V.tam_desc,V.prod_cod,V.prod_desc,V.dpto_cod,V.dpto_desc,V.mun_cod,V.mun_desc,V.anio,SUM(V.vta_cajas)
> as cajas,SUM(V.vta_divisa) as divisa FROM dm.venta V WHERE V.anio=2007 or
> V.anio=2006 or V.anio=2005 GROUP BY
> V.geren_cod,V.geren_desc,V.gerente,V.region_cod,V.region_desc,V.super_cod,V.super_desc,V.ruta,V.cliente_cod,V.cliente_desc,V.punto_cod,V.punto_desc,V.neg_cod,V.neg_desc,V.grupo_cod,V.grupo_desc,V.div_cod,V.div_desc,V.marca_cod,V.marca_desc,V.pres_cod,V.pres_desc,V.tam_cod,V.tam_desc,V.prod_cod,V.prod_desc,V.dpto_cod,V.dpto_desc,V.mun_cod,V.mun_desc,V.anio
> ORDER BY
> V.geren_desc,V.geren_cod,V.gerente,V.region_desc,V.region_cod,V.super_desc,V.super_cod,V.ruta,V.cliente_desc,V.cliente_cod,V.punto_desc,V.punto_cod,V.neg_desc,V.neg_cod,V.grupo_desc,V.grupo_cod,V.div_desc,V.div_cod,V.marca_desc,V.marca_cod,V.pres_desc,V.pres_cod,V.tam_desc,V.tam_cod,V.prod_desc,V.prod_cod,V.dpto_desc,V.dpto_cod,V.mun_desc,V.mun_cod,V.anio
> DESC;
>
> QUERY PLAN
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Sort (cost=238008.81..238297.98 rows=115667 width=437) (actual
> time=143460.996..143754.395 rows=211412 loops=1)
> Sort Key: geren_desc, geren_cod, gerente, region_desc, region_cod,
> super_desc, super_cod, ruta, cliente_desc, cliente_cod, punto_desc,
> punto_cod, neg_desc, neg_cod, grupo_desc, grupo_cod, div_desc, div_cod,
> marca_desc, marca_cod, pres_desc, pres_cod, tam_desc, tam_cod, prod_desc,
> prod_cod, dpto_desc, dpto_cod, mun_desc, mun_cod, anio
> -> HashAggregate (cost=226546.43..228281.43 rows=115667 width=437)
> (actual time=17964.950..18908.797 rows=211412 loops=1)
> -> Index Scan using venta_idxanio on venta v
> (cost=0.00..131121.40 rows=1156667 width=437) (actual time=0.139..3269.739
> rows=1405855 loops=1)
> Total runtime: 143944.487 ms
>
>
> Agradeceria sugerencias.
>
> Saludos,
>
>
> ---------------------------(fin del mensaje)---------------------------
> TIP 1: para suscribirte y desuscribirte, visita http://archives.postgresql.org/pgsql-es-ayuda
>

como que de entrada hay que darle una normalizada no ?

--
Leonel

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2007-03-23 03:16:09 Re: Crear los indices adecuados
Previous Message Julio Cesar Sánchez González 2007-03-23 02:38:19 Re: Otro caso de Replicacion