Re: Indexing null dates - Mailing list pgsql-general

From John Sidney-Woollett
Subject Re: Indexing null dates
Date
Msg-id 3187.192.168.0.64.1082140077.squirrel@mercury.wardbrook.com
Whole thread Raw
In response to Re: Indexing null dates  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Indexing null dates
List pgsql-general
Tom Lane said:
> "John Sidney-Woollett" <johnsw@wardbrook.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Table Lock issue
Next
From: Pascal Polleunus
Date:
Subject: Re: Parse error a in short stored procedure : What's wrong