postgresql/src/include/access
Peter Geoghegan 41486c4aae Fix btmarkpos/btrestrpos array key wraparound bug.
nbtree's mark/restore processing failed to correctly handle an edge case
involving array key advancement and related search-type scan key state.
Scans with ScalarArrayScalarArrayOpExpr quals requiring mark/restore
processing (for a merge join) could incorrectly conclude that an
affected array/scan key must not have advanced during the time between
marking and restoring the scan's position.

As a result of all this, array key handling within btrestrpos could skip
a required call to _bt_preprocess_keys().  This confusion allowed later
primitive index scans to overlook tuples matching the true current array
keys.  The scan's search-type scan keys would still have spurious values
corresponding to the final array element(s) -- not values matching the
first/now-current array element(s).

To fix, remember that "array key wraparound" has taken place during the
ongoing btrescan in a flag variable stored in the scan's state, and use
that information at the point where btrestrpos decides if another call
to _bt_preprocess_keys is required.

Oversight in commit 70bc5833, which taught nbtree to handle array keys
during mark/restore processing, but missed this subtlety.  That commit
was itself a bug fix for an issue in commit 9e8da0f7, which taught
nbtree to handle ScalarArrayOpExpr quals natively.

Author: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-WzkgP3DDRJxw6DgjCxo-cu-DKrvjEv_ArkP2ctBJatDCYg@mail.gmail.com
Backpatch: 11- (all supported branches).
2023-09-28 16:29:29 -07:00
..
amapi.h Pass down "logically unchanged index" hint. 2021-01-13 08:11:00 -08:00
amvalidate.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
attmap.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
attnum.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
brin.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
brin_internal.h Move IS [NOT] NULL handling from BRIN support functions 2021-03-23 00:45:42 +01:00
brin_page.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
brin_pageops.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
brin_revmap.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
brin_tuple.h Fix handling of empty ranges and NULLs in BRIN 2023-05-19 00:15:00 +02:00
brin_xlog.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
bufmask.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
clog.h Remove unused function prototypes. 2021-01-05 11:42:38 +13:00
commit_ts.h Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
detoast.h Allow configurable LZ4 TOAST compression. 2021-03-19 15:10:38 -04:00
genam.h Simplify state managed by VACUUM. 2021-04-05 13:21:44 -07:00
generic_xlog.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
gin.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
gin_private.h Pass down "logically unchanged index" hint. 2021-01-13 08:11:00 -08:00
ginblock.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
ginxlog.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
gist.h C comments: improve description of GiST NSN and GistBuildLSN 2021-03-10 17:03:10 -05:00
gist_private.h Pass down "logically unchanged index" hint. 2021-01-13 08:11:00 -08:00
gistscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
gistxlog.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
hash.h Pass down "logically unchanged index" hint. 2021-01-13 08:11:00 -08:00
hash_xlog.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
heapam.h Prevent access to no-longer-pinned buffer in heapam_tuple_lock(). 2022-04-13 13:35:02 -04:00
heapam_xlog.h Remove tupgone special case from vacuumlazy.c. 2021-04-06 08:49:22 -07:00
heaptoast.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
hio.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
htup.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
htup_details.h Rework HeapTupleHeader macros to reuse itemptr.h 2021-03-25 15:47:48 -03:00
itup.h Support INCLUDE'd columns in SP-GiST. 2021-04-05 18:41:21 -04:00
multixact.h Remove unused function prototypes. 2021-01-05 11:42:38 +13:00
nbtree.h Fix btmarkpos/btrestrpos array key wraparound bug. 2023-09-28 16:29:29 -07:00
nbtxlog.h Don't consider newly inserted tuples in nbtree VACUUM. 2021-03-10 16:27:01 -08:00
parallel.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
printsimple.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
printtup.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
relation.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
reloptions.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
relscan.h Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
rewriteheap.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
rmgr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
rmgrlist.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
sdir.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
session.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
skey.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
slru.h Prevent excess SimpleLruTruncate() deletion. 2021-01-16 12:21:35 -08:00
spgist.h Pass down "logically unchanged index" hint. 2021-01-13 08:11:00 -08:00
spgist_private.h Re-order pg_attribute columns to eliminate some padding space. 2021-05-23 12:12:09 -04:00
spgxlog.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
stratnum.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
subtrans.h Remove unused function prototypes. 2021-01-05 11:42:38 +13:00
syncscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
sysattr.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
table.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
tableam.h Simplify state managed by VACUUM. 2021-04-05 13:21:44 -07:00
timeline.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
toast_compression.h Rethink definition of pg_attribute.attcompression. 2021-05-27 13:24:27 -04:00
toast_helper.h Allow configurable LZ4 TOAST compression. 2021-03-19 15:10:38 -04:00
toast_internals.h Short-circuit slice requests that are for more than the object's size. 2021-03-22 14:01:20 -04:00
transam.h Reduce the range of OIDs reserved for genbki.pl. 2021-05-27 15:55:08 -04:00
tsmapi.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
tupconvert.h Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:51 +02:00
tupdesc.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
tupdesc_details.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
tupmacs.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
twophase.h Fix CREATE INDEX CONCURRENTLY for the newest prepared transactions. 2021-10-23 18:36:42 -07:00
twophase_rmgr.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
valid.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
visibilitymap.h Split macros from visibilitymap.h into a separate header 2021-09-23 19:59:11 +03:00
visibilitymapdefs.h Split macros from visibilitymap.h into a separate header 2021-09-23 19:59:11 +03:00
xact.h Rethink handling of [Prevent|Is]InTransactionBlock in pipeline mode. 2022-12-13 14:23:59 -05:00
xlog.h Document XLOG_INCLUDE_XID a little better 2021-09-21 19:47:53 -03:00
xlog_internal.h Fix WAL replay in presence of an incomplete record 2021-09-29 11:41:01 -03:00
xlogarchive.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
xlogdefs.h Revert "Avoid creating archive status ".ready" files too early" 2021-09-04 12:14:30 -04:00
xloginsert.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
xlogreader.h Fix WAL replay in presence of an incomplete record 2021-09-29 11:41:01 -03:00
xlogrecord.h Document XLOG_INCLUDE_XID a little better 2021-09-21 19:47:53 -03:00
xlogutils.h Revert "Fix replay of create database records on standby" 2022-03-29 15:36:21 +02:00