Thread: pgsql: Add infrastructure to support EphemeralNamedRelationreferences.
Add infrastructure to support EphemeralNamedRelation references. 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 Branch ------ master Details ------- http://git.postgresql.org/pg/commitdiff/18ce3a4ab22d2984f8540ab480979c851dae5338 Modified Files -------------- 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(-)
rhinoceros says you missed contrib/sepgsql. More generally, if you hack the API of some globally-referenced function, you ought to grep for references to it rather than just assume your compiler will find them all for you. For one thing, that approach is a great way to fail to update relevant comments. (And while I'm bitching, you definitely failed to update ProcessUtility's header comment, which like most significant functions takes some pains to describe all the arguments.) regards, tom lane
Re: pgsql: Add infrastructure to supportEphemeralNamedRelation references.
From
Kevin Grittner
Date:
On Sat, Apr 1, 2017 at 12:01 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote: > rhinoceros says you missed contrib/sepgsql. Yeah, I saw that and have pushed an attempt to fix. > More generally, if you hack the API of some globally-referenced function, > you ought to grep for references to it rather than just assume your > compiler will find them all for you. For one thing, that approach is a > great way to fail to update relevant comments. That's what I normally do, and thought that I had here, but clearly I messed up. The log shows that even in 2014, when this was written, those calls were there. > (And while I'm bitching, you definitely failed to update ProcessUtility's > header comment, which like most significant functions takes some pains > to describe all the arguments.) Will fix. -- Kevin Grittner
Re: pgsql: Add infrastructure to supportEphemeralNamedRelation references.
From
Kevin Grittner
Date:
On Sat, Apr 1, 2017 at 12:21 AM, Kevin Grittner <kgrittn@gmail.com> wrote: > On Sat, Apr 1, 2017 at 12:01 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote: > >> rhinoceros says you missed contrib/sepgsql. > > Yeah, I saw that and have pushed an attempt to fix. That blind fix seemed to work. >> (And while I'm bitching, you definitely failed to update ProcessUtility's >> header comment, which like most significant functions takes some pains >> to describe all the arguments.) > > Will fix. I pushed a fix for that and then went looking to see what else I missed. I found CreateCachedPlan, but then saw that the parameter was never referenced within the function. That seems odd. I want to go over that carefully, but I'm too tired now. Will investigate tomorrow. -- Kevin Grittner