Re: BUG #6283: About the behavior of indexscan in case there are some NULL values. - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #6283: About the behavior of indexscan in case there are some NULL values.
Date
Msg-id 2259.1320251883@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #6283: About the behavior of indexscan in case there are some NULL values.  (安西 直也<anzai-naoya@mxu.nes.nec.co.jp>)
List pgsql-bugs
安西 直也 <anzai-naoya@mxu.nes.nec.co.jp> writes:
> I have checked latest source code.
> But, backward scan doesn't work correctly...

[ pokes at that... ]  Hmm, the patches I applied a couple days ago
assumed that we are stepping forward or back from a place where the
WHERE clauses are satisfied.  But in this example, the system just
applies _bt_endpoint to descend to the right-hand end of the index,
since there is no upper-bound qual with which to do anything different.
So we start from a place where the clauses aren't satisfied.  That also
means that we haven't really fixed the original performance complaint:
there could be lots of nulls to be stepped over before we reach the
first matching row.

I think that the right fix for this is probably to make
_bt_preprocess_keys explicitly generate the "id is not null" qual that's
implied by "id > 0", so that it will have what amounts to a range
condition on the index contents (since for NULLS LAST, "id is not null"
amounts to "id is less than null", as it were).  Then, instead of applying
_bt_endpoint, it will use the less-than key to descend the btree to the
last non-null entry, and we'll be good for both correctness and
performance.

I don't see any big problem in doing this in HEAD, but it's getting past
what seems like a sane back-patch.  So probably we should revert the
back-branch versions of the prior patch, and just say that the
performance problem is only going to be addressed in HEAD.
        regards, tom lane


pgsql-bugs by date:

Previous
From: 安西 直也
Date:
Subject: Re: BUG #6283: About the behavior of indexscan in case there are some NULL values.
Next
From: Archana Sachin Ghag
Date:
Subject: Issue with passing NULL for function parameter