]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Improve detection of implicitly-temporary views.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 24 Nov 2025 22:00:16 +0000 (17:00 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 24 Nov 2025 22:00:16 +0000 (17:00 -0500)
commit698fa924b11a4ff55ac83b340dbae1e6cee00e59
tree8e477c446feb7e554a55847aca287f2f018e9386
parent0664aa4ff89a640e5c0362cdcfc6cfc3eb63a659
Improve detection of implicitly-temporary views.

We've long had a practice of making views temporary by default if they
reference any temporary tables.  However the implementation was pretty
incomplete, in that it only searched for RangeTblEntry references to
temp relations.  Uses of temporary types, regclass constants, etc
were not detected even though the dependency mechanism considers them
grounds for dropping the view.  Thus a view not believed to be temp
could silently go away at session exit anyhow.

To improve matters, replace the ad-hoc isQueryUsingTempRelation()
logic with use of the dependency-based infrastructure introduced by
commit 572c40ba9.  This is complete by definition, and it's less code
overall.

While we're at it, we can also extend the warning NOTICE (or ERROR
in the case of a materialized view) to mention one of the temp
objects motivating the classification of the view as temp, as was
done for functions in 572c40ba9.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Jim Jones <jim.jones@uni-muenster.de>
Discussion: https://postgr.es/m/19cf6ae1-04cd-422c-a760-d7e75fe6cba9@uni-muenster.de
12 files changed:
src/backend/catalog/dependency.c
src/backend/commands/view.c
src/backend/parser/analyze.c
src/backend/parser/parse_relation.c
src/include/catalog/dependency.h
src/include/parser/parse_relation.h
src/test/regress/expected/create_view.out
src/test/regress/expected/groupingsets.out
src/test/regress/expected/matview.out
src/test/regress/expected/window.out
src/test/regress/sql/create_view.sql
src/test/regress/sql/matview.sql