Add infrastructure to support EphemeralNamedRelation references

Enterprise / PostgreSQL - Kevin Grittner [postgresql.org] - 1 April 2017 00:17 EDT

A QueryEnvironment concept is added, which allows new types of objects to be passed into queries from parsing on through execution. At this point, the only thing implemented is a collection of EphemeralNamedRelation objects -- relations which can be referenced by name in queries, but do not exist in the catalogs. The only type of ENR implemented is NamedTuplestore, but provision is made to add more types fairly easily.

An ENR can carry its own TupleDesc or reference a relation in the catalogs by relid.

Although these features can be used without SPI, convenience functions are added to SPI so that ENRs can easily be used by code run through SPI.

The initial use of all this is going to be transition tables in AFTER triggers, but that will be added to each PL as a separate commit.

An incidental effect of this patch is to produce a more informative error message if an attempt is made to modify the contents of a CTE from a referencing DML statement. No tests previously covered that possibility, so one is added.

Kevin Grittner and Thomas Munro Reviewed by Heikki Linnakangas, David Fetter, and Thomas Munro with valuable comments and suggestions from many others

18ce3a4 Add infrastructure to support EphemeralNamedRelation references.
contrib/pg_stat_statements/pg_stat_statements.c | 15 +-
doc/src/sgml/spi.sgml | 204 ++++++++++++++++++++++++
src/backend/catalog/pg_proc.c | 3 +-
src/backend/commands/copy.c | 5 +-
src/backend/commands/createas.c | 5 +-
src/backend/commands/explain.c | 40 +++--
src/backend/commands/extension.c | 6 +-
src/backend/commands/foreigncmds.c | 2 +-
src/backend/commands/matview.c | 2 +-
src/backend/commands/prepare.c | 17 +-
src/backend/commands/schemacmds.c | 1 +
src/backend/commands/trigger.c | 9 +-
src/backend/commands/view.c | 2 +-
src/backend/executor/Makefile | 3 +-
src/backend/executor/execAmi.c | 6 +
src/backend/executor/execMain.c | 5 +
src/backend/executor/execParallel.c | 2 +-
src/backend/executor/execProcnode.c | 14 ++
src/backend/executor/execUtils.c | 2 +
src/backend/executor/functions.c | 8 +-
src/backend/executor/nodeNamedtuplestorescan.c | 198 +++++++++++++++++++++++
src/backend/executor/spi.c | 116 ++++++++++++--
src/backend/nodes/copyfuncs.c | 25 +++
src/backend/nodes/nodeFuncs.c | 2 +
src/backend/nodes/outfuncs.c | 20 +++
src/backend/nodes/print.c | 4 +
src/backend/nodes/readfuncs.c | 7 +
src/backend/optimizer/path/allpaths.c | 45 ++++++
src/backend/optimizer/path/costsize.c | 70 ++++++++
src/backend/optimizer/plan/createplan.c | 71 +++++++++
src/backend/optimizer/plan/setrefs.c | 16 ++
src/backend/optimizer/plan/subselect.c | 4 +
src/backend/optimizer/prep/prepjointree.c | 2 +
src/backend/optimizer/util/clauses.c | 2 +-
src/backend/optimizer/util/pathnode.c | 26 +++
src/backend/optimizer/util/plancat.c | 7 +-
src/backend/optimizer/util/relnode.c | 1 +
src/backend/parser/Makefile | 5 +-
src/backend/parser/analyze.c | 14 +-
src/backend/parser/parse_clause.c | 59 +++++--
src/backend/parser/parse_enr.c | 29 ++++
src/backend/parser/parse_node.c | 2 +
src/backend/parser/parse_relation.c | 143 ++++++++++++++++-
src/backend/parser/parse_target.c | 2 +
src/backend/tcop/postgres.c | 22 ++-
src/backend/tcop/pquery.c | 10 +-
src/backend/tcop/utility.c | 34 ++--
src/backend/utils/adt/ruleutils.c | 1 +
src/backend/utils/cache/plancache.c | 34 ++--
src/backend/utils/misc/Makefile | 4 +-
src/backend/utils/misc/queryenvironment.c | 144 +++++++++++++++++
src/backend/utils/sort/tuplestore.c | 17 ++
src/include/catalog/catversion.h | 2 +-
src/include/commands/createas.h | 3 +-
src/include/commands/explain.h | 9 +-
src/include/commands/prepare.h | 4 +-
src/include/executor/execdesc.h | 2 +
src/include/executor/nodeNamedtuplestorescan.h | 24 +++
src/include/executor/spi.h | 7 +
src/include/executor/spi_priv.h | 2 +
src/include/nodes/execnodes.h | 21 +++
src/include/nodes/nodes.h | 2 +
src/include/nodes/parsenodes.h | 6 +-
src/include/nodes/plannodes.h | 10 ++
src/include/optimizer/cost.h | 3 +
src/include/optimizer/pathnode.h | 2 +
src/include/parser/analyze.h | 2 +-
src/include/parser/parse_enr.h | 22 +++
src/include/parser/parse_node.h | 3 +
src/include/parser/parse_relation.h | 4 +
src/include/tcop/tcopprot.h | 7 +-
src/include/tcop/utility.h | 5 +-
src/include/utils/plancache.h | 10 +-
src/include/utils/portal.h | 1 +
src/include/utils/queryenvironment.h | 74 +++++++++
src/include/utils/tuplestore.h | 2 +
src/test/regress/expected/with.out | 3 +
src/test/regress/sql/with.sql | 3 +
78 files changed, 1598 insertions(+), 122 deletions(-)

Upstream: git.postgresql.org


  • Share