On 07/01/11 14:15, pasman pasmański wrote:
Sorry, but this examples not use index.

Looks like it does here (oh, and please try to post your replies at the bottom of the message)

On 1/7/11, Susanne Ebrecht<susa...@2ndquadrant.com>  wrote:

The more proper way is:
   SELECT * from tab WHERE EXTRACT(YEAR FROM log_date) = 2011 and
EXTRACT(MONTH FROM log_date) = 1;

CREATE TABLE d_table (d date);
INSERT INTO d_table SELECT '2001-01-01'::date + generate_series(1,9999);
CREATE INDEX d_extract_idx ON d_table ( extract('day' FROM d) );
EXPLAIN ANALYSE SELECT * FROM d_table WHERE extract('day' FROM d) = 3;

That ends up doing a bitmap index scan for me.

Of course, it's entirely possible an index on year+month returns too many rows to be useful.

--
  Richard Huxton
  Archonet Ltd

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply via email to