pgsql: Improve detection of implicitly-temporary views. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Improve detection of implicitly-temporary views.
Date
Msg-id E1vNebk-001EcF-2D@gemulon.postgresql.org
Whole thread Raw
List 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@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(-)


pgsql-committers by date:

Previous
From: Jacob Champion
Date:
Subject: pgsql: Add pg_add_size_overflow() and friends
Next
From: Jeff Davis
Date:
Subject: pgsql: Avoid global LC_CTYPE dependency in pg_locale_libc.c.