Re: Indexing null dates

From: "John Sidney-Woollett" <johnsw(at)wardbrook(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: johnsw(at)wardbrook(dot)com, pgsql-general(at)postgresql(dot)org
Subject: Re: Indexing null dates
Date: 2004-04-16 18:27:57
Message-ID: 3187.192.168.0.64.1082140077.squirrel@mercury.wardbrook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane said:
> "John Sidney-Woollett" <johnsw(at)wardbrook(dot)com> writes:
>> [ needs to make this fast: ]
>> -- locate the next order
>> select WCCustOrderID into vCustOrderID
>> from CUSTOMER.WCCustOrderStatusLog
>> where WCOrderStatusID = pStatusID
>> and Acknowledged is null
>> and Processing is null
>> for update
>> limit 1;
>
>> My question is whether postgres can index null values, and if not, do I
>> have to accept a full table scan when locating records.
>
> It indexes them, but "is null" is not an indexable operator, so you
> can't directly solve the above with a 3-column index. What you can do
> instead is use a partial index, for instance
>
> create index i on CUSTOMER.WCCustOrderStatusLog (WCOrderStatusID)
> where Acknowledged is null and Processing is null;

That's a very nifty trick and exactly the sort of answer I was after!

Many thanks

John Sidney-Woollett

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bob Ghodsi 2004-04-16 19:43:38 Vb databound
Previous Message Tom Lane 2004-04-16 17:52:07 Re: Table Lock issue