Re: ayuda con optimizacion de consulta

From: Martin Marques <martin(at)bugs(dot)unl(dot)edu(dot)ar>
To: Arturo Llanquihuén Martinez <arturo(at)llanquihuen(dot)cl>
Cc: "Alvaro Herrera" <alvherre(at)dcc(dot)uchile(dot)cl>, <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: ayuda con optimizacion de consulta
Date: 2004-09-08 20:36:29
Message-ID: 200409081736.30015.martin@bugs.unl.edu.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

El Mié 08 Sep 2004 15:17, Arturo Llanquihuén Martinez escribió:
> otra duda que tengo es, sí creo la tabla con oid es redundante que cree un
> campo rut_id como primary key secuencial?

Los oid no deben ser usados como PK, ya que no se puede garantizar su
recuperación, y no son parte de la lógica de las relaciones, sino
identificadores que usa el sistema para realizar otras operaciones.

> si elimino el primary key puedo marcar el oid como primary key?

No.

>
> CREATE INDEX index_patente
> ON mm_ruta
> USING btree
> (rut_uni_patente);

Agrega un índice en rut_uni_patente también.

>
> la consulta:
>
> select rut_latlong,rut_uni_patente,oid from mm_ruta
> where rut_id in (select max(rut_id)
^^^^^^^^^^^
rut_id es un PK, por lo tanto no tiene datos duplicados. Para que lo pones en
un IN ()? Y porque buscas el máximo?

> 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'))

Que tal si probas con:

SELECT rut_latlong,rut_uni_patente FROM mm_ruta
WHERE rut_id = currval('mm_ruta_rut_id_seq') AND
rut_uni_patente IN ('PK-3513','SA-2633','PH-3317')

(lo acorte un poco).
esto siempre que lo hagas despues un una insersion en la que se busque el
valor por defecto de rut_id (para que se llame a
nextval('mm_ruta_rut_id_seq')).

> 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"

--
17:20:01 up 8 days, 6:45, 3 users, load average: 0.59, 1.03, 0.82
-----------------------------------------------------------------
Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar'
Centro de Telematica | DBA, Programador, Administrador
Universidad Nacional
del Litoral
-----------------------------------------------------------------

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Horacio Degiorgi 2004-09-08 21:13:25
Previous Message Noe Monreal 2004-09-08 20:29:44 Stored Procedures en PostGres