Re: Query lenta

From: Lennin Caro <lennin(dot)caro(at)yahoo(dot)com>
To: FRANCISCO JOSE PALAO VILLANUEVA <fjpv_2000(at)yahoo(dot)es>, "pgsql-es-ayuda(at)postgresql(dot)org" <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Query lenta
Date: 2014-02-11 19:11:11
Message-ID: 1392145871.82926.YahooMailNeo@web161004.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

On Tuesday, February 11, 2014 2:01 PM, FRANCISCO JOSE PALAO VILLANUEVA <fjpv_2000(at)yahoo(dot)es> wrote:

Hola haber si me pueden ayudar:

Tengo una relación maestro detalle entre cabeceras de ventas y detalles de ventas. Tengo un view 'reimp' que enlaza las dos tablas mediante cod_factura y cod_oficina.

Si ejecuto un select sum(adv_q*adv_up) from reimp where av_d >= '01/12/2013' hace un escaneado secuencial de la tabla detalles
La ejecución puede demorarse hasta en 105 segundos ???, sin embargo si hago
 select sum(adv_q*adv_up) from reimp where av_d = '01/12/2013' entonces usa índices de tabla detalles y es casi inmediato si hago un between y las filas están ya cacheadas también usa índices sino no. Les pongo el explain haber si me pueden ayudar:

'Aggregate  (cost=545557.78..545557.79 rows=1 width=10)'
'  ->  Hash Join  (cost=262267.42..544984.31 rows=114695 width=10)'
'        Hash Cond: ((t1.av_id = t2.av_id) AND (t1.av_ov = t2.av_ov))'
'        ->  Index Scan using avavd on a_v t1  (cost=0.42..5248.01 rows=114546 width=6)'
'              Index Cond: (av_d >= '2013-12-01'::date)'
'        ->  Hash  (cost=135397.40..135397.40 rows=6380840 width=16)'
'              ->  Seq Scan on a_dv t2  (cost=0.00..135397.40 rows=6380840 width=16)'

La tabla detalles tiene índices sobre (av_id,av_ov), sobre av_id  y sobre av_ov. La tabla cabeceras los mismos, además de otros campos.

Saludos
Que tipo de dato es el de la columna av_d y por cierto que version de postgresql tienes.

 
---------------------------------------------------------------------------------------
Ing. Lennin Caro Pérez
Usuario:GNU/LINUX
PHP Developer
PostgreSQL DBA
Oracle DBA
Linux counter id 474393

In response to

  • Query lenta at 2014-02-11 18:30:06 from FRANCISCO JOSE PALAO VILLANUEVA

Responses

  • Re: Query lenta at 2014-02-11 19:44:59 from FRANCISCO JOSE PALAO VILLANUEVA

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message FRANCISCO JOSE PALAO VILLANUEVA 2014-02-11 19:44:59 Re: Query lenta
Previous Message FRANCISCO JOSE PALAO VILLANUEVA 2014-02-11 18:30:06 Query lenta