pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix missed lock acquisition while inlining new-style SQL functio
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix missed lock acquisition while inlining new-style SQL functio
@ 2021-08-31 16:02  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2021-08-31 16:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix missed lock acquisition while inlining new-style SQL functions.

When starting to use a query parsetree loaded from the catalogs,
we must begin by applying AcquireRewriteLocks(), to obtain the same
relation locks that the parser would have gotten if the query were
entered interactively, and to do some other cleanup such as dealing
with later-dropped columns.  New-style SQL functions are just as
subject to this rule as other stored parsetrees; however, of the
places dealing with such functions, only init_sql_fcache had gotten
the memo.  In particular, if we successfully inlined a new-style
set-returning SQL function that contained any relation references,
we'd either get an assertion failure or attempt to use those
relation(s) sans locks.

I also added AcquireRewriteLocks calls to fmgr_sql_validator and
print_function_sqlbody.  Desultory experiments didn't demonstrate any
failures in those, but I suspect that I just didn't try hard enough.
Certainly we don't expect nearby code paths to operate without locks.

On the same logic of it-ought-to-have-the-same-effects-as-the-old-code,
call pg_rewrite_query() in fmgr_sql_validator, too.  It's possible
that neither code path there needs to bother with rewriting, but
doing the analysis to prove that is beyond my goals for today.

Per bug #17161 from Alexander Lakhin.

Discussion: https://postgr.es/m/17161-048a1cdff8422800@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/589be6f6c732a20e2bcaa02560de464ebbd48af2

Modified Files
--------------
src/backend/catalog/pg_proc.c                   | 23 +++++++++++++++++++--
src/backend/optimizer/util/clauses.c            |  9 +++++++++
src/backend/utils/adt/ruleutils.c               | 16 +++++++++++----
src/test/regress/expected/create_function_3.out | 27 ++++++++++++++-----------
src/test/regress/sql/create_function_3.sql      |  9 +++++++--
5 files changed, 64 insertions(+), 20 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix missed lock acquisition while inlining new-style SQL functio
@ 2021-08-31 16:02  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2021-08-31 16:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix missed lock acquisition while inlining new-style SQL functions.

When starting to use a query parsetree loaded from the catalogs,
we must begin by applying AcquireRewriteLocks(), to obtain the same
relation locks that the parser would have gotten if the query were
entered interactively, and to do some other cleanup such as dealing
with later-dropped columns.  New-style SQL functions are just as
subject to this rule as other stored parsetrees; however, of the
places dealing with such functions, only init_sql_fcache had gotten
the memo.  In particular, if we successfully inlined a new-style
set-returning SQL function that contained any relation references,
we'd either get an assertion failure or attempt to use those
relation(s) sans locks.

I also added AcquireRewriteLocks calls to fmgr_sql_validator and
print_function_sqlbody.  Desultory experiments didn't demonstrate any
failures in those, but I suspect that I just didn't try hard enough.
Certainly we don't expect nearby code paths to operate without locks.

On the same logic of it-ought-to-have-the-same-effects-as-the-old-code,
call pg_rewrite_query() in fmgr_sql_validator, too.  It's possible
that neither code path there needs to bother with rewriting, but
doing the analysis to prove that is beyond my goals for today.

Per bug #17161 from Alexander Lakhin.

Discussion: https://postgr.es/m/17161-048a1cdff8422800@postgresql.org

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/983d7033df6e03134572eb75dd76603fb9245211

Modified Files
--------------
src/backend/catalog/pg_proc.c                   | 23 +++++++++++++++++++--
src/backend/optimizer/util/clauses.c            |  9 +++++++++
src/backend/utils/adt/ruleutils.c               | 16 +++++++++++----
src/test/regress/expected/create_function_3.out | 27 ++++++++++++++-----------
src/test/regress/sql/create_function_3.sql      |  9 +++++++--
5 files changed, 64 insertions(+), 20 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-08-31 16:02 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31 16:02 pgsql: Fix missed lock acquisition while inlining new-style SQL functio Tom Lane <tgl@sss.pgh.pa.us>
2021-08-31 16:02 pgsql: Fix missed lock acquisition while inlining new-style SQL functio 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