From: Tom Lane <tgl@sss.pgh.pa.us>
To: $B0B@>!!D>Li(B <anzai-naoya@mxu.nes.nec.co.jp>
Cc: Simon Riggs <simon@2ndQuadrant.com>
Cc: pgsql-bugs@postgresql.org
Cc: $B4d@u!!98O:(B <iwaasa@mxs.nes.nec.co.jp>
Subject: Re: BUG #6283: About the behavior of indexscan in case there are some NULL values.
Date: Wed, 02 Nov 2011 12:38:03 -0400
Message-ID: <2259.1320251883@sss.pgh.pa.us> (raw)
In-Reply-To: <11CC99435D0E8Canzai-naoya@mxu.nes.nec.co.jp>
References: <201111020444.pA24iN5a031950@wwwmaster.postgresql.org>
<CA+U5nMKfLLKYvnBup-z3RkdhKjA2ypGETQgB1ToqLbBE65K3jQ@mail.gmail.com>
<11CC99435D0E8Canzai-naoya@mxu.nes.nec.co.jp>
=?iso-2022-jp?B?GyRCMEJAPiEhRD5MaRsoQg==?= <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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, anzai-naoya@mxu.nes.nec.co.jp, simon@2ndQuadrant.com, iwaasa@mxs.nes.nec.co.jp
Subject: Re: BUG #6283: About the behavior of indexscan in case there are some NULL values.
In-Reply-To: <2259.1320251883@sss.pgh.pa.us>
References: <201111020444.pA24iN5a031950@wwwmaster.postgresql.org> <CA+U5nMKfLLKYvnBup-z3RkdhKjA2ypGETQgB1ToqLbBE65K3jQ@mail.gmail.com> <11CC99435D0E8Canzai-naoya@mxu.nes.nec.co.jp> <2259.1320251883@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox