pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS 7+ messages / 1 participants [nested] [flat]
* pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS @ 2019-12-01 18:10 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2019-12-01 18:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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. Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/283f095d0bff349682985bfa84c36e86c282a055 Modified Files -------------- src/backend/catalog/heap.c | 11 +++++-- src/backend/catalog/index.c | 59 ++++++++++++++++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 52 +++++++++++++++++++++++++++++++++ src/include/catalog/index.h | 2 ++ src/include/utils/relcache.h | 1 + src/test/regress/expected/temp.out | 2 ++ src/test/regress/sql/temp.sql | 3 ++ 7 files changed, 128 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS @ 2019-12-01 18:10 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2019-12-01 18:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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. Branch ------ REL9_4_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/0c84e992c3309e1a0a80ebf3af9ebead9e23d58f Modified Files -------------- src/backend/catalog/heap.c | 11 ++++++-- src/backend/catalog/index.c | 55 ++++++++++++++++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 53 ++++++++++++++++++++++++++++++++++++ src/include/catalog/index.h | 2 ++ src/include/utils/relcache.h | 1 + src/test/regress/expected/temp.out | 2 ++ src/test/regress/sql/temp.sql | 3 +++ 7 files changed, 125 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS @ 2019-12-01 18:10 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2019-12-01 18:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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. Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/c35b714caff008c875b484656de7d168a7bc45f9 Modified Files -------------- src/backend/catalog/heap.c | 11 ++++++-- src/backend/catalog/index.c | 50 +++++++++++++++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 51 ++++++++++++++++++++++++++++++++++++++ src/include/catalog/index.h | 2 ++ src/include/utils/relcache.h | 1 + src/test/regress/expected/temp.out | 2 ++ src/test/regress/sql/temp.sql | 3 +++ 7 files changed, 118 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS @ 2019-12-01 18:10 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2019-12-01 18:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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. Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/768a401e242de18f22d2d0d3b810fce7b3d5e612 Modified Files -------------- src/backend/catalog/heap.c | 11 ++++-- src/backend/catalog/index.c | 69 ++++++++++++++++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 52 ++++++++++++++++++++++++++++ src/include/catalog/index.h | 2 ++ src/include/utils/relcache.h | 1 + src/test/regress/expected/temp.out | 2 ++ src/test/regress/sql/temp.sql | 3 ++ 7 files changed, 138 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS @ 2019-12-01 18:10 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2019-12-01 18:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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. Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/b154d70f743039452f2cadee9566d754e79e3653 Modified Files -------------- src/backend/catalog/heap.c | 11 ++++++-- src/backend/catalog/index.c | 50 +++++++++++++++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 51 ++++++++++++++++++++++++++++++++++++++ src/include/catalog/index.h | 2 ++ src/include/utils/relcache.h | 1 + src/test/regress/expected/temp.out | 2 ++ src/test/regress/sql/temp.sql | 3 +++ 7 files changed, 118 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS @ 2019-12-01 18:10 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2019-12-01 18:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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. Branch ------ REL9_5_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/cfffa8a6b22d8813c30fd524affc07c0c580ea58 Modified Files -------------- src/backend/catalog/heap.c | 11 +++++-- src/backend/catalog/index.c | 59 ++++++++++++++++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 53 ++++++++++++++++++++++++++++++++++ src/include/catalog/index.h | 2 ++ src/include/utils/relcache.h | 1 + src/test/regress/expected/temp.out | 2 ++ src/test/regress/sql/temp.sql | 3 ++ 7 files changed, 129 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS @ 2019-12-01 18:10 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2019-12-01 18:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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. Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/25c7183c06271b44ad2f13fc6ffe435544bee970 Modified Files -------------- src/backend/catalog/heap.c | 11 +++++-- src/backend/catalog/index.c | 63 ++++++++++++++++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 52 +++++++++++++++++++++++++++++++ src/include/catalog/index.h | 2 ++ src/include/utils/relcache.h | 1 + src/test/regress/expected/temp.out | 2 ++ src/test/regress/sql/temp.sql | 3 ++ 7 files changed, 132 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2019-12-01 18:10 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-12-01 18:10 pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS Tom Lane <tgl@sss.pgh.pa.us> 2019-12-01 18:10 pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS Tom Lane <tgl@sss.pgh.pa.us> 2019-12-01 18:10 pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS Tom Lane <tgl@sss.pgh.pa.us> 2019-12-01 18:10 pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS Tom Lane <tgl@sss.pgh.pa.us> 2019-12-01 18:10 pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS Tom Lane <tgl@sss.pgh.pa.us> 2019-12-01 18:10 pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS Tom Lane <tgl@sss.pgh.pa.us> 2019-12-01 18:10 pgsql: Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox