diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-06 16:34:07 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-06 16:34:07 +0000 |
commit | ad161bcc8a3792d18ef2f3ebe66bb1e22d42b6f2 (patch) | |
tree | 18ec8963fbd1d6dd62ad214bfe3552fc2e7d06eb /src/backend/optimizer/util | |
parent | 0f3748a28c42d09d794ff00af3f1f992eaa5fd7c (diff) | |
download | postgresql-ad161bcc8a3792d18ef2f3ebe66bb1e22d42b6f2.tar.gz postgresql-ad161bcc8a3792d18ef2f3ebe66bb1e22d42b6f2.zip |
Merge Resdom nodes into TargetEntry nodes to simplify code and save a
few palloc's. I also chose to eliminate the restype and restypmod fields
entirely, since they are redundant with information stored in the node's
contained expression; re-examining the expression at need seems simpler
and more reliable than trying to keep restype/restypmod up to date.
initdb forced due to change in contents of stored rules.
Diffstat (limited to 'src/backend/optimizer/util')
-rw-r--r-- | src/backend/optimizer/util/clauses.c | 14 | ||||
-rw-r--r-- | src/backend/optimizer/util/pathnode.c | 4 | ||||
-rw-r--r-- | src/backend/optimizer/util/plancat.c | 19 | ||||
-rw-r--r-- | src/backend/optimizer/util/tlist.c | 99 |
4 files changed, 32 insertions, 104 deletions
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index 2cf4fcd663d..24d74523c37 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.192 2005/03/31 22:46:09 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.193 2005/04/06 16:34:06 tgl Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -966,22 +966,22 @@ has_distinct_on_clause(Query *query) { TargetEntry *tle = (TargetEntry *) lfirst(l); - if (tle->resdom->ressortgroupref == 0) + if (tle->ressortgroupref == 0) { - if (tle->resdom->resjunk) + if (tle->resjunk) continue; /* we can ignore unsorted junk cols */ return true; /* definitely not in DISTINCT list */ } if (targetIsInSortList(tle, query->distinctClause)) { - if (tle->resdom->resjunk) + if (tle->resjunk) return true; /* junk TLE in DISTINCT means DISTINCT ON */ /* else this TLE is okay, keep looking */ } else { /* This TLE is not in DISTINCT list */ - if (!tle->resdom->resjunk) + if (!tle->resjunk) return true; /* non-junk, non-DISTINCT, so DISTINCT ON */ if (targetIsInSortList(tle, query->sortClause)) return true; /* sorted, non-distinct junk */ @@ -3314,10 +3314,6 @@ expression_tree_mutator(Node *node, break; case T_TargetEntry: { - /* - * We mutate the expression, but not the resdom, by - * default. - */ TargetEntry *targetentry = (TargetEntry *) node; TargetEntry *newnode; diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index b6b0cc505f3..14b62b80fc8 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.114 2005/03/27 06:29:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.115 2005/04/06 16:34:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -789,7 +789,7 @@ is_distinct_query(Query *query) TargetEntry *tle = get_sortgroupclause_tle(grpcl, query->targetList); - if (tle->resdom->resjunk) + if (tle->resjunk) break; } if (!gl) /* got to the end? */ diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index c64f2aad1ff..e01a1d76a59 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.103 2005/03/29 00:17:02 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.104 2005/04/06 16:34:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -378,6 +378,7 @@ build_physical_tlist(Query *root, RelOptInfo *rel) for (attrno = 1; attrno <= numattrs; attrno++) { Form_pg_attribute att_tup = relation->rd_att->attrs[attrno - 1]; + Var *var; if (att_tup->attisdropped) { @@ -386,13 +387,17 @@ build_physical_tlist(Query *root, RelOptInfo *rel) break; } + var = makeVar(varno, + attrno, + att_tup->atttypid, + att_tup->atttypmod, + 0); + tlist = lappend(tlist, - create_tl_element(makeVar(varno, - attrno, - att_tup->atttypid, - att_tup->atttypmod, - 0), - attrno)); + makeTargetEntry((Expr *) var, + attrno, + NULL, + false)); } heap_close(relation, AccessShareLock); diff --git a/src/backend/optimizer/util/tlist.c b/src/backend/optimizer/util/tlist.c index d5118de296a..1672cda77c0 100644 --- a/src/backend/optimizer/util/tlist.c +++ b/src/backend/optimizer/util/tlist.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.68 2004/12/31 22:00:23 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.69 2005/04/06 16:34:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -25,12 +25,12 @@ *****************************************************************************/ /* - * tlistentry_member + * tlist_member * Finds the (first) member of the given tlist whose expression is * equal() to the given expression. Result is NULL if no such member. */ TargetEntry * -tlistentry_member(Node *node, List *targetlist) +tlist_member(Node *node, List *targetlist) { ListCell *temp; @@ -44,77 +44,6 @@ tlistentry_member(Node *node, List *targetlist) return NULL; } -#ifdef NOT_USED -/* - * matching_tlist_expr - * Same as tlistentry_member(), except returns the tlist expression - * rather than its parent TargetEntry node. - */ -Node * -matching_tlist_expr(Node *node, List *targetlist) -{ - TargetEntry *tlentry; - - tlentry = tlistentry_member(node, targetlist); - if (tlentry) - return tlentry->expr; - - return NULL; -} -#endif - -/* - * tlist_member - * Same as tlistentry_member(), except returns the Resdom node - * rather than its parent TargetEntry node. - */ -Resdom * -tlist_member(Node *node, List *targetlist) -{ - TargetEntry *tlentry; - - tlentry = tlistentry_member(node, targetlist); - if (tlentry) - return tlentry->resdom; - - return NULL; -} - -/* - * create_tl_element - * Creates a target list entry node and its associated (resdom var) pair - * with its resdom number equal to 'resdomno'. - * - * Note: the argument is almost always a Var, but occasionally not. - */ -TargetEntry * -create_tl_element(Var *var, int resdomno) -{ - Oid vartype; - int32 vartypmod; - - if (IsA(var, Var)) - { - vartype = var->vartype; - vartypmod = var->vartypmod; - } - else - { - vartype = exprType((Node *) var); - vartypmod = exprTypmod((Node *) var); - } - return makeTargetEntry(makeResdom(resdomno, - vartype, - vartypmod, - NULL, - false), - (Expr *) var); -} - -/***************************************************************************** - * ---------- GENERAL target list routines ---------- - *****************************************************************************/ - /* * flatten_tlist * Create a target list that only contains unique variables. @@ -153,24 +82,22 @@ flatten_tlist(List *tlist) List * add_to_flat_tlist(List *tlist, List *vars) { - int next_resdomno = list_length(tlist) + 1; + int next_resno = list_length(tlist) + 1; ListCell *v; foreach(v, vars) { Var *var = (Var *) lfirst(v); - if (!tlistentry_member((Node *) var, tlist)) + if (!tlist_member((Node *) var, tlist)) { - Resdom *r; - - r = makeResdom(next_resdomno++, - var->vartype, - var->vartypmod, - NULL, - false); - tlist = lappend(tlist, - makeTargetEntry(r, copyObject(var))); + TargetEntry *tle; + + tle = makeTargetEntry(copyObject(var), /* copy needed?? */ + next_resno++, + NULL, + false); + tlist = lappend(tlist, tle); } } return tlist; @@ -195,7 +122,7 @@ get_sortgroupclause_tle(SortClause *sortClause, { TargetEntry *tle = (TargetEntry *) lfirst(l); - if (tle->resdom->ressortgroupref == refnumber) + if (tle->ressortgroupref == refnumber) return tle; } |