Fix incorrect handling of NULL index entries in indexed ROW() comparisons.
authorTom Lane
Wed, 9 Mar 2016 19:51:01 +0000 (14:51 -0500)
committerTom Lane
Wed, 9 Mar 2016 19:51:01 +0000 (14:51 -0500)
commitda936200dbd92509768376b8ca198cfcbeec738b
tree2ba0a4a8eb557c97538252a01e4a4fe3a2ea8abb
parent7e31314c5fcf942a900cce4637a27594ee32a65b
Fix incorrect handling of NULL index entries in indexed ROW() comparisons.

An index search using a row comparison such as ROW(a, b) > ROW('x', 'y')
would stop upon reaching a NULL entry in the "b" column, ignoring the
fact that there might be non-NULL "b" values associated with later values
of "a".  This happens because _bt_mark_scankey_required() marks the
subsidiary scankey for "b" as required, which is just wrong: it's for
a column after the one with the first inequality key (namely "a"), and
thus can't be considered a required match.

This bit of brain fade dates back to the very beginnings of our support
for indexed ROW() comparisons, in 2006.  Kind of astonishing that no one
came across it before Glen Takahashi, in bug #14010.

Back-patch to all supported versions.

Note: the given test case doesn't actually fail in unpatched 9.1, evidently
because the fix for bug #6278 (i.e., stopping at nulls in either scan
direction) is required to make it fail.  I'm sure I could devise a case
that fails in 9.1 as well, perhaps with something involving making a cursor
back up; but it doesn't seem worth the trouble.
src/backend/access/nbtree/nbtutils.c
src/test/regress/expected/rowtypes.out
src/test/regress/sql/rowtypes.sql