Re: [GENERAL] Indice en Date

From: "Jaime Casanova" <systemguards(at)gmail(dot)com>
To: Arturo <arturomunive(at)gmail(dot)com>
Cc: Postgresql <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: [GENERAL] Indice en Date
Date: 2007-05-01 22:52:18
Message-ID: c2d9e70e0705011552h7e61774ejb16a2505ad48ef57@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda pgsql-general

On 5/1/07, Arturo <arturomunive(at)gmail(dot)com> wrote:
> > On 4/27/07, Arturo Munive <arturomunive(at)gmail(dot)com> wrote:
> >>
> >> tengo un indice sobre una columna date.
> >>
> >> cuando hago una consulta ...
> >> Select
> >> id
> >> from
> >> ventas
> >> WHERE
> >> fecha = date('12-JAN-2007')
> >>
> >> el planificador usa el indice
> >>
> >> pero cuando la restriccion es WHERE fecha < date('12-JAN-2007')
> >>
> >> se efectua un barrido secuencial.
> >>
> >> ni e indice ni la tabla ni la consulta son nada complejos
> >>
>
> Buno el problema que tenía lo resolví, pero no se si es la manera correcta.
>
> SELECT
> id
> FROM
> ventas
> WHERE
> fecha < date('12-JAN-2007')
>
>
> No usa el índice, pero cuando la consulta es
>
> SELECT
> id
> FROM
> ventas
> WHERE
> fecha::date < date('12-JAN-2007')
>
> usa el índice como esperaba....
>
> lo raro de todo esto es que la columna fecha está definida del tipo date
>

que version de postgres estas usando? la version en la que yo probe es
la 8.3 que aun esta en desarrollo...
los bitmap index scan's aparecieron en la version 8.1 y se me ocurre
que estas usando una version anterior....
hare notar que la consulta solo devuelve 88 registros de 1000 que hay
en la tabla, en mi caso solo se usa un busqueda por indice simple
cuando se regresa una sola fila

sgerp=# explain analyze select * from prueba where fecha::date <
date('2007-10-01');
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on prueba (cost=4.93..11.03 rows=88 width=8)
(actual time=0.097..0.150 rows=88 loops=1)
Recheck Cond: (fecha < '2007-10-01'::date)
-> Bitmap Index Scan on idx_fecha (cost=0.00..4.91 rows=88
width=0) (actual time=0.075..0.075 rows=88 loops=1)
Index Cond: (fecha < '2007-10-01'::date)
Total runtime: 0.264 ms
(5 rows)

sgerp=# select count(*) from prueba where fecha::date < date('2007-10-01');
count
-------
88
(1 row)

--
Atentamente,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
Richard Cook

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Ricardo Martin Gomez 2007-05-01 23:07:19 Conectar Bases de Datos postgres
Previous Message Alvaro Herrera 2007-05-01 21:00:02 Re: mapa de base de datos

Browse pgsql-general by date

  From Date Subject
Next Message novnov 2007-05-01 23:10:57 Re: IF function?
Previous Message Jan Bilek 2007-05-01 22:21:34 Re: PostgreSql replication and load balancing ( is Slony-I a solution?)