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

Commit79a1b00

Browse files
committed
Replace slightly klugy create_bitmap_restriction() function with a
more efficient routine in restrictinfo.c (which can make use ofmake_restrictinfo_internal).
1 parent7a4c34c commit79a1b00

File tree

5 files changed

+99
-90
lines changed

5 files changed

+99
-90
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.69 2005/04/2501:30:13 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.70 2005/04/2502:14:47 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -146,7 +146,8 @@ create_or_index_quals(Query *root, RelOptInfo *rel)
146146
* Convert the path's indexclauses structure to a RestrictInfo tree,
147147
* and add it to the rel's restriction list.
148148
*/
149-
newrinfos=create_bitmap_restriction((Path*)bestpath);
149+
newrinfos=make_restrictinfo_from_bitmapqual((Path*)bestpath,
150+
true, true);
150151
Assert(list_length(newrinfos)==1);
151152
or_rinfo= (RestrictInfo*)linitial(newrinfos);
152153
Assert(IsA(or_rinfo,RestrictInfo));

‎src/backend/optimizer/plan/createplan.c

Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.185 2005/04/2501:30:13 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.186 2005/04/2502:14:47 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -54,7 +54,6 @@ static BitmapHeapScan *create_bitmap_scan_plan(Query *root,
5454
List*tlist,List*scan_clauses);
5555
staticPlan*create_bitmap_subplan(Query*root,Path*bitmapqual,
5656
List**qual,List**indexqual);
57-
staticList*create_bitmap_qual(Path*bitmapqual);
5857
staticTidScan*create_tidscan_plan(Query*root,TidPath*best_path,
5958
List*tlist,List*scan_clauses);
6059
staticSubqueryScan*create_subqueryscan_plan(Query*root,Path*best_path,
@@ -981,86 +980,6 @@ create_bitmap_subplan(Query *root, Path *bitmapqual,
981980
returnplan;
982981
}
983982

984-
/*
985-
* Given a bitmapqual tree, generate the equivalent ordinary expression tree
986-
* (which we need for the bitmapqualorig field of the BitmapHeapScan plan).
987-
* The result is expressed as an implicit-AND list.
988-
*/
989-
staticList*
990-
create_bitmap_qual(Path*bitmapqual)
991-
{
992-
List*result;
993-
List*sublist;
994-
995-
if (IsA(bitmapqual,BitmapAndPath))
996-
{
997-
BitmapAndPath*apath= (BitmapAndPath*)bitmapqual;
998-
ListCell*l;
999-
1000-
result=NIL;
1001-
foreach(l,apath->bitmapquals)
1002-
{
1003-
sublist=create_bitmap_qual(lfirst(l));
1004-
result=list_concat(result,sublist);
1005-
}
1006-
}
1007-
elseif (IsA(bitmapqual,BitmapOrPath))
1008-
{
1009-
BitmapOrPath*opath= (BitmapOrPath*)bitmapqual;
1010-
List*newlist=NIL;
1011-
ListCell*l;
1012-
1013-
foreach(l,opath->bitmapquals)
1014-
{
1015-
sublist=create_bitmap_qual(lfirst(l));
1016-
if (sublist==NIL)
1017-
{
1018-
/* constant TRUE input yields constant TRUE OR result */
1019-
returnNIL;
1020-
}
1021-
newlist=lappend(newlist,make_ands_explicit(sublist));
1022-
}
1023-
result=list_make1(make_orclause(newlist));
1024-
}
1025-
elseif (IsA(bitmapqual,IndexPath))
1026-
{
1027-
IndexPath*ipath= (IndexPath*)bitmapqual;
1028-
1029-
result=get_actual_clauses(ipath->indexclauses);
1030-
}
1031-
else
1032-
{
1033-
elog(ERROR,"unrecognized node type: %d",nodeTag(bitmapqual));
1034-
result=NIL;/* keep compiler quiet */
1035-
}
1036-
1037-
returnresult;
1038-
}
1039-
1040-
/*
1041-
* Given a bitmapqual tree, generate the equivalent RestrictInfo list.
1042-
*/
1043-
List*
1044-
create_bitmap_restriction(Path*bitmapqual)
1045-
{
1046-
List*bitmapquals;
1047-
List*bitmapclauses;
1048-
ListCell*l;
1049-
1050-
bitmapquals=create_bitmap_qual(bitmapqual);
1051-
1052-
/* must convert qual list to restrictinfos ... painful ... */
1053-
bitmapclauses=NIL;
1054-
foreach(l,bitmapquals)
1055-
{
1056-
bitmapclauses=lappend(bitmapclauses,
1057-
make_restrictinfo((Expr*)lfirst(l),
1058-
true, true));
1059-
}
1060-
1061-
returnbitmapclauses;
1062-
}
1063-
1064983
/*
1065984
* create_tidscan_plan
1066985
* Returns a tidscan plan for the base relation scanned by 'best_path'
@@ -1210,7 +1129,9 @@ create_nestloop_plan(Query *root,
12101129
{
12111130
List*bitmapclauses;
12121131

1213-
bitmapclauses=create_bitmap_restriction(innerpath->bitmapqual);
1132+
bitmapclauses=
1133+
make_restrictinfo_from_bitmapqual(innerpath->bitmapqual,
1134+
true, true);
12141135
joinrestrictclauses=
12151136
select_nonredundant_join_clauses(root,
12161137
joinrestrictclauses,

‎src/backend/optimizer/util/restrictinfo.c

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.34 2005/04/2501:30:13 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.35 2005/04/2502:14:47 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -65,10 +65,95 @@ make_restrictinfo(Expr *clause, bool is_pushed_down, bool valid_everywhere)
6565
is_pushed_down,valid_everywhere);
6666
}
6767

68+
/*
69+
* make_restrictinfo_from_bitmapqual
70+
*
71+
* Given the bitmapqual Path structure for a bitmap indexscan, generate
72+
* RestrictInfo node(s) equivalent to the condition represented by the
73+
* indexclauses of the Path structure.
74+
*
75+
* The result is a List since we might need to return multiple RestrictInfos.
76+
*
77+
* To do this through the normal make_restrictinfo() API, callers would have
78+
* to strip off the RestrictInfo nodes present in the indexclauses lists, and
79+
* then make_restrictinfo() would have to build new ones. It's better to have
80+
* a specialized routine to allow sharing of RestrictInfos.
81+
*/
82+
List*
83+
make_restrictinfo_from_bitmapqual(Path*bitmapqual,
84+
boolis_pushed_down,
85+
boolvalid_everywhere)
86+
{
87+
List*result;
88+
89+
if (IsA(bitmapqual,BitmapAndPath))
90+
{
91+
BitmapAndPath*apath= (BitmapAndPath*)bitmapqual;
92+
ListCell*l;
93+
94+
result=NIL;
95+
foreach(l,apath->bitmapquals)
96+
{
97+
List*sublist;
98+
99+
sublist=make_restrictinfo_from_bitmapqual((Path*)lfirst(l),
100+
is_pushed_down,
101+
valid_everywhere);
102+
result=list_concat(result,sublist);
103+
}
104+
}
105+
elseif (IsA(bitmapqual,BitmapOrPath))
106+
{
107+
BitmapOrPath*opath= (BitmapOrPath*)bitmapqual;
108+
List*withris=NIL;
109+
List*withoutris=NIL;
110+
ListCell*l;
111+
112+
foreach(l,opath->bitmapquals)
113+
{
114+
List*sublist;
115+
116+
sublist=make_restrictinfo_from_bitmapqual((Path*)lfirst(l),
117+
is_pushed_down,
118+
valid_everywhere);
119+
if (sublist==NIL)
120+
{
121+
/* constant TRUE input yields constant TRUE OR result */
122+
/* (though this probably cannot happen) */
123+
returnNIL;
124+
}
125+
/* Create AND subclause with RestrictInfos */
126+
withris=lappend(withris,make_ands_explicit(sublist));
127+
/* And one without */
128+
sublist=get_actual_clauses(sublist);
129+
withoutris=lappend(withoutris,make_ands_explicit(sublist));
130+
}
131+
/* Here's the magic part not available to outside callers */
132+
result=
133+
list_make1(make_restrictinfo_internal(make_orclause(withoutris),
134+
make_orclause(withris),
135+
is_pushed_down,
136+
valid_everywhere));
137+
}
138+
elseif (IsA(bitmapqual,IndexPath))
139+
{
140+
IndexPath*ipath= (IndexPath*)bitmapqual;
141+
142+
result=list_copy(ipath->indexclauses);
143+
}
144+
else
145+
{
146+
elog(ERROR,"unrecognized node type: %d",nodeTag(bitmapqual));
147+
result=NIL;/* keep compiler quiet */
148+
}
149+
150+
returnresult;
151+
}
152+
68153
/*
69154
* make_restrictinfo_internal
70155
*
71-
* Common code for the main entrypoint and the recursive cases.
156+
* Common code for the main entrypoints and the recursive cases.
72157
*/
73158
staticRestrictInfo*
74159
make_restrictinfo_internal(Expr*clause,Expr*orclause,

‎src/include/optimizer/planmain.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.83 2005/04/2501:30:14 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.84 2005/04/2502:14:48 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -33,7 +33,6 @@ extern Plan *optimize_minmax_aggregates(Query *root, List *tlist,
3333
* prototypes for plan/createplan.c
3434
*/
3535
externPlan*create_plan(Query*root,Path*best_path);
36-
externList*create_bitmap_restriction(Path*bitmapqual);
3736
externSubqueryScan*make_subqueryscan(List*qptlist,List*qpqual,
3837
Indexscanrelid,Plan*subplan);
3938
externAppend*make_append(List*appendplans,boolisTarget,List*tlist);

‎src/include/optimizer/restrictinfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.28 2005/04/2501:30:14 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.29 2005/04/2502:14:48 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -18,6 +18,9 @@
1818

1919
externRestrictInfo*make_restrictinfo(Expr*clause,boolis_pushed_down,
2020
boolvalid_everywhere);
21+
externList*make_restrictinfo_from_bitmapqual(Path*bitmapqual,
22+
boolis_pushed_down,
23+
boolvalid_everywhere);
2124
externboolrestriction_is_or_clause(RestrictInfo*restrictinfo);
2225
externList*get_actual_clauses(List*restrictinfo_list);
2326
externvoidget_actual_join_clauses(List*restrictinfo_list,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp