diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-05 00:38:11 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-05 00:38:11 +0000 |
commit | a4996a895399a4b0363c7dace71fc6ce8acbc196 (patch) | |
tree | 9fe26cb35badc6a7b0c86a9db1eaf2e7ca95b142 /src/include | |
parent | efe0d0808b055fb2f651dd3732bd770290eb2659 (diff) | |
download | postgresql-a4996a895399a4b0363c7dace71fc6ce8acbc196.tar.gz postgresql-a4996a895399a4b0363c7dace71fc6ce8acbc196.zip |
Replace the parser's namespace tree (which formerly had the same
representation as the jointree) with two lists of RTEs, one showing
the RTEs accessible by qualified names, and the other showing the RTEs
accessible by unqualified names. I think this is conceptually simpler
than what we did before, and it's sure a whole lot easier to search.
This seems to eliminate the parse-time bottleneck for deeply nested
JOIN structures that was exhibited by phil@vodafone.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/nodes/parsenodes.h | 12 | ||||
-rw-r--r-- | src/include/parser/parse_node.h | 24 | ||||
-rw-r--r-- | src/include/parser/parse_relation.h | 9 |
3 files changed, 27 insertions, 18 deletions
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 1208def12ce..9a525eb1de0 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.279 2005/06/03 23:05:29 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.280 2005/06/05 00:38:10 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -479,10 +479,10 @@ typedef struct DefElem * FROM clause, but POSTQUEL allows you to refer to tables not listed, * in which case a range table entry will be generated. We still support * this POSTQUEL feature, although there is some doubt whether it's - * convenient or merely confusing. The flag is needed since an - * implicitly-added RTE shouldn't change the namespace for unqualified - * column names processed later, and it also shouldn't affect the - * expansion of '*'. + * convenient or merely confusing. The flag is not actually needed + * anymore during parsing, since the parser uses a separate "namespace" + * data structure to control visibility, but it is needed by ruleutils.c + * to determine whether RTEs should be included in decompiled queries. * * requiredPerms and checkAsUser specify run-time access permissions * checks to be performed at query startup. The user must have *all* @@ -552,7 +552,7 @@ typedef struct RangeTblEntry Alias *alias; /* user-written alias clause, if any */ Alias *eref; /* expanded reference names */ bool inh; /* inheritance requested? */ - bool inFromCl; /* present in FROM clause */ + bool inFromCl; /* present in FROM clause? */ AclMode requiredPerms; /* bitmask of required access permissions */ AclId checkAsUser; /* if not zero, check access as this user */ } RangeTblEntry; diff --git a/src/include/parser/parse_node.h b/src/include/parser/parse_node.h index bfcf00fd47d..291282e0920 100644 --- a/src/include/parser/parse_node.h +++ b/src/include/parser/parse_node.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/parser/parse_node.h,v 1.43 2005/04/28 21:47:18 tgl Exp $ + * $PostgreSQL: pgsql/src/include/parser/parse_node.h,v 1.44 2005/06/05 00:38:11 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -27,12 +27,19 @@ * p_joinlist: list of join items (RangeTblRef and JoinExpr nodes) that * will become the fromlist of the query's top-level FromExpr node. * - * p_namespace: list of join items that represents the current namespace - * for table and column lookup. This may be just a subset of the rtable + - * joinlist, and/or may contain entries that are not yet added to the main - * joinlist. Note that an RTE that is present in p_namespace, but does not - * have its inFromCl flag set, is accessible only with an explicit qualifier; - * lookups of unqualified column names should ignore it. + * p_relnamespace: list of RTEs that represents the current namespace for + * table lookup, ie, those RTEs that are accessible by qualified names. + * This may be just a subset of the rtable + joinlist, and/or may contain + * entries that are not yet added to the main joinlist. + * + * p_varnamespace: list of RTEs that represents the current namespace for + * column lookup, ie, those RTEs that are accessible by unqualified names. + * This is different from p_relnamespace because a JOIN without an alias does + * not hide the contained tables (so they must still be in p_relnamespace) + * but it does hide their columns (unqualified references to the columns must + * refer to the JOIN, not the member tables). Also, we put POSTQUEL-style + * implicit RTEs into p_relnamespace but not p_varnamespace, so that they + * do not affect the set of columns available for unqualified references. * * p_paramtypes: an array of p_numparams type OIDs for $n parameter symbols * (zeroth entry in array corresponds to $1). If p_variableparams is true, the @@ -49,7 +56,8 @@ typedef struct ParseState List *p_rtable; /* range table so far */ List *p_joinlist; /* join items so far (will become FromExpr * node's fromlist) */ - List *p_namespace; /* current lookup namespace (join items) */ + List *p_relnamespace; /* current namespace for relations */ + List *p_varnamespace; /* current namespace for columns */ Oid *p_paramtypes; /* OIDs of types for $n parameter symbols */ int p_numparams; /* allocated size of p_paramtypes[] */ int p_next_resno; /* next targetlist resno to assign */ diff --git a/src/include/parser/parse_relation.h b/src/include/parser/parse_relation.h index b74098e10c7..e6d989cf87e 100644 --- a/src/include/parser/parse_relation.h +++ b/src/include/parser/parse_relation.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/parser/parse_relation.h,v 1.50 2005/06/04 19:19:42 tgl Exp $ + * $PostgreSQL: pgsql/src/include/parser/parse_relation.h,v 1.51 2005/06/05 00:38:11 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -22,8 +22,8 @@ extern RangeTblEntry *refnameRangeTblEntry(ParseState *pstate, const char *schemaname, const char *refname, int *sublevels_up); -extern void checkNameSpaceConflicts(ParseState *pstate, Node *namespace1, - Node *namespace2); +extern void checkNameSpaceConflicts(ParseState *pstate, List *namespace1, + List *namespace2); extern int RTERangeTablePosn(ParseState *pstate, RangeTblEntry *rte, int *sublevels_up); @@ -64,7 +64,8 @@ extern RangeTblEntry *addRangeTableEntryForJoin(ParseState *pstate, Alias *alias, bool inFromCl); extern void addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte, - bool addToJoinList, bool addToNameSpace); + bool addToJoinList, + bool addToRelNameSpace, bool addToVarNameSpace); extern RangeTblEntry *addImplicitRTE(ParseState *pstate, RangeVar *relation); extern void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, bool include_dropped, |