postgresql/src/include/access
Andres Freund c3b23ae457 Don't to predicate lock for analyze scans, refactor scan option passing.
Before this commit, when ANALYZE was run on a table and serializable
was used (either by virtue of an explicit BEGIN TRANSACTION ISOLATION
LEVEL SERIALIZABLE, or default_transaction_isolation being set to
serializable) a null pointer dereference lead to a crash.

The analyze scan doesn't need a snapshot (nor predicate locking), but
before this commit a scan only contained information about being a
bitmap or sample scan.

Refactor the option passing to the scan_begin callback to use a
bitmask instead. Alternatively we could have added a new boolean
parameter, but that seems harder to read. Even before this issue
various people (Heikki, Tom, Robert) suggested doing so.

These changes don't change the scan APIs outside of tableam. The flags
argument could be exposed, it's not necessary to fix this
problem. Also the wrapper table_beginscan* functions encapsulate most
of that complexity.

After these changes fixing the bug is trivial, just don't acquire
predicate lock for analyze style scans. That was already done for
bitmap heap scans.  Add an assert that a snapshot is passed when
acquiring the predicate lock, so this kind of bug doesn't require
running with serializable.

Also add a comment about sample scans currently requiring predicate
locking the entire relation, that previously wasn't remarked upon.

Reported-By: Joe Wildish
Author: Andres Freund
Discussion:
    https://postgr.es/m/4EA80A20-E9BF-49F1-9F01-5B66CAB21453@elusive.cx
    https://postgr.es/m/20190411164947.nkii4gaeilt4bui7@alap3.anarazel.de
    https://postgr.es/m/20190518203102.g7peu2fianukjuxm@alap3.anarazel.de
2019-05-19 15:10:28 -07:00
..
amapi.h Report progress of CREATE INDEX operations 2019-04-02 15:18:08 -03:00
amvalidate.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
attnum.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
brin.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
brin_internal.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
brin_page.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
brin_pageops.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
brin_revmap.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
brin_tuple.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
brin_xlog.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
bufmask.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
clog.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
commit_ts.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
genam.h Report progress of CREATE INDEX operations 2019-04-02 15:18:08 -03:00
generic_xlog.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
gin.h Generate less WAL during GiST, GIN and SP-GiST index build. 2019-04-03 17:03:15 +03:00
gin_private.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
ginblock.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
ginxlog.h Generate less WAL during GiST, GIN and SP-GiST index build. 2019-04-03 17:03:15 +03:00
gist.h Generate less WAL during GiST, GIN and SP-GiST index build. 2019-04-03 17:03:15 +03:00
gist_private.h Detect internal GiST page splits correctly during index build. 2019-05-14 13:18:44 +03:00
gistscan.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
gistxlog.h Convert gist to compute page level xid horizon on primary. 2019-04-22 14:28:30 -07:00
hash.h Move hash_any prototype from access/hash.h to utils/hashutils.h 2019-03-11 13:17:50 -03:00
hash_xlog.h Compute XID horizon for page level index vacuum on primary. 2019-03-26 16:52:54 -07:00
heapam.h Don't to predicate lock for analyze scans, refactor scan option passing. 2019-05-19 15:10:28 -07:00
heapam_xlog.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
hio.h Don't include heapam.h from others headers. 2019-01-14 16:24:41 -08:00
htup.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
htup_details.h Standardize ItemIdData terminology. 2019-05-13 15:53:39 -07:00
itup.h Standardize ItemIdData terminology. 2019-05-13 15:53:39 -07:00
multixact.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
nbtree.h Prevent O(N^2) unique index insertion edge case. 2019-04-23 10:33:57 -07:00
nbtxlog.h Compute XID horizon for page level index vacuum on primary. 2019-03-26 16:52:54 -07:00
parallel.h Enable parallel query with SERIALIZABLE isolation. 2019-03-15 17:47:04 +13:00
printsimple.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
printtup.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
relation.h Introduce access/{table.h, relation.h}, for generic functions from heapam.h. 2019-01-21 10:51:36 -08:00
reloptions.h Finish reverting "recheck_on_update" patch. 2019-01-15 12:07:10 -05:00
relscan.h Don't to predicate lock for analyze scans, refactor scan option passing. 2019-05-19 15:10:28 -07:00
rewriteheap.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
rmgr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
rmgrlist.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
sdir.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
session.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
skey.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
slru.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
spgist.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
spgist_private.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
spgxlog.h Generate less WAL during GiST, GIN and SP-GiST index build. 2019-04-03 17:03:15 +03:00
stratnum.h Move hash_any prototype from access/hash.h to utils/hashutils.h 2019-03-11 13:17:50 -03:00
subtrans.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
sysattr.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
table.h Introduce access/{table.h, relation.h}, for generic functions from heapam.h. 2019-01-21 10:51:36 -08:00
tableam.h Don't to predicate lock for analyze scans, refactor scan option passing. 2019-05-19 15:10:28 -07:00
timeline.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
transam.h Use FullTransactionId for the transaction stack. 2019-03-28 18:24:43 +13:00
tsmapi.h tableam: sample scan. 2019-03-31 18:37:57 -07:00
tupconvert.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
tupdesc.h Generated columns 2019-03-30 08:15:57 +01:00
tupdesc_details.h Make naming of tupdesc related structs more consistent with the rest of PG. 2019-01-14 16:25:50 -08:00
tupmacs.h Improve comment for att_isnull. 2019-05-13 13:13:24 -04:00
tuptoaster.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
twophase.h Make release of 2PC identifier and locks consistent in COMMIT PREPARED 2019-02-25 14:19:34 +09:00
twophase_rmgr.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
valid.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
visibilitymap.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
xact.h Log all statements from a sample of transactions 2019-04-03 18:43:59 -03:00
xlog.h Add wal_recycle and wal_init_zero GUCs. 2019-04-02 14:37:14 +13:00
xlog_internal.h Convert gist to compute page level xid horizon on primary. 2019-04-22 14:28:30 -07:00
xlogdefs.h Generate less WAL during GiST, GIN and SP-GiST index build. 2019-04-03 17:03:15 +03:00
xloginsert.h Generate less WAL during GiST, GIN and SP-GiST index build. 2019-04-03 17:03:15 +03:00
xlogreader.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
xlogrecord.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
xlogutils.h Update copyright for 2019 2019-01-02 12:44:25 -05:00