Re: Date index not used when selecting a date range

From: Poul Møller Hansen <freebsd(at)pbnet(dot)dk>
To: pgsql-general(at)postgresql(dot)org
Cc: David Wilson <david(dot)t(dot)wilson(at)gmail(dot)com>
Subject: Re: Date index not used when selecting a date range
Date: 2008-07-29 07:25:10
Message-ID: 488EC5D6.9090707@pbnet.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


>> This is the index:
>> CREATE INDEX idx_stat_date_node_type
>> ON public.stat
>> USING btree
>> (date, node, "type");
>>
>>
>> explain SELECT * FROM public.stat WHERE node = '1010101010' AND
>> ("date" <= '2008-06-30'::date AND "date" >= '2008-01-01'::date)
>>
>
> Try changing the index order to node, date rather than date, node. You
> need the column on which you'll be doing range checking to be the
> furthest to the right in the index column list.
>
>
Then it works. Unfortunately the production database is always in use
and it contains more than 100 mill. rows,
so creating an index is not an option.

Poul

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Poul Møller Hansen 2008-07-29 07:49:36 Re: Date index not used when selecting a date range
Previous Message Craig Ringer 2008-07-29 07:11:56 Re: How to give input a file for a stored procedure