postgresql/src/backend/utils
Tom Lane cfffa8a6b2 Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS tables.
We implement ON COMMIT DELETE ROWS by truncating tables marked that
way, which requires also truncating/rebuilding their indexes.  But
RelationTruncateIndexes asks the relcache for up-to-date copies of any
index expressions, which may cause execution of eval_const_expressions
on them, which can result in actual execution of subexpressions.
This is a bad thing to have happening during ON COMMIT.  Manuel Rigger
reported that use of a SQL function resulted in crashes due to
expectations that ActiveSnapshot would be set, which it isn't.
The most obvious fix perhaps would be to push a snapshot during
PreCommit_on_commit_actions, but I think that would just open the door
to more problems: CommitTransaction explicitly expects that no
user-defined code can be running at this point.

Fortunately, since we know that no tuples exist to be indexed, there
seems no need to use the real index expressions or predicates during
RelationTruncateIndexes.  We can set up dummy index expressions
instead (we do need something that will expose the right data type,
as there are places that build index tupdescs based on this), and
just ignore predicates and exclusion constraints.

In a green field it'd likely be better to reimplement ON COMMIT DELETE
ROWS using the same "init fork" infrastructure used for unlogged
relations.  That seems impractical without catalog changes though,
and even without that it'd be too big a change to back-patch.
So for now do it like this.

Per private report from Manuel Rigger.  This has been broken forever,
so back-patch to all supported branches.
2019-12-01 13:09:27 -05:00
..
adt Defend against self-referential views in relation_is_updatable(). 2019-11-21 16:21:44 -05:00
cache Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS tables. 2019-12-01 13:09:27 -05:00
error Disallow setting client_min_messages higher than ERROR. 2018-11-08 17:33:26 -05:00
fmgr Add a utility function to extract variadic function arguments 2017-10-25 07:20:37 -04:00
hash Reorganize our CRC source files again. 2015-04-14 17:03:42 +03:00
init Consistently test for in-use shared memory. 2019-04-12 22:41:42 -07:00
mb Avoid unnecessary out-of-memory errors during encoding conversion. 2019-10-03 17:34:26 -04:00
misc When restoring GUCs in parallel workers, show an error context. 2019-10-17 13:50:59 +13:00
mmgr Allow repalloc() to give back space when a large chunk is downsized. 2019-10-03 13:56:26 -04:00
resowner Update copyright for 2015 2015-01-06 11:43:47 -05:00
sort Fix actual and potential double-frees around tuplesort usage. 2018-03-28 13:26:43 -04:00
time Fix pruning of locked and updated tuples. 2017-12-14 18:20:48 -08:00
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
errcodes.txt Redesign tablesample method API, and do extensive code review. 2015-07-25 14:39:00 -04:00
Gen_dummy_probes.pl Remove dependency on psed for MSVC builds. 2016-03-19 18:44:04 -04:00
Gen_dummy_probes.sed Update copyright for 2015 2015-01-06 11:43:47 -05:00
Gen_fmgrtab.pl Allow forcing nullness of columns during bootstrap. 2015-02-21 22:31:54 +01:00
generate-errcodes.pl Update copyright for 2015 2015-01-06 11:43:47 -05:00
Makefile Fix make rules that generate multiple output files. 2018-03-23 13:45:38 -04:00
probes.d Update copyright for 2015 2015-01-06 11:43:47 -05:00