pgsql: Improve detection of implicitly-temporary views.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve detection of implicitly-temporary views.
Date: 2025-11-24 22:00:29
Message-ID: E1vNebk-001EcF-2D@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-by: Jim Jones <jim(dot)jones(at)uni-muenster(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2025-11-24 22:57:40 pgsql: Avoid global LC_CTYPE dependency in pg_locale_libc.c.
Previous Message Nathan Bossart 2025-11-24 21:25:51 Re: pgsql: Teach DSM registry to ERROR if attaching to an uninitialized ent