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

Commit6480c14

Browse files
committed
Partially revert my patch of 2008-11-12 that installed a limit on the number
of AND/OR clause branches that predtest.c would attempt to deal with. Asnoted in bug #4721, that change disabled proof attempts for sizes of problemsthat people are actually expecting it to work for. The original complaintit was trying to solve was O(N^2) behavior for long IN-lists, so let's tryapplying the limit to just ScalarArrayOpExprs rather than everything.Another case of "foolish consistency" I fear.Back-patch to 8.2, same as the previous patch was.
1 parente54ec92 commit6480c14

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

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

Lines changed: 18 additions & 21 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.25 2009/05/10 22:45:28 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.26 2009/05/11 17:56:08 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -31,13 +31,13 @@
3131

3232

3333
/*
34-
* Proof attempts involvingmany AND or OR branches are likely to require
35-
* O(N^2) time, and more often than not fail anyway. So we set an arbitrary
36-
* limit on the number ofbranches that we will allow at any one level of
37-
*clause. (Note that this is only effective because the trees have been
38-
*AND/OR flattened!)XXX is it worth exposing this as a GUC knob?
34+
* Proof attempts involvinglarge arrays in ScalarArrayOpExpr nodes are
35+
*likely to requireO(N^2) time, and more often than not fail anyway.
36+
*So we set an arbitrarylimit on the number ofarray elements that
37+
*we will allow to be treated as an AND or OR clause.
38+
* XXX is it worth exposing this as a GUC knob?
3939
*/
40-
#defineMAX_BRANCHES_TO_TEST100
40+
#defineMAX_SAOP_ARRAY_SIZE100
4141

4242
/*
4343
* To avoid redundant coding in predicate_implied_by_recurse and
@@ -735,12 +735,12 @@ predicate_refuted_by_recurse(Node *clause, Node *predicate)
735735
* If the expression is classified as AND- or OR-type, then *info is filled
736736
* in with the functions needed to iterate over its components.
737737
*
738-
* This function also implements enforcement ofMAX_BRANCHES_TO_TEST: ifan
739-
*AND/OR expression has too manybranches, we just classify it as an atom.
740-
* (This will result in its being passed as-is to the simple_clause functions,
741-
* which will fail to prove anything about it.) Note that we cannot just stop
742-
* after consideringMAX_BRANCHES_TO_TEST branches; in general that would
743-
* result in wrong proofs rather than failing to prove anything.
738+
* This function also implements enforcement ofMAX_SAOP_ARRAY_SIZE: ifa
739+
*ScalarArrayOpExpr's array has too manyelements, we just classify it as an
740+
*atom.(This will result in its being passed as-is to the simple_clause
741+
*functions,which will fail to prove anything about it.) Note that we
742+
*cannot just stopafter consideringMAX_SAOP_ARRAY_SIZE elements; in general
743+
*that wouldresult in wrong proofs, rather than failing to prove anything.
744744
*/
745745
staticPredClass
746746
predicate_classify(Node*clause,PredIterInfoinfo)
@@ -753,8 +753,7 @@ predicate_classify(Node *clause, PredIterInfo info)
753753
* If we see a List, assume it's an implicit-AND list; this is the correct
754754
* semantics for lists of RestrictInfo nodes.
755755
*/
756-
if (IsA(clause,List)&&
757-
list_length((List*)clause) <=MAX_BRANCHES_TO_TEST)
756+
if (IsA(clause,List))
758757
{
759758
info->startup_fn=list_startup_fn;
760759
info->next_fn=list_next_fn;
@@ -763,16 +762,14 @@ predicate_classify(Node *clause, PredIterInfo info)
763762
}
764763

765764
/* Handle normal AND and OR boolean clauses */
766-
if (and_clause(clause)&&
767-
list_length(((BoolExpr*)clause)->args) <=MAX_BRANCHES_TO_TEST)
765+
if (and_clause(clause))
768766
{
769767
info->startup_fn=boolexpr_startup_fn;
770768
info->next_fn=list_next_fn;
771769
info->cleanup_fn=list_cleanup_fn;
772770
returnCLASS_AND;
773771
}
774-
if (or_clause(clause)&&
775-
list_length(((BoolExpr*)clause)->args) <=MAX_BRANCHES_TO_TEST)
772+
if (or_clause(clause))
776773
{
777774
info->startup_fn=boolexpr_startup_fn;
778775
info->next_fn=list_next_fn;
@@ -800,7 +797,7 @@ predicate_classify(Node *clause, PredIterInfo info)
800797

801798
arrayval=DatumGetArrayTypeP(((Const*)arraynode)->constvalue);
802799
nelems=ArrayGetNItems(ARR_NDIM(arrayval),ARR_DIMS(arrayval));
803-
if (nelems <=MAX_BRANCHES_TO_TEST)
800+
if (nelems <=MAX_SAOP_ARRAY_SIZE)
804801
{
805802
info->startup_fn=arrayconst_startup_fn;
806803
info->next_fn=arrayconst_next_fn;
@@ -810,7 +807,7 @@ predicate_classify(Node *clause, PredIterInfo info)
810807
}
811808
elseif (arraynode&&IsA(arraynode,ArrayExpr)&&
812809
!((ArrayExpr*)arraynode)->multidims&&
813-
list_length(((ArrayExpr*)arraynode)->elements) <=MAX_BRANCHES_TO_TEST)
810+
list_length(((ArrayExpr*)arraynode)->elements) <=MAX_SAOP_ARRAY_SIZE)
814811
{
815812
info->startup_fn=arrayexpr_startup_fn;
816813
info->next_fn=arrayexpr_next_fn;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp