summaryrefslogtreecommitdiff
path: root/src/backend/tcop/utility.c
diff options
context:
space:
mode:
authorKevin Grittner <kgrittn@postgresql.org>2017-03-31 23:17:18 -0500
committerKevin Grittner <kgrittn@postgresql.org>2017-03-31 23:17:18 -0500
commit18ce3a4ab22d2984f8540ab480979c851dae5338 (patch)
treeff63f19ee776dfe26c675abacb8558bb60c5b0b6 /src/backend/tcop/utility.c
parent25dc142a49c60c3107480c487cd8444dc83f9bdf (diff)
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
Diffstat (limited to 'src/backend/tcop/utility.c')
-rw-r--r--src/backend/tcop/utility.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 584f4f13ccc..b610c8e7cee 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -78,6 +78,7 @@ static void ProcessUtilitySlow(ParseState *pstate,
const char *queryString,
ProcessUtilityContext context,
ParamListInfo params,
+ QueryEnvironment *queryEnv,
DestReceiver *dest,
char *completionTag);
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel);
@@ -333,6 +334,7 @@ ProcessUtility(PlannedStmt *pstmt,
const char *queryString,
ProcessUtilityContext context,
ParamListInfo params,
+ QueryEnvironment *queryEnv,
DestReceiver *dest,
char *completionTag)
{
@@ -347,11 +349,11 @@ ProcessUtility(PlannedStmt *pstmt,
*/
if (ProcessUtility_hook)
(*ProcessUtility_hook) (pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
else
standard_ProcessUtility(pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
}
@@ -371,6 +373,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
const char *queryString,
ProcessUtilityContext context,
ParamListInfo params,
+ QueryEnvironment *queryEnv,
DestReceiver *dest,
char *completionTag)
{
@@ -672,7 +675,8 @@ standard_ProcessUtility(PlannedStmt *pstmt,
break;
case T_ExplainStmt:
- ExplainQuery(pstate, (ExplainStmt *) parsetree, queryString, params, dest);
+ ExplainQuery(pstate, (ExplainStmt *) parsetree, queryString, params,
+ queryEnv, dest);
break;
case T_AlterSystemStmt:
@@ -819,7 +823,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
if (EventTriggerSupportsGrantObjectType(stmt->objtype))
ProcessUtilitySlow(pstate, pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
else
ExecuteGrantStmt(stmt);
@@ -832,7 +836,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
if (EventTriggerSupportsObjectType(stmt->removeType))
ProcessUtilitySlow(pstate, pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
else
ExecDropStmt(stmt, isTopLevel);
@@ -845,7 +849,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
if (EventTriggerSupportsObjectType(stmt->renameType))
ProcessUtilitySlow(pstate, pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
else
ExecRenameStmt(stmt);
@@ -858,7 +862,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
if (EventTriggerSupportsObjectType(stmt->objectType))
ProcessUtilitySlow(pstate, pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
else
ExecAlterObjectDependsStmt(stmt, NULL);
@@ -871,7 +875,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
if (EventTriggerSupportsObjectType(stmt->objectType))
ProcessUtilitySlow(pstate, pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
else
ExecAlterObjectSchemaStmt(stmt, NULL);
@@ -884,7 +888,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
if (EventTriggerSupportsObjectType(stmt->objectType))
ProcessUtilitySlow(pstate, pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
else
ExecAlterOwnerStmt(stmt);
@@ -897,7 +901,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
if (EventTriggerSupportsObjectType(stmt->objtype))
ProcessUtilitySlow(pstate, pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
else
CommentObject(stmt);
@@ -910,7 +914,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
if (EventTriggerSupportsObjectType(stmt->objtype))
ProcessUtilitySlow(pstate, pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
else
ExecSecLabelStmt(stmt);
@@ -920,7 +924,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
default:
/* All other statement types have event trigger support */
ProcessUtilitySlow(pstate, pstmt, queryString,
- context, params,
+ context, params, queryEnv,
dest, completionTag);
break;
}
@@ -939,6 +943,7 @@ ProcessUtilitySlow(ParseState *pstate,
const char *queryString,
ProcessUtilityContext context,
ParamListInfo params,
+ QueryEnvironment *queryEnv,
DestReceiver *dest,
char *completionTag)
{
@@ -1062,6 +1067,7 @@ ProcessUtilitySlow(ParseState *pstate,
queryString,
PROCESS_UTILITY_SUBCOMMAND,
params,
+ NULL,
None_Receiver,
NULL);
}
@@ -1140,6 +1146,7 @@ ProcessUtilitySlow(ParseState *pstate,
queryString,
PROCESS_UTILITY_SUBCOMMAND,
params,
+ NULL,
None_Receiver,
NULL);
EventTriggerAlterTableStart(parsetree);
@@ -1438,7 +1445,8 @@ ProcessUtilitySlow(ParseState *pstate,
case T_CreateTableAsStmt:
address = ExecCreateTableAs((CreateTableAsStmt *) parsetree,
- queryString, params, completionTag);
+ queryString, params, queryEnv,
+ completionTag);
break;
case T_RefreshMatViewStmt: