diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-08-22 20:15:04 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-08-22 20:15:04 +0000 |
commit | 78114cd4d4fd99feb0c753de34d358b16d1ff0ee (patch) | |
tree | 58838858badf427beddaafe425a9def510741d37 /src/include | |
parent | db436adf761bd5cb7990745ceba2959ac4bfca7c (diff) | |
download | postgresql-78114cd4d4fd99feb0c753de34d358b16d1ff0ee.tar.gz postgresql-78114cd4d4fd99feb0c753de34d358b16d1ff0ee.zip |
Further planner/optimizer cleanups. Move all set_tlist_references
and fix_opids processing to a single recursive pass over the plan tree
executed at the very tail end of planning, rather than haphazardly here
and there at different places. Now that tlist Vars do not get modified
until the very end, it's possible to get rid of the klugy var_equal and
match_varid partial-matching routines, and just use plain equal()
throughout the optimizer. This is a step towards allowing merge and
hash joins to be done on expressions instead of only Vars ...
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/nodes/makefuncs.h | 6 | ||||
-rw-r--r-- | src/include/nodes/primnodes.h | 28 | ||||
-rw-r--r-- | src/include/optimizer/clauses.h | 14 | ||||
-rw-r--r-- | src/include/optimizer/planmain.h | 19 | ||||
-rw-r--r-- | src/include/optimizer/tlist.h | 14 | ||||
-rw-r--r-- | src/include/optimizer/var.h | 3 |
6 files changed, 41 insertions, 43 deletions
diff --git a/src/include/nodes/makefuncs.h b/src/include/nodes/makefuncs.h index 6a387fd5c5c..1aaead722d8 100644 --- a/src/include/nodes/makefuncs.h +++ b/src/include/nodes/makefuncs.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: makefuncs.h,v 1.20 1999/07/15 23:03:52 momjian Exp $ + * $Id: makefuncs.h,v 1.21 1999/08/22 20:15:00 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -25,9 +25,7 @@ extern Var *makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, - Index varlevelsup, - Index varnoold, - AttrNumber varoattno); + Index varlevelsup); extern TargetEntry *makeTargetEntry(Resdom *resdom, Node *expr); diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index 4eea81446b2..10e51e40268 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: primnodes.h,v 1.34 1999/08/21 03:49:09 tgl Exp $ + * $Id: primnodes.h,v 1.35 1999/08/22 20:15:00 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -120,15 +120,23 @@ typedef struct Expr /* ---------------- * Var * varno - index of this var's relation in the range table - * (could be INNER or OUTER) + * (could also be INNER or OUTER) * varattno - attribute number of this var, or zero for all - * vartype - pg_type tuple oid for the type of this var + * vartype - pg_type tuple OID for the type of this var * vartypmod - pg_attribute typmod value - * varlevelsup - for subquery variables referencing outer relations - * varnoold - keep varno around in case it got changed to INNER/ - * OUTER (see match_varid) - * varoattno - attribute number of this var - * [ '(varnoold varoattno) was varid -ay 2/95] + * varlevelsup - for subquery variables referencing outer relations; + * 0 in a normal var, >0 means N levels up + * varnoold - original value of varno + * varoattno - original value of varattno + * + * Note: during parsing/planning, varnoold/varoattno are always just copies + * of varno/varattno. At the tail end of planning, Var nodes appearing in + * upper-level plan nodes are reassigned to point to the outputs of their + * subplans; for example, in a join node varno becomes INNER or OUTER and + * varattno becomes the index of the proper element of that subplan's target + * list. But varnoold/varoattno continue to hold the original values. + * The code doesn't really need varnoold/varoattno, but they are very useful + * for debugging and interpreting completed plans, so we keep them around. * ---------------- */ #define INNER 65000 @@ -145,8 +153,8 @@ typedef struct Var Oid vartype; int32 vartypmod; Index varlevelsup; /* erased by upper optimizer */ - Index varnoold; /* only used by optimizer */ - AttrNumber varoattno; /* only used by optimizer */ + Index varnoold; /* mainly for debugging --- see above */ + AttrNumber varoattno; } Var; /* ---------------- diff --git a/src/include/optimizer/clauses.h b/src/include/optimizer/clauses.h index ec2dce883fc..6ea6b4f97ea 100644 --- a/src/include/optimizer/clauses.h +++ b/src/include/optimizer/clauses.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: clauses.h,v 1.28 1999/08/16 02:17:44 tgl Exp $ + * $Id: clauses.h,v 1.29 1999/08/22 20:14:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -38,9 +38,13 @@ extern Expr *make_ands_explicit(List *andclauses); extern List *make_ands_implicit(Expr *clause); extern List *pull_constant_clauses(List *quals, List **constantQual); +extern List *pull_agg_clause(Node *clause); +extern bool check_subplans_for_ungrouped_vars(Node *clause, + List *groupClause, + List *targetList); + extern void clause_get_relids_vars(Node *clause, Relids *relids, List **vars); extern int NumRelids(Node *clause); -extern List *fix_opids(List *clauses); extern void get_relattval(Node *clause, int targetrelid, int *relid, AttrNumber *attno, Datum *constval, int *flag); @@ -53,8 +57,8 @@ extern bool expression_tree_walker(Node *node, bool (*walker) (), extern Node *expression_tree_mutator(Node *node, Node * (*mutator) (), void *context); -#define is_subplan(clause) ((Node*) (clause) != NULL && \ - nodeTag((Node*) (clause)) == T_Expr && \ - ((Expr *) (clause))->opType == SUBPLAN_EXPR) +#define is_subplan(clause) ((clause) != NULL && \ + IsA(clause, Expr) && \ + ((Expr *) (clause))->opType == SUBPLAN_EXPR) #endif /* CLAUSES_H */ diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h index 38ff367384b..3abda02d932 100644 --- a/src/include/optimizer/planmain.h +++ b/src/include/optimizer/planmain.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: planmain.h,v 1.31 1999/08/21 03:49:15 tgl Exp $ + * $Id: planmain.h,v 1.32 1999/08/22 20:14:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -27,14 +27,14 @@ extern Plan *query_planner(Query *root, * prototypes for plan/createplan.c */ extern Plan *create_plan(Path *best_path); -extern SeqScan *make_seqscan(List *qptlist, List *qpqual, Index scanrelid, - Plan *lefttree); +extern SeqScan *make_seqscan(List *qptlist, List *qpqual, Index scanrelid); extern Sort *make_sort(List *tlist, Oid nonameid, Plan *lefttree, int keycount); extern Agg *make_agg(List *tlist, Plan *lefttree); extern Group *make_group(List *tlist, bool tuplePerGroup, int ngrp, AttrNumber *grpColIdx, Plan *lefttree); extern Unique *make_unique(List *tlist, Plan *lefttree, char *uniqueAttr); +extern Result *make_result(List *tlist, Node *resconstantqual, Plan *subplan); /* * prototypes for plan/initsplan.c @@ -47,17 +47,10 @@ extern void add_missing_vars_to_tlist(Query *root, List *tlist); /* * prototypes for plan/setrefs.c */ -extern void set_tlist_references(Plan *plan); +extern void set_plan_references(Plan *plan); extern List *join_references(List *clauses, List *outer_tlist, - List *inner_tlist); -extern void replace_tlist_with_subplan_refs(List *tlist, - Index subvarno, - List *subplanTargetList); -extern bool set_agg_tlist_references(Agg *aggNode); -extern List *pull_agg_clause(Node *clause); -extern void check_having_for_ungrouped_vars(Node *clause, - List *groupClause, - List *targetList); + List *inner_tlist, Index acceptable_rel); +extern void fix_opids(Node *node); /* * prep/prepkeyset.c diff --git a/src/include/optimizer/tlist.h b/src/include/optimizer/tlist.h index f0ddb9ac9dc..58b1b7b2e99 100644 --- a/src/include/optimizer/tlist.h +++ b/src/include/optimizer/tlist.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: tlist.h,v 1.21 1999/08/21 03:49:15 tgl Exp $ + * $Id: tlist.h,v 1.22 1999/08/22 20:14:57 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -15,20 +15,16 @@ #include "nodes/relation.h" -extern TargetEntry *tlistentry_member(Var *var, List *targetlist); -extern Expr *matching_tlist_var(Var *var, List *targetlist); +extern TargetEntry *tlistentry_member(Node *node, List *targetlist); +extern Node *matching_tlist_expr(Node *node, List *targetlist); +extern Resdom *tlist_member(Node *node, List *targetlist); + extern void add_var_to_tlist(RelOptInfo *rel, Var *var); extern TargetEntry *create_tl_element(Var *var, int resdomno); -extern List *get_actual_tlist(List *tlist); -extern Resdom *tlist_member(Var *var, List *tlist); -extern TargetEntry *match_varid(Var *test_var, List *tlist); extern List *new_unsorted_tlist(List *targetlist); -extern List *copy_vars(List *target, List *source); extern List *flatten_tlist(List *tlist); extern List *add_to_flat_tlist(List *tlist, List *vars); -extern List *unflatten_tlist(List *full_tlist, - List *flat_tlist); extern Var *get_expr(TargetEntry *tle); extern Node *get_sortgroupclause_expr(SortClause *sortClause, diff --git a/src/include/optimizer/var.h b/src/include/optimizer/var.h index 16f9f4f6634..440b62f49ad 100644 --- a/src/include/optimizer/var.h +++ b/src/include/optimizer/var.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: var.h,v 1.8 1999/07/15 15:21:23 momjian Exp $ + * $Id: var.h,v 1.9 1999/08/22 20:14:57 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -18,6 +18,5 @@ extern List *pull_varnos(Node *me); extern bool contain_var_clause(Node *clause); extern List *pull_var_clause(Node *clause); -extern bool var_equal(Var *var1, Var *var2); #endif /* VAR_H */ |