postgresql/src
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
..
backend Don't to predicate lock for analyze scans, refactor scan option passing. 2019-05-19 15:10:28 -07:00
bin In the pg_upgrade test suite, don't write to src/test/regress. 2019-05-19 14:36:44 -07:00
common Move logging.h and logging.c from src/fe_utils/ to src/common/. 2019-05-14 14:20:10 -04:00
fe_utils Move logging.h and logging.c from src/fe_utils/ to src/common/. 2019-05-14 14:20:10 -04:00
include Don't to predicate lock for analyze scans, refactor scan option passing. 2019-05-19 15:10:28 -07:00
interfaces Move logging.h and logging.c from src/fe_utils/ to src/common/. 2019-05-14 14:20:10 -04:00
makefiles Define WIN32_STACK_RLIMIT throughout win32 and cygwin builds. 2019-04-09 08:25:39 -07:00
pl Fix grammar in error message 2019-05-09 09:16:59 +02:00
port ANSI-ify a few straggler K&R-style function definitions. 2019-05-18 20:16:50 -04:00
template Yet further rethinking of build changes for macOS Mojave. 2018-11-02 18:54:00 -04:00
test Don't to predicate lock for analyze scans, refactor scan option passing. 2019-05-19 15:10:28 -07:00
timezone Portability fix for zic.c. 2019-04-26 21:20:55 -04:00
tools In the pg_upgrade test suite, don't write to src/test/regress. 2019-05-19 14:36:44 -07:00
tutorial SQL comment: remove extra word in heading comment 2019-01-25 18:57:21 -05:00
.gitignore
DEVELOPERS
Makefile Fix partial-build problems introduced by having more generated headers. 2018-04-09 16:42:10 -04:00
Makefile.global.in Consistently test for in-use shared memory. 2019-04-12 22:36:38 -07:00
Makefile.shlib Ensure static libraries have correct mod time even if ranlib messes it up. 2018-11-29 15:53:44 -05:00
nls-global.mk Move logging.h and logging.c from src/fe_utils/ to src/common/. 2019-05-14 14:20:10 -04:00