From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve detection of implicitly-temporary views.
Date: Mon, 24 Nov 2025 22:00:29 +0000
Message-ID: <E1vNebk-001EcF-2D@gemulon.postgresql.org> (raw)
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
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/698fa924b11a4ff55ac83b340dbae1e6cee00e59
Modified Files
--------------
src/backend/catalog/dependency.c | 25 +++++++++++++++
src/backend/commands/view.c | 8 +++--
src/backend/parser/analyze.c | 9 ++++--
src/backend/parser/parse_relation.c | 51 ------------------------------
src/include/catalog/dependency.h | 2 ++
src/include/parser/parse_relation.h | 1 -
src/test/regress/expected/create_view.out | 21 ++++++++++--
src/test/regress/expected/groupingsets.out | 1 +
src/test/regress/expected/matview.out | 5 +++
src/test/regress/expected/window.out | 1 +
src/test/regress/sql/create_view.sql | 4 +--
src/test/regress/sql/matview.sql | 4 +++
12 files changed, 71 insertions(+), 61 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Improve detection of implicitly-temporary views.
In-Reply-To: <E1vNebk-001EcF-2D@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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