aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_target.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-01-02 11:29:01 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-01-02 11:29:01 -0500
commit5815696bc66b3092f6361f53e0394909647042c8 (patch)
tree590a95ba0a43325dc14b7fa8f88222c5ef7110a3 /src/backend/parser/parse_target.c
parent198c7153dccb11950e3030dec564fdc6e59b4451 (diff)
downloadpostgresql-5815696bc66b3092f6361f53e0394909647042c8.tar.gz
postgresql-5815696bc66b3092f6361f53e0394909647042c8.zip
Make parser rely more heavily on the ParseNamespaceItem data structure.
When I added the ParseNamespaceItem data structure (in commit 5ebaaa494), it wasn't very tightly integrated into the parser's APIs. In the wake of adding p_rtindex to that struct (commit b541e9acc), there is a good reason to make more use of it: by passing around ParseNamespaceItem pointers instead of bare RTE pointers, we can get rid of various messy methods for passing back or deducing the rangetable index of an RTE during parsing. Hence, refactor the addRangeTableEntryXXX functions to build and return a ParseNamespaceItem struct, not just the RTE proper; and replace addRTEtoQuery with addNSItemToQuery, which is passed a ParseNamespaceItem rather than building one internally. Also, add per-column data (a ParseNamespaceColumn array) to each ParseNamespaceItem. These arrays are built during addRangeTableEntryXXX, where we have column type data at hand so that it's nearly free to fill the data structure. Later, when we need to build Vars referencing RTEs, we can use the ParseNamespaceColumn info to avoid the rather expensive operations done in get_rte_attribute_type() or expandRTE(). get_rte_attribute_type() is indeed dead code now, so I've removed it. This makes for a useful improvement in parse analysis speed, around 20% in one moderately-complex test query. The ParseNamespaceColumn structs also include Var identity information (varno/varattno). That info isn't actually being used in this patch, except that p_varno == 0 is a handy test for a dropped column. A follow-on patch will make more use of it. Discussion: https://postgr.es/m/2461.1577764221@sss.pgh.pa.us
Diffstat (limited to 'src/backend/parser/parse_target.c')
-rw-r--r--src/backend/parser/parse_target.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index 4953cc2a4c2..8476d3cb3f6 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -551,7 +551,7 @@ transformAssignedExpr(ParseState *pstate,
*/
Var *var;
- var = makeVar(pstate->p_target_rtindex, attrno,
+ var = makeVar(pstate->p_target_nsitem->p_rtindex, attrno,
attrtype, attrtypmod, attrcollation, 0);
var->location = location;
@@ -1359,8 +1359,7 @@ ExpandSingleTable(ParseState *pstate, ParseNamespaceItem *nsitem,
List *vars;
ListCell *l;
- expandRTE(rte, nsitem->p_rtindex, sublevels_up, location, false,
- NULL, &vars);
+ vars = expandNSItemVars(nsitem, sublevels_up, location, NULL);
/*
* Require read access to the table. This is normally redundant with
@@ -1496,6 +1495,12 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
Assert(IsA(var, Var));
Assert(var->vartype == RECORDOID);
+ /*
+ * Note: it's tempting to use GetNSItemByRangeTablePosn here so that we
+ * can use expandNSItemVars instead of expandRTE; but that does not work
+ * for some of the recursion cases below, where we have consed up a
+ * ParseState that lacks p_namespace data.
+ */
netlevelsup = var->varlevelsup + levelsup;
rte = GetRTEByRangeTablePosn(pstate, var->varno, netlevelsup);
attnum = var->varattno;