ayuda con optimizacion de consulta

From: Arturo Llanquihuén Martinez <arturo(at)llanquihuen(dot)cl>
To: "Alvaro Herrera" <alvherre(at)dcc(dot)uchile(dot)cl>
Cc: <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: ayuda con optimizacion de consulta
Date: 2004-09-08 18:17:25
Message-ID: 010f01c495d0$1852c3f0$fb0000c0@report
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

hola lista:
soy bastante novato en lo que a bases de datos se refiere, por lo tanto
recurro a su ayuda para que me aconsejen.
bueno para que se hagan la idea, con esta consulta saco la ultima posicion
de cada automovil en un grupo que puede variar,
luego con esta genero un mapa via mapserver por lo cual la consulta debe
hacerse en el menor tiempo posible.

agradeceria sus comentarios:

ya lei alguno mails anteriores referentes a index de los cuales saque alguna
informacion pero no me han resultado los indices que agrego.
otra duda que tengo es, sí creo la tabla con oid es redundante que cree un
campo rut_id como primary key secuencial?
si elimino el primary key puedo marcar el oid como primary key?

agradesco desde ya su ayuda.

CREATE TABLE mm_ruta
(
rut_id int8 NOT NULL DEFAULT nextval('public."mm_ruta_rut_id_seq"'::text),
rut_fecha date NOT NULL,
rut_hora "time" NOT NULL,
rut_velocidad float4 NOT NULL,
rut_heading float4 NOT NULL,
rut_height "varchar"(10),
rut_uni_id "varchar"(4),
rut_eve_id "varchar"(4),
rut_rpv "varchar"(4),
rut_gpstime float4,
rut_age int4,
rut_datasource "varchar"(9),
rut_uni_patente "varchar"(10) NOT NULL,
rut_latlong geometry,
CONSTRAINT mm_ruta_pkey PRIMARY KEY (rut_id),
CONSTRAINT "$1" CHECK ((srid(rut_latlong) = -1)),
CONSTRAINT "$2" CHECK (((geometrytype(rut_latlong) = 'POINT'::text) OR
(rut_latlong IS NULL)))
)
WITH OIDS;

CREATE INDEX index_patente
ON mm_ruta
USING btree
(rut_uni_patente);

la consulta:

select rut_latlong,rut_uni_patente,oid from mm_ruta
where rut_id in (select max(rut_id)
from mm_ruta
group by rut_uni_patente
having rut_uni_patente in
('PK-3513','SA-2633','PH-3317','PF-5050','PT-7837','NT-9872','RU-9034','NS-4
324','RT-2931','RT-8028','RG-5849','RJ-3966','NN-3476','PX-8459','NF-6813','
RT-5803','NG-3852','PE-9118','UE-4205','RZ-9503'))

EXPLAIN

"Seq Scan on mm_ruta (cost=0.00..16336842441.45 rows=162094 width=47)"
" Filter: (subplan)"
" SubPlan"
" -> Materialize (cost=50392.91..50392.91 rows=18744 width=19)"
" -> Aggregate (cost=48987.13..50392.91 rows=18744 width=19)"
" -> Group (cost=48987.13..49924.32 rows=187437 width=19)"
" -> Sort (cost=48987.13..49455.73 rows=187437
width=19)"
" Sort Key: rut_uni_patente"
" -> Seq Scan on mm_ruta (cost=0.00..29536.34
rows=187437 width=19)"
" Filter: ((rut_uni_patente =
'PK-3513'::character varying) OR (rut_uni_patente = 'SA-2633'::character
varying) OR (rut_uni_patente = 'PH-3317'::character varying) OR
(rut_uni_patente = 'PF-5050'::character varying) OR (rut_ (..)"

EXPLAIN ANALYZE

"Seq Scan on mm_ruta (cost=0.00..16336842441.45 rows=162094 width=47)
(actual time=31402.96..36331.50 rows=20 loops=1)"
" Filter: (subplan)"
" SubPlan"
" -> Materialize (cost=50392.91..50392.91 rows=18744 width=19) (actual
time=0.08..0.09 rows=20 loops=324461)"
" -> Aggregate (cost=48987.13..50392.91 rows=18744 width=19)
(actual time=23736.98..26009.69 rows=20 loops=1)"
" -> Group (cost=48987.13..49924.32 rows=187437 width=19)
(actual time=23592.64..25698.82 rows=318759 loops=1)"
" -> Sort (cost=48987.13..49455.73 rows=187437
width=19) (actual time=23592.62..23950.97 rows=318759 loops=1)"
" Sort Key: rut_uni_patente"
" -> Seq Scan on mm_ruta (cost=0.00..29536.34
rows=187437 width=19) (actual time=0.06..7069.58 rows=318759 loops=1)"
" Filter: ((rut_uni_patente =
'PK-3513'::character varying) OR (rut_uni_patente = 'SA-2633'::character
varying) OR (rut_uni_patente = 'PH-3317'::character varying) OR
(rut_uni_patente = 'PF-5050'::character varying) OR (rut_ (..)"
"Total runtime: 36337.29 msec"

In response to

  • Re: Migrar at 2004-09-08 18:18:45 from Alvaro Herrera

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2004-09-08 18:18:45 Re: Migrar
Previous Message Edwin Quijada 2004-09-08 17:43:41 Re: Pc Info