[Pgsql-ayuda] indices...

GUSTAVO MARTIN OCAMPO gocampo79@hotmail.com
Mon, 10 Nov 2003 15:22:02 +0000


Hola lista, tengo una tabla llamada basemovibanco de la forma:


     Column       |         Type         | Modifiers
----------------------+------------------------+-------------------
id_juego                  | character varying(3) | not null
id_sorteo                | character varying(5) | not null
id_agencia              | character varying(3) | not null
id_tipomoneda        | smallint             | not null
id_debicredi            | character varying(1) | not null
importe                  | double precision     | not null
fecha_proceso        | date                 | not null
fecha_vencimiento  | date                 | not null


Si hago la siguiente consulta:
test=>select distinct extract (year from basemovibanco.fecha_vencimiento) as 
fecha;
obtengo...

fecha
-------
  2002
  2003
(2 rows)

y si hago...

test=>explain analyze select distinct extract (year from 
basemovibanco.fecha_vencimiento) as fecha;

                                                           QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------
Unique  (cost=18100.75..18887.62 rows=15737 width=4) (actual 
time=2343.14..2551.59 rows=2 loops=1)
   ->  Sort  (cost=18100.75..18494.19 rows=157373 width=4) (actual 
time=2343.13..2470.25 rows=157373 loops=1)
         Sort Key: date_part('year'::text, fecha_vencimiento)
         ->  Seq Scan on basemovibanco  (cost=0.00..3284.73 rows=157373 
width=4) (actual time=1.00..1502.77 rows=157373 loops=1)
Total runtime: 2558.52 msec
(5 rows)

Hay alguna manera de optimizar esta consulta?
mi tabla tiene 153849 registros y ya he probado creando un indice sobre el 
campo fecha_vencimiento, pero igualmente realizo la misma consulta y me 
devuelve el mismo plan de ejecución, o sea, no utiliza el indice creado, 
tambien tengo en claro que el tipo de dato de mi indice no es el correcto 
pero no se me ocurrio otra solucion.
Desde ya, muchas gracias.-

_________________________________________________________________
Charla con tus amigos en línea mediante MSN Messenger: 
http://messenger.yupimsn.com/