From: | "Vida Luz Arista" <vida(dot)arista(at)ideay(dot)net(dot)ni> |
---|---|
To: | "'Alvaro Herrera'" <alvherre(at)alvh(dot)no-ip(dot)org> |
Cc: | <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | RE: Tuning auna consulta |
Date: | 2009-07-16 00:42:44 |
Message-ID: | !&!AAAAAAAAAAAYAAAAAAAAAOO6ezNGTUlAlozSL92lwK7CgAAAEAAAACoyzkjmwytOthaoM3Z8d4kBAAAAAA==@ideay.net.ni |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Ok, les envió el explain analyze
QUERY PLAN
Unique (cost=24430.61..24459.29 rows=675 width=433) (actual
time=9603.559..11206.646 rows=11601 loops=1)
-> Sort (cost=24430.61..24432.29 rows=675 width=433) (actual
time=9603.553..11113.330 rows=30132 loops=1)
Sort Key: emp.nombre, emp.id_empresa, (subplan), CASE WHEN (ta.descripcion
IS NOT NULL) THEN ta.descripcion ELSE 'Ninguna'::character varying END,
tca.descripcion, dep.descripcion, mun.nombre, CASE WHEN (dis.nombre IS NOT
NULL) THEN dis.nombre ELSE 'Ninguno'::character varying END, CASE WHEN
(emp.direccion IS NOT NULL) THEN emp.direccion ELSE 'Ninguno'::character
varying END, CASE WHEN (emp.telefono IS NOT NULL) THEN emp.telefono ELSE
'Ninguno'::character varying END, CASE WHEN (us.fax IS NOT NULL) THEN us.fax
ELSE 'Ninguno'::character varying END, CASE WHEN (emp.email IS NOT NULL)
THEN emp.email ELSE 'Ninguno'::character varying END, CASE WHEN
(lic.consec_constancia IS NOT NULL) THEN lic.consec_constancia ELSE 0 END,
CASE WHEN emp.activo THEN emp.fecha_apertura WHEN (NOT emp.activo) THEN
emp.fecha_cierre ELSE emp.fecha_cierre END, CASE WHEN emp.activo THEN
'Activo'::character varying WHEN (NOT emp.activo) THEN tc.descripcion ELSE
'Inactivo'::character varying END, CASE WHEN (lic.num_licencia IS NOT NULL)
THEN lic.num_licencia ELSE 'Ninguno'::character varying END
-> HashAggregate (cost=403.29..24398.89 rows=675 width=433) (actual
time=6585.911..8016.053 rows=30132 loops=1)
-> Hash Left Join (cost=225.67..372.92 rows=675 width=433) (actual
time=16.911..3678.086 rows=603936 loops=1)
Hash Cond: (lic.id_estado_pago = ep.id_estado_pago)
-> Hash Left Join (cost=224.62..369.27 rows=675 width=437) (actual
time=16.872..2351.792 rows=603936 loops=1)
Hash Cond: ((ea.id_actividad)::text = (paremp.id_actividad)::text)
-> Hash Left Join (cost=198.20..301.87 rows=185 width=437) (actual
time=16.633..773.906 rows=298503 loops=1)
Hash Cond: ((ea.id_actividad)::text = (cemp.id_actividad)::text)
-> Hash Left Join (cost=196.07..298.36 rows=185 width=437) (actual
time=16.376..120.104 rows=11601 loops=1)
Hash Cond: (emp.departamento = dep.id_dept)
-> Hash Left Join (cost=194.64..296.06 rows=185 width=412) (actual
time=16.286..90.147 rows=11601 loops=1)
Hash Cond: (emp.departamento = mun.id_dept)
-> Hash Left Join (cost=190.16..290.19 rows=185 width=369) (actual
time=15.860..69.014 rows=1289 loops=1)
Hash Cond: (emp.distrito = dis.id)
-> Hash Left Join (cost=189.01..288.27 rows=185 width=341) (actual
time=15.799..65.525 rows=1289 loops=1)
Hash Cond: (emp.id_situacion = s.id_situacion)
-> Hash Left Join (cost=187.92..286.45 rows=185 width=345) (actual
time=15.748..61.870 rows=1289 loops=1)
Hash Cond: (emp.id_empresa = lic.id_empresa)
-> Hash Left Join (cost=159.21..235.89 rows=185 width=305) (actual
time=14.856..57.671 rows=1289 loops=1)
Hash Cond: (ce.id_tipo_cierre = tc.id)
-> Nested Loop Left Join (cost=120.18..190.24 rows=29 width=285) (actual
time=14.805..54.489 rows=1289 loops=1)
-> Hash Left Join (cost=120.18..179.39 rows=29 width=257) (actual
time=14.777..35.892 rows=1289 loops=1)
Hash Cond: ((ea.id_actividad)::text = (ta.id_actividad)::text)
-> Hash Left Join (cost=118.30..177.31 rows=29 width=225) (actual
time=14.590..31.422 rows=1289 loops=1)
Hash Cond: ((ea.id_categoria)::text = (tca.id_tipo_categoria)::text)
-> Hash Left Join (cost=115.03..173.74 rows=29 width=225) (actual
time=14.233..25.553 rows=1289 loops=1)
Hash Cond: (emp.id_empresa = ce.id_empresa)
-> Hash Join (cost=94.46..151.30 rows=29 width=221) (actual
time=14.162..22.645 rows=1289 loops=1)
Hash Cond: (ea.id_empresa = emp.id_empresa)
-> Seq Scan on empresa_actividad ea (cost=0.00..50.94 rows=1497 width=68)
(actual time=0.023..3.577 rows=1504 loops=1)
Filter: (NOT principal)
-> Hash (cost=94.08..94.08 rows=30 width=161) (actual time=14.107..14.107
rows=1289 loops=1)
-> Hash Join (cost=64.31..94.08 rows=30 width=161) (actual
time=6.433..11.320 rows=1289 loops=1)
Hash Cond: (ue.id_empresa = emp.id_empresa)
-> Seq Scan on usuario_empresa ue (cost=0.00..23.89 rows=1489 width=8)
(actual time=0.015..1.421 rows=1495 loops=1)
-> Hash (cost=63.92..63.92 rows=31 width=153) (actual time=6.384..6.384
rows=1299 loops=1)
-> Seq Scan on empresa emp (cost=0.00..63.92 rows=31 width=153) (actual
time=0.044..3.588 rows=1299 loops=1)
Filter: (((nombre)::text ~~* '%%'::text) AND ((id_situacion)::text ~~*
'%%'::text) AND (departamento = ANY ('{1,2,3,4}'::integer[])))
-> Hash (cost=14.70..14.70 rows=470 width=8) (actual time=0.039..0.039
rows=11 loops=1)
-> Seq Scan on cierre_empresa ce (cost=0.00..14.70 rows=470 width=8)
(actual time=0.006..0.017 rows=11 loops=1)
-> Hash (cost=2.01..2.01 rows=101 width=36) (actual time=0.320..0.320
rows=101 loops=1)
-> Seq Scan on tipo_categoria tca (cost=0.00..2.01 rows=101 width=36)
(actual time=0.010..0.121 rows=101 loops=1)
-> Hash (cost=1.39..1.39 rows=39 width=36) (actual time=0.156..0.156
rows=39 loops=1)
-> Seq Scan on tipo_actividad ta (cost=0.00..1.39 rows=39 width=36)
(actual time=0.006..0.052 rows=39 loops=1)
-> Index Scan using usuario_new_pkey on usuario us (cost=0.00..0.36 rows=1
width=36) (actual time=0.006..0.009 rows=1 loops=1289)
Index Cond: (us.id_usuario = ue.id_usuario)
-> Hash (cost=22.90..22.90 rows=1290 width=28) (actual time=0.021..0.021
rows=3 loops=1)
-> Seq Scan on tipo_cierre tc (cost=0.00..22.90 rows=1290 width=28)
(actual time=0.003..0.006 rows=3 loops=1)
-> Hash (cost=17.76..17.76 rows=876 width=44) (actual time=0.857..0.857
rows=297 loops=1)
-> Seq Scan on licencias lic (cost=0.00..17.76 rows=876 width=44) (actual
time=0.014..0.440 rows=297 loops=1)
-> Hash (cost=1.04..1.04 rows=4 width=4) (actual time=0.022..0.022 rows=4
loops=1)
-> Seq Scan on situacion s (cost=0.00..1.04 rows=4 width=4) (actual
time=0.004..0.009 rows=4 loops=1)
-> Hash (cost=1.07..1.07 rows=7 width=36) (actual time=0.033..0.033 rows=7
loops=1)
-> Seq Scan on distrito dis (cost=0.00..1.07 rows=7 width=36) (actual
time=0.004..0.013 rows=7 loops=1)
-> Hash (cost=3.53..3.53 rows=76 width=47) (actual time=0.398..0.398
rows=153 loops=1)
-> Seq Scan on municipio mun (cost=0.00..3.53 rows=76 width=47) (actual
time=0.014..0.189 rows=153 loops=1)
Filter: activo
-> Hash (cost=1.19..1.19 rows=19 width=33) (actual time=0.059..0.059
rows=17 loops=1)
-> Seq Scan on departamento dep (cost=0.00..1.19 rows=19 width=33) (actual
time=0.005..0.024 rows=17 loops=1)
-> Hash (cost=1.50..1.50 rows=50 width=4) (actual time=0.238..0.238
rows=75 loops=1)
-> Seq Scan on cargos_empresa cemp (cost=0.00..1.50 rows=50 width=4)
(actual time=0.007..0.090 rows=75 loops=1)
-> Hash (cost=17.30..17.30 rows=730 width=36) (actual time=0.208..0.208
rows=61 loops=1)
-> Seq Scan on parametros_empresa paremp (cost=0.00..17.30 rows=730
width=36) (actual time=0.007..0.073 rows=61 loops=1)
-> Hash (cost=1.02..1.02 rows=2 width=4) (actual time=0.018..0.018 rows=2
loops=1)
-> Seq Scan on estado_pago ep (cost=0.00..1.02 rows=2 width=4) (actual
time=0.004..0.006 rows=2 loops=1)
SubPlan
-> Nested Loop (cost=6.24..35.54 rows=1 width=32) (actual
time=0.030..0.038 rows=1 loops=30132)
-> Hash Join (cost=6.24..27.26 rows=1 width=36) (actual time=0.019..0.023
rows=1 loops=30132)
Hash Cond: ((ea2.id_actividad)::text = (ta2.id_actividad)::text)
-> Bitmap Heap Scan on empresa_actividad ea2 (cost=4.36..25.34 rows=7
width=36) (actual time=0.010..0.012 rows=1 loops=30132)
Recheck Cond: ($0 = id_empresa)
Filter: principal
-> Bitmap Index Scan on empresa_actividad_new_idx (cost=0.00..4.36 rows=15
width=0) (actual time=0.006..0.006 rows=2 loops=30132)
Index Cond: ($0 = id_empresa)
-> Hash (cost=1.39..1.39 rows=39 width=36) (actual time=0.153..0.153
rows=39 loops=1)
-> Seq Scan on tipo_actividad ta2 (cost=0.00..1.39 rows=39 width=36)
(actual time=0.009..0.055 rows=39 loops=1)
-> Index Scan using empresa_new_pkey on empresa e2 (cost=0.00..8.27 rows=1
width=4) (actual time=0.006..0.008 rows=1 loops=30132)
Index Cond: (id_empresa = $0)
Total runtime: 11233.479 ms
-----Mensaje original-----
De: Alvaro Herrera [mailto:alvherre(at)alvh(dot)no-ip(dot)org]
Enviado el: Wednesday, July 15, 2009 4:31 PM
Para: Vida Luz Arista
CC: pgsql-es-ayuda(at)postgresql(dot)org
Asunto: Re: [pgsql-es-ayuda] Tuning auna consulta
Vida Luz Arista escribió:
> Tengo un problema con una consulta, uno de los chicos de desarrollo, tiene
> una consulta que se hace pesada, y esta tarde como unos 2 minutos, lo más
> extraño es que no hay muchos registros y estos es demasiado tiempo sobre
> todo porque aun son pocos registros, me asusta porque cuando la BD crezca
> esto va ser demasiado tiempo, en esta consulta se trabaja con 15 tablas,
la
> consulta se las dejo y les pido sugerencias para mejorar la consulta o si
es
> posible partirla.
¿Qué version de Postgres? Por favor muestra el EXPLAIN ANALYZE de la
consulta.
--
Alvaro Herrera
http://www.flickr.com/photos/alvherre/
"Para tener más hay que desear menos"
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2009-07-16 01:50:54 | Re: Tuning auna consulta |
Previous Message | Miguel Beltran R. | 2009-07-16 00:33:45 | Re: Fundamento teorico del rendimiento de una vista |