mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
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
This commit is contained in:
@@ -23,7 +23,7 @@ extern PGDLLIMPORT post_parse_analyze_hook_type post_parse_analyze_hook;
|
||||
|
||||
|
||||
extern Query *parse_analyze(RawStmt *parseTree, const char *sourceText,
|
||||
Oid *paramTypes, int numParams);
|
||||
Oid *paramTypes, int numParams, QueryEnvironment *queryEnv);
|
||||
extern Query *parse_analyze_varparams(RawStmt *parseTree, const char *sourceText,
|
||||
Oid **paramTypes, int *numParams);
|
||||
|
||||
|
||||
22
src/include/parser/parse_enr.h
Normal file
22
src/include/parser/parse_enr.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* parse_enr.h
|
||||
* Internal definitions for parser
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/parser/parse_enr.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef PARSE_ENR_H
|
||||
#define PARSE_ENR_H
|
||||
|
||||
#include "parser/parse_node.h"
|
||||
|
||||
extern bool name_matches_visible_ENR(ParseState *pstate, const char *refname);
|
||||
extern EphemeralNamedRelationMetadata get_visible_ENR(ParseState *pstate, const char *refname);
|
||||
|
||||
#endif /* PARSE_ENR_H */
|
||||
@@ -15,6 +15,7 @@
|
||||
#define PARSE_NODE_H
|
||||
|
||||
#include "nodes/parsenodes.h"
|
||||
#include "utils/queryenvironment.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
|
||||
@@ -188,6 +189,8 @@ struct ParseState
|
||||
bool p_resolve_unknowns; /* resolve unknown-type SELECT outputs
|
||||
* as type text */
|
||||
|
||||
QueryEnvironment *p_queryEnv; /* curr env, incl refs to enclosing env */
|
||||
|
||||
/* Flags telling about things found in the query: */
|
||||
bool p_hasAggs;
|
||||
bool p_hasWindowFuncs;
|
||||
|
||||
@@ -42,6 +42,7 @@ extern RangeTblEntry *refnameRangeTblEntry(ParseState *pstate,
|
||||
extern CommonTableExpr *scanNameSpaceForCTE(ParseState *pstate,
|
||||
const char *refname,
|
||||
Index *ctelevelsup);
|
||||
extern bool scanNameSpaceForENR(ParseState *pstate, const char *refname);
|
||||
extern void checkNameSpaceConflicts(ParseState *pstate, List *namespace1,
|
||||
List *namespace2);
|
||||
extern int RTERangeTablePosn(ParseState *pstate,
|
||||
@@ -107,6 +108,9 @@ extern RangeTblEntry *addRangeTableEntryForCTE(ParseState *pstate,
|
||||
Index levelsup,
|
||||
RangeVar *rv,
|
||||
bool inFromCl);
|
||||
extern RangeTblEntry *addRangeTableEntryForENR(ParseState *pstate,
|
||||
RangeVar *rv,
|
||||
bool inFromCl);
|
||||
extern bool isLockedRefname(ParseState *pstate, const char *refname);
|
||||
extern void addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte,
|
||||
bool addToJoinList,
|
||||
|
||||
Reference in New Issue
Block a user