Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit78114cd

Browse files
committed
Further planner/optimizer cleanups. Move all set_tlist_references
and fix_opids processing to a single recursive pass over the plan treeexecuted at the very tail end of planning, rather than haphazardly hereand there at different places. Now that tlist Vars do not get modifieduntil the very end, it's possible to get rid of the klugy var_equal andmatch_varid partial-matching routines, and just use plain equal()throughout the optimizer. This is a step towards allowing merge andhash joins to be done on expressions instead of only Vars ...
1 parentdb436ad commit78114cd

File tree

24 files changed

+650
-951
lines changed

24 files changed

+650
-951
lines changed

‎doc/src/sgml/arch-dev.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,7 @@ having clause} is found.
24752475
+ if(node->plan.qual != NULL)
24762476
+ {
24772477
+ qual_result =
2478-
+ ExecQual(fix_opids(node->plan.qual),
2478+
+ ExecQual(node->plan.qual,
24792479
+ econtext);
24802480
+ }
24812481
+ if (oneTuple) pfree(oneTuple);

‎src/backend/commands/indexcmds.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.9 1999/07/17 20:16:52 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.10 1999/08/22 20:14:37 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -24,6 +24,7 @@
2424
#include"catalog/pg_type.h"
2525
#include"commands/defrem.h"
2626
#include"optimizer/clauses.h"
27+
#include"optimizer/planmain.h"
2728
#include"optimizer/prep.h"
2829
#include"parser/parsetree.h"
2930
#include"utils/builtins.h"
@@ -142,7 +143,7 @@ DefineIndex(char *heapRelationName,
142143
if (predicate!=NULL&&rangetable!=NIL)
143144
{
144145
cnfPred=cnfify((Expr*)copyObject(predicate), true);
145-
fix_opids(cnfPred);
146+
fix_opids((Node*)cnfPred);
146147
CheckPredicate(cnfPred,rangetable,relationId);
147148
}
148149

@@ -285,7 +286,7 @@ ExtendIndex(char *indexRelationName, Expr *predicate, List *rangetable)
285286
if (rangetable!=NIL)
286287
{
287288
cnfPred=cnfify((Expr*)copyObject(predicate), true);
288-
fix_opids(cnfPred);
289+
fix_opids((Node*)cnfPred);
289290
CheckPredicate(cnfPred,rangetable,relationId);
290291
}
291292

‎src/backend/executor/nodeAgg.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include"executor/executor.h"
2424
#include"executor/nodeAgg.h"
2525
#include"optimizer/clauses.h"
26-
#include"optimizer/planmain.h"
2726
#include"parser/parse_type.h"
2827
#include"utils/syscache.h"
2928

@@ -443,7 +442,7 @@ ExecAgg(Agg *node)
443442
* qualifications it is ignored and the next group is fetched
444443
*/
445444
if (node->plan.qual!=NULL)
446-
qual_result=ExecQual(fix_opids(node->plan.qual),econtext);
445+
qual_result=ExecQual(node->plan.qual,econtext);
447446
else
448447
qual_result= false;
449448

‎src/backend/nodes/makefuncs.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.17 1999/08/21 03:48:58 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.18 1999/08/22 20:14:59 tgl Exp $
1111
*
1212
* NOTES
1313
* Creator functions in POSTGRES 4.2 are generated automatically. Most of
@@ -52,9 +52,7 @@ makeVar(Index varno,
5252
AttrNumbervarattno,
5353
Oidvartype,
5454
int32vartypmod,
55-
Indexvarlevelsup,
56-
Indexvarnoold,
57-
AttrNumbervaroattno)
55+
Indexvarlevelsup)
5856
{
5957
Var*var=makeNode(Var);
6058

@@ -63,8 +61,14 @@ makeVar(Index varno,
6361
var->vartype=vartype;
6462
var->vartypmod=vartypmod;
6563
var->varlevelsup=varlevelsup;
66-
var->varnoold=varnoold;
67-
var->varoattno=varoattno;
64+
/*
65+
* Since few if any routines ever create Var nodes with varnoold/varoattno
66+
* different from varno/varattno, we don't provide separate arguments
67+
* for them, but just initialize them to the given varno/varattno.
68+
* This reduces code clutter and chance of error for most callers.
69+
*/
70+
var->varnoold=varno;
71+
var->varoattno=varattno;
6872

6973
returnvar;
7074
}

‎src/backend/optimizer/path/costsize.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Copyright (c) 1994, Regents of the University of California
1919
*
2020
* IDENTIFICATION
21-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.44 1999/08/06 04:00:15 tgl Exp $
21+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.45 1999/08/22 20:14:41 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -431,7 +431,7 @@ compute_rel_size(RelOptInfo *rel)
431431
int
432432
compute_rel_width(RelOptInfo*rel)
433433
{
434-
returncompute_targetlist_width(get_actual_tlist(rel->targetlist));
434+
returncompute_targetlist_width(rel->targetlist);
435435
}
436436

437437
/*
@@ -448,8 +448,7 @@ compute_targetlist_width(List *targetlist)
448448

449449
foreach(temp_tl,targetlist)
450450
{
451-
tuple_width=tuple_width+
452-
compute_attribute_width(lfirst(temp_tl));
451+
tuple_width+=compute_attribute_width(lfirst(temp_tl));
453452
}
454453
returntuple_width;
455454
}

‎src/backend/optimizer/path/pathkeys.c

Lines changed: 26 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.15 1999/08/21 03:49:01 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.16 1999/08/22 20:14:42 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -24,8 +24,6 @@
2424
#include"utils/lsyscache.h"
2525

2626
staticPathKeyItem*makePathKeyItem(Node*key,Oidsortop);
27-
staticboolpathkeyitem_equal(PathKeyItem*a,PathKeyItem*b);
28-
staticboolpathkeyitem_member(PathKeyItem*a,List*l);
2927
staticVar*find_indexkey_var(intindexkey,List*tlist);
3028
staticList*build_join_pathkey(List*pathkeys,List*join_rel_tlist,
3129
List*joinclauses);
@@ -118,45 +116,6 @@ makePathKeyItem(Node *key, Oid sortop)
118116
*PATHKEY COMPARISONS
119117
****************************************************************************/
120118

121-
/*
122-
* Compare two pathkey items for equality.
123-
*
124-
* This is unlike straight equal() because when the two keys are both Vars,
125-
* we want to apply the weaker var_equal() condition (doesn't check varnoold
126-
* or varoattno). But if that fails, try equal() so that we recognize
127-
* functional-index keys.
128-
*/
129-
staticbool
130-
pathkeyitem_equal (PathKeyItem*a,PathKeyItem*b)
131-
{
132-
Assert(a&&IsA(a,PathKeyItem));
133-
Assert(b&&IsA(b,PathKeyItem));
134-
135-
if (a->sortop!=b->sortop)
136-
return false;
137-
if (var_equal((Var*)a->key, (Var*)b->key))
138-
return true;
139-
returnequal(a->key,b->key);
140-
}
141-
142-
/*
143-
* member() test using pathkeyitem_equal
144-
*/
145-
staticbool
146-
pathkeyitem_member (PathKeyItem*a,List*l)
147-
{
148-
List*i;
149-
150-
Assert(a&&IsA(a,PathKeyItem));
151-
152-
foreach(i,l)
153-
{
154-
if (pathkeyitem_equal(a, (PathKeyItem*)lfirst(i)))
155-
return true;
156-
}
157-
return false;
158-
}
159-
160119
/*
161120
* compare_pathkeys
162121
* Compare two pathkeys to see if they are equivalent, and if not whether
@@ -191,7 +150,7 @@ compare_pathkeys(List *keys1, List *keys2)
191150
{
192151
foreach(i,subkey1)
193152
{
194-
if (!pathkeyitem_member((PathKeyItem*)lfirst(i),subkey2))
153+
if (!member(lfirst(i),subkey2))
195154
{
196155
key1_subsetof_key2= false;
197156
break;
@@ -203,7 +162,7 @@ compare_pathkeys(List *keys1, List *keys2)
203162
{
204163
foreach(i,subkey2)
205164
{
206-
if (!pathkeyitem_member((PathKeyItem*)lfirst(i),subkey1))
165+
if (!member(lfirst(i),subkey1))
207166
{
208167
key2_subsetof_key1= false;
209168
break;
@@ -336,8 +295,8 @@ build_index_pathkeys(Query *root, RelOptInfo *rel, RelOptInfo *index)
336295
int32type_mod=get_atttypmod(reloid,varattno);
337296

338297
funcargs=lappend(funcargs,
339-
makeVar(relid,varattno,vartypeid,type_mod,
340-
0,relid,varattno));
298+
makeVar(relid,varattno,vartypeid,
299+
type_mod,0));
341300
indexkeys++;
342301
}
343302

@@ -483,13 +442,13 @@ build_join_pathkey(List *pathkey,
483442
foreach(i,pathkey)
484443
{
485444
PathKeyItem*key= (PathKeyItem*)lfirst(i);
486-
Expr*tlist_key;
445+
Node*tlist_key;
487446

488447
Assert(key&&IsA(key,PathKeyItem));
489448

490-
tlist_key=matching_tlist_var((Var*)key->key,join_rel_tlist);
449+
tlist_key=matching_tlist_expr(key->key,join_rel_tlist);
491450
if (tlist_key)
492-
new_pathkey=lcons(makePathKeyItem((Node*)tlist_key,
451+
new_pathkey=lcons(makePathKeyItem(tlist_key,
493452
key->sortop),
494453
new_pathkey);
495454

@@ -498,27 +457,27 @@ build_join_pathkey(List *pathkey,
498457
RestrictInfo*restrictinfo= (RestrictInfo*)lfirst(j);
499458
Expr*joinclause=restrictinfo->clause;
500459
/* We assume the clause is a binary opclause... */
501-
Var*l=get_leftop(joinclause);
502-
Var*r=get_rightop(joinclause);
503-
Var*other_var=NULL;
460+
Node*l= (Node*)get_leftop(joinclause);
461+
Node*r= (Node*)get_rightop(joinclause);
462+
Node*other_var=NULL;
504463
Oidother_sortop=InvalidOid;
505464

506-
if (var_equal((Var*)key->key,l))
465+
if (equal(key->key,l))
507466
{
508467
other_var=r;
509468
other_sortop=restrictinfo->right_sortop;
510469
}
511-
elseif (var_equal((Var*)key->key,r))
470+
elseif (equal(key->key,r))
512471
{
513472
other_var=l;
514473
other_sortop=restrictinfo->left_sortop;
515474
}
516475

517476
if (other_var&&other_sortop)
518477
{
519-
tlist_key=matching_tlist_var(other_var,join_rel_tlist);
478+
tlist_key=matching_tlist_expr(other_var,join_rel_tlist);
520479
if (tlist_key)
521-
new_pathkey=lcons(makePathKeyItem((Node*)tlist_key,
480+
new_pathkey=lcons(makePathKeyItem(tlist_key,
522481
other_sortop),
523482
new_pathkey);
524483
}
@@ -638,20 +597,17 @@ find_mergeclauses_for_pathkeys(List *pathkeys, List *restrictinfos)
638597
foreach(j,pathkey)
639598
{
640599
PathKeyItem*keyitem=lfirst(j);
641-
Var*keyvar= (Var*)keyitem->key;
600+
Node*key=keyitem->key;
642601
List*k;
643602

644-
if (!IsA(keyvar,Var))
645-
continue;/* for now, only Vars can be mergejoined */
646-
647603
foreach(k,restrictinfos)
648604
{
649605
RestrictInfo*restrictinfo=lfirst(k);
650606

651607
Assert(restrictinfo->mergejoinoperator!=InvalidOid);
652608

653-
if ((var_equal(keyvar,get_leftop(restrictinfo->clause))||
654-
var_equal(keyvar,get_rightop(restrictinfo->clause)))&&
609+
if ((equal(key,get_leftop(restrictinfo->clause))||
610+
equal(key,get_rightop(restrictinfo->clause)))&&
655611
!member(restrictinfo,mergeclauses))
656612
{
657613
matched_restrictinfo=restrictinfo;
@@ -705,23 +661,24 @@ make_pathkeys_for_mergeclauses(List *mergeclauses, List *tlist)
705661
foreach(i,mergeclauses)
706662
{
707663
RestrictInfo*restrictinfo= (RestrictInfo*)lfirst(i);
708-
Var*key;
664+
Node*key;
709665
Oidsortop;
710666

667+
Assert(restrictinfo->mergejoinoperator!=InvalidOid);
668+
711669
/*
712670
* Find the key and sortop needed for this mergeclause.
713671
*
714672
* We can use either side of the mergeclause, since we haven't yet
715673
* committed to which side will be inner.
716674
*/
717-
Assert(restrictinfo->mergejoinoperator!=InvalidOid);
718-
key= (Var*)matching_tlist_var(get_leftop(restrictinfo->clause),
719-
tlist);
675+
key=matching_tlist_expr((Node*)get_leftop(restrictinfo->clause),
676+
tlist);
720677
sortop=restrictinfo->left_sortop;
721678
if (!key)
722679
{
723-
key=(Var*)matching_tlist_var(get_rightop(restrictinfo->clause),
724-
tlist);
680+
key=matching_tlist_expr((Node*)get_rightop(restrictinfo->clause),
681+
tlist);
725682
sortop=restrictinfo->right_sortop;
726683
}
727684
if (!key)
@@ -730,7 +687,7 @@ make_pathkeys_for_mergeclauses(List *mergeclauses, List *tlist)
730687
* Add a pathkey sublist for this sort item
731688
*/
732689
pathkeys=lappend(pathkeys,
733-
lcons(makePathKeyItem((Node*)key,sortop),
690+
lcons(makePathKeyItem(key,sortop),
734691
NIL));
735692
}
736693

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp