Re: Bug in nbtree optimization to skip > operator comparisons (or < comparisons in backwards scans) - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Bug in nbtree optimization to skip > operator comparisons (or < comparisons in backwards scans)
Date
Msg-id 997901.1701824030@sss.pgh.pa.us
Whole thread Raw
In response to Bug in nbtree optimization to skip > operator comparisons (or < comparisons in backwards scans)  (Peter Geoghegan <pg@bowt.ie>)
Responses Re: Bug in nbtree optimization to skip > operator comparisons (or < comparisons in backwards scans)
List pgsql-hackers
Peter Geoghegan <pg@bowt.ie> writes:
> As I recently went into on the thread where we've been discussing my
> nbtree SAOP patch [1], there is good reason to suspect that one of the
> optimizations added by commit e0b1ee17 is buggy in the presence of an
> opfamily lacking the full set of cross-type comparisons. The attached
> test case confirms that these suspicions were correct. Running the
> tese case against HEAD will lead to an assertion failure (or a wrong
> answer when assertions are disabled).

Hmm ... I had not paid any attention to this commit, but the rationale
given in the commit message is just flat wrong:

    Imagine the ordered B-tree scan for the query like this.

    SELECT * FROM tbl WHERE col > 'a' AND col < 'b' ORDER BY col;

    The (col > 'a') scan key will be always matched once we find the location to
    start the scan.  The (col < 'b') scan key will match every item on the page
    as long as it matches the last item on the page.

That argument probably holds for the index's first column, but it is
completely and obviously wrong for every following column.  Nonetheless
it looks like we're trying to apply the optimization to every scan key.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Bug in nbtree optimization to skip > operator comparisons (or < comparisons in backwards scans)
Next
From: Peter Geoghegan
Date:
Subject: Re: Bug in nbtree optimization to skip > operator comparisons (or < comparisons in backwards scans)