postgresql/src/backend/utils/cache
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
..
attoptcache.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
catcache.c Remove AtEOXact_CatCache(). 2017-08-13 16:15:14 -04:00
evtcache.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
inval.c Limit depth of forced recursion for CLOBBER_CACHE_RECURSIVELY. 2018-09-07 18:14:30 -04:00
lsyscache.c Further patch rangetypes_selfuncs.c's statistics slot management. 2017-05-08 15:02:58 -04:00
Makefile Add infrastructure for mapping relfilenodes to relation OIDs. 2013-07-22 11:09:10 -04:00
plancache.c Invalidate cached plans on FDW option changes. 2017-01-06 14:12:52 -05:00
relcache.c Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS tables. 2019-12-01 13:09:27 -05:00
relfilenodemap.c Reduce initial size of RelfilenodeMapHash. 2017-05-12 18:30:02 -04:00
relmapper.c PANIC on fsync() failure. 2018-11-19 14:13:22 +13:00
spccache.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
syscache.c Avoid searching for callback functions in CallSyscacheCallbacks(). 2017-05-12 19:05:29 -04:00
ts_cache.c Don't access catalogs to validate GUCs when not connected to a DB. 2019-06-10 23:36:59 -07:00
typcache.c Fix typcache's failure to treat ranges as container types. 2017-10-20 17:12:27 -04:00