pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Redesign the caching done by get_cached_rowtype(). 4+ messages / 1 participants [nested] [flat]
* pgsql: Redesign the caching done by get_cached_rowtype(). @ 2021-04-13 17:37 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2021-04-13 17:37 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Redesign the caching done by get_cached_rowtype(). Previously, get_cached_rowtype() cached a pointer to a reference-counted tuple descriptor from the typcache, relying on the ExprContextCallback mechanism to release the tupdesc refcount when the expression tree using the tupdesc was destroyed. This worked fine when it was designed, but the introduction of within-DO-block COMMITs broke it. The refcount is logged in a transaction-lifespan resource owner, but plpgsql won't destroy simple expressions made within the DO block (before its first commit) until the DO block is exited. That results in a warning about a leaked tupdesc refcount when the COMMIT destroys the original resource owner, and then an error about the active resource owner not holding a matching refcount when the expression is destroyed. To fix, get rid of the need to have a shutdown callback at all, by instead caching a pointer to the relevant typcache entry. Those survive for the life of the backend, so we needn't worry about the pointer becoming stale. (For registered RECORD types, we can still cache a pointer to the tupdesc, knowing that it won't change for the life of the backend.) This mechanism has been in use in plpgsql and expandedrecord.c since commit 4b93f5799, and seems to work well. This change requires modifying the ExprEvalStep structs used by the relevant expression step types, which is slightly worrisome for back-patching. However, there seems no good reason for extensions to be familiar with the details of these particular sub-structs. Per report from Rohit Bhogate. Back-patch to v11 where within-DO-block COMMITs became a thing. Discussion: https://postgr.es/m/CAAV6ZkQRCVBh8qAY+SZiHnz+U+FqAGBBDaDTjF2yiKa2nJSLKg@mail.gmail.com Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/22f2a98cf3ed73ece782c66917e4734b8f736374 Modified Files -------------- src/backend/executor/execExpr.c | 31 ++-- src/backend/executor/execExprInterp.c | 157 ++++++++++++--------- src/include/executor/execExpr.h | 36 +++-- .../plpgsql/src/expected/plpgsql_transaction.out | 24 ++++ src/pl/plpgsql/src/sql/plpgsql_transaction.sql | 20 +++ 5 files changed, 177 insertions(+), 91 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Redesign the caching done by get_cached_rowtype(). @ 2021-04-13 17:37 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2021-04-13 17:37 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Redesign the caching done by get_cached_rowtype(). Previously, get_cached_rowtype() cached a pointer to a reference-counted tuple descriptor from the typcache, relying on the ExprContextCallback mechanism to release the tupdesc refcount when the expression tree using the tupdesc was destroyed. This worked fine when it was designed, but the introduction of within-DO-block COMMITs broke it. The refcount is logged in a transaction-lifespan resource owner, but plpgsql won't destroy simple expressions made within the DO block (before its first commit) until the DO block is exited. That results in a warning about a leaked tupdesc refcount when the COMMIT destroys the original resource owner, and then an error about the active resource owner not holding a matching refcount when the expression is destroyed. To fix, get rid of the need to have a shutdown callback at all, by instead caching a pointer to the relevant typcache entry. Those survive for the life of the backend, so we needn't worry about the pointer becoming stale. (For registered RECORD types, we can still cache a pointer to the tupdesc, knowing that it won't change for the life of the backend.) This mechanism has been in use in plpgsql and expandedrecord.c since commit 4b93f5799, and seems to work well. This change requires modifying the ExprEvalStep structs used by the relevant expression step types, which is slightly worrisome for back-patching. However, there seems no good reason for extensions to be familiar with the details of these particular sub-structs. Per report from Rohit Bhogate. Back-patch to v11 where within-DO-block COMMITs became a thing. Discussion: https://postgr.es/m/CAAV6ZkQRCVBh8qAY+SZiHnz+U+FqAGBBDaDTjF2yiKa2nJSLKg@mail.gmail.com Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/6530df6c294c3f3b2dba6a1703574f6bbcde0886 Modified Files -------------- src/backend/executor/execExpr.c | 31 ++-- src/backend/executor/execExprInterp.c | 157 ++++++++++++--------- src/include/executor/execExpr.h | 36 +++-- .../plpgsql/src/expected/plpgsql_transaction.out | 24 ++++ src/pl/plpgsql/src/sql/plpgsql_transaction.sql | 20 +++ 5 files changed, 177 insertions(+), 91 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Redesign the caching done by get_cached_rowtype(). @ 2021-04-13 17:37 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2021-04-13 17:37 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Redesign the caching done by get_cached_rowtype(). Previously, get_cached_rowtype() cached a pointer to a reference-counted tuple descriptor from the typcache, relying on the ExprContextCallback mechanism to release the tupdesc refcount when the expression tree using the tupdesc was destroyed. This worked fine when it was designed, but the introduction of within-DO-block COMMITs broke it. The refcount is logged in a transaction-lifespan resource owner, but plpgsql won't destroy simple expressions made within the DO block (before its first commit) until the DO block is exited. That results in a warning about a leaked tupdesc refcount when the COMMIT destroys the original resource owner, and then an error about the active resource owner not holding a matching refcount when the expression is destroyed. To fix, get rid of the need to have a shutdown callback at all, by instead caching a pointer to the relevant typcache entry. Those survive for the life of the backend, so we needn't worry about the pointer becoming stale. (For registered RECORD types, we can still cache a pointer to the tupdesc, knowing that it won't change for the life of the backend.) This mechanism has been in use in plpgsql and expandedrecord.c since commit 4b93f5799, and seems to work well. This change requires modifying the ExprEvalStep structs used by the relevant expression step types, which is slightly worrisome for back-patching. However, there seems no good reason for extensions to be familiar with the details of these particular sub-structs. Per report from Rohit Bhogate. Back-patch to v11 where within-DO-block COMMITs became a thing. Discussion: https://postgr.es/m/CAAV6ZkQRCVBh8qAY+SZiHnz+U+FqAGBBDaDTjF2yiKa2nJSLKg@mail.gmail.com Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/97b7ad4688848b38ceac604e1dd2e6af39098229 Modified Files -------------- src/backend/executor/execExpr.c | 31 ++-- src/backend/executor/execExprInterp.c | 163 ++++++++++++--------- src/include/executor/execExpr.h | 36 +++-- .../plpgsql/src/expected/plpgsql_transaction.out | 24 +++ src/pl/plpgsql/src/sql/plpgsql_transaction.sql | 20 +++ 5 files changed, 180 insertions(+), 94 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Redesign the caching done by get_cached_rowtype(). @ 2021-04-13 17:37 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2021-04-13 17:37 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Redesign the caching done by get_cached_rowtype(). Previously, get_cached_rowtype() cached a pointer to a reference-counted tuple descriptor from the typcache, relying on the ExprContextCallback mechanism to release the tupdesc refcount when the expression tree using the tupdesc was destroyed. This worked fine when it was designed, but the introduction of within-DO-block COMMITs broke it. The refcount is logged in a transaction-lifespan resource owner, but plpgsql won't destroy simple expressions made within the DO block (before its first commit) until the DO block is exited. That results in a warning about a leaked tupdesc refcount when the COMMIT destroys the original resource owner, and then an error about the active resource owner not holding a matching refcount when the expression is destroyed. To fix, get rid of the need to have a shutdown callback at all, by instead caching a pointer to the relevant typcache entry. Those survive for the life of the backend, so we needn't worry about the pointer becoming stale. (For registered RECORD types, we can still cache a pointer to the tupdesc, knowing that it won't change for the life of the backend.) This mechanism has been in use in plpgsql and expandedrecord.c since commit 4b93f5799, and seems to work well. This change requires modifying the ExprEvalStep structs used by the relevant expression step types, which is slightly worrisome for back-patching. However, there seems no good reason for extensions to be familiar with the details of these particular sub-structs. Per report from Rohit Bhogate. Back-patch to v11 where within-DO-block COMMITs became a thing. Discussion: https://postgr.es/m/CAAV6ZkQRCVBh8qAY+SZiHnz+U+FqAGBBDaDTjF2yiKa2nJSLKg@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/c2db458c1036efae503ce5e451f8369e64c99541 Modified Files -------------- src/backend/executor/execExpr.c | 31 ++-- src/backend/executor/execExprInterp.c | 163 ++++++++++++--------- src/include/executor/execExpr.h | 36 +++-- .../plpgsql/src/expected/plpgsql_transaction.out | 24 +++ src/pl/plpgsql/src/sql/plpgsql_transaction.sql | 20 +++ 5 files changed, 180 insertions(+), 94 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2021-04-13 17:37 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-04-13 17:37 pgsql: Redesign the caching done by get_cached_rowtype(). Tom Lane <tgl@sss.pgh.pa.us> 2021-04-13 17:37 pgsql: Redesign the caching done by get_cached_rowtype(). Tom Lane <tgl@sss.pgh.pa.us> 2021-04-13 17:37 pgsql: Redesign the caching done by get_cached_rowtype(). Tom Lane <tgl@sss.pgh.pa.us> 2021-04-13 17:37 pgsql: Redesign the caching done by get_cached_rowtype(). 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