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

Commit723476c

Browse files
committed
Make a marginal performance improvement in predicate_implied_by and
predicate_refuted_by: if either top-level input is a single-element list,reduce it to its lone member before proceeding. This avoidsa useless level of AND-recursion within the recursive proof routines.It's worth doing because, for example, if the clause is a 100-elementlist and the predicate is a 1-element list then we'd otherwise stripthe predicate's list structure 100 times as we iterate through the clause.It's only needed at top level because there won't be any trivial ANDs belowthat --- this situation is an artifact of the decision to represent evensingle-item conditions as Lists in the "implicit AND" format, and that formatis only used at the top level of any predicate or restriction condition.
1 parent4db44b4 commit723476c

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

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

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.24 2009/01/09 15:46:10 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.25 2009/05/10 22:45:28 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -124,14 +124,31 @@ static void InvalidateOprProofCacheCallBack(Datum arg, int cacheid, ItemPointer
124124
bool
125125
predicate_implied_by(List*predicate_list,List*restrictinfo_list)
126126
{
127+
Node*p,
128+
*r;
129+
127130
if (predicate_list==NIL)
128131
return true;/* no predicate: implication is vacuous */
129132
if (restrictinfo_list==NIL)
130133
return false;/* no restriction: implication must fail */
131134

132-
/* Otherwise, away we go ... */
133-
returnpredicate_implied_by_recurse((Node*)restrictinfo_list,
134-
(Node*)predicate_list);
135+
/*
136+
* If either input is a single-element list, replace it with its lone
137+
* member; this avoids one useless level of AND-recursion. We only need
138+
* to worry about this at top level, since eval_const_expressions should
139+
* have gotten rid of any trivial ANDs or ORs below that.
140+
*/
141+
if (list_length(predicate_list)==1)
142+
p= (Node*)linitial(predicate_list);
143+
else
144+
p= (Node*)predicate_list;
145+
if (list_length(restrictinfo_list)==1)
146+
r= (Node*)linitial(restrictinfo_list);
147+
else
148+
r= (Node*)restrictinfo_list;
149+
150+
/* And away we go ... */
151+
returnpredicate_implied_by_recurse(r,p);
135152
}
136153

137154
/*
@@ -165,14 +182,31 @@ predicate_implied_by(List *predicate_list, List *restrictinfo_list)
165182
bool
166183
predicate_refuted_by(List*predicate_list,List*restrictinfo_list)
167184
{
185+
Node*p,
186+
*r;
187+
168188
if (predicate_list==NIL)
169189
return false;/* no predicate: no refutation is possible */
170190
if (restrictinfo_list==NIL)
171191
return false;/* no restriction: refutation must fail */
172192

173-
/* Otherwise, away we go ... */
174-
returnpredicate_refuted_by_recurse((Node*)restrictinfo_list,
175-
(Node*)predicate_list);
193+
/*
194+
* If either input is a single-element list, replace it with its lone
195+
* member; this avoids one useless level of AND-recursion. We only need
196+
* to worry about this at top level, since eval_const_expressions should
197+
* have gotten rid of any trivial ANDs or ORs below that.
198+
*/
199+
if (list_length(predicate_list)==1)
200+
p= (Node*)linitial(predicate_list);
201+
else
202+
p= (Node*)predicate_list;
203+
if (list_length(restrictinfo_list)==1)
204+
r= (Node*)linitial(restrictinfo_list);
205+
else
206+
r= (Node*)restrictinfo_list;
207+
208+
/* And away we go ... */
209+
returnpredicate_refuted_by_recurse(r,p);
176210
}
177211

178212
/*----------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp