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 */
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 require O(N^2) time, and more often than not fail anyway.
36+ *So we set an arbitrary limit 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- #define MAX_BRANCHES_TO_TEST 100
40+ #define MAX_SAOP_ARRAY_SIZE 100
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 stop after consideringMAX_SAOP_ARRAY_SIZE elements ; in general
743+ *that would result in wrong proofs, rather than failing to prove anything.
744744 */
745745static PredClass
746746predicate_classify (Node * clause ,PredIterInfo info )
@@ -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{
759758info -> startup_fn = list_startup_fn ;
760759info -> 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{
769767info -> startup_fn = boolexpr_startup_fn ;
770768info -> next_fn = list_next_fn ;
771769info -> cleanup_fn = list_cleanup_fn ;
772770return CLASS_AND ;
773771}
774- if (or_clause (clause )&&
775- list_length (((BoolExpr * )clause )-> args ) <=MAX_BRANCHES_TO_TEST )
772+ if (or_clause (clause ))
776773{
777774info -> startup_fn = boolexpr_startup_fn ;
778775info -> next_fn = list_next_fn ;
@@ -800,7 +797,7 @@ predicate_classify(Node *clause, PredIterInfo info)
800797
801798arrayval = DatumGetArrayTypeP (((Const * )arraynode )-> constvalue );
802799nelems = ArrayGetNItems (ARR_NDIM (arrayval ),ARR_DIMS (arrayval ));
803- if (nelems <=MAX_BRANCHES_TO_TEST )
800+ if (nelems <=MAX_SAOP_ARRAY_SIZE )
804801{
805802info -> startup_fn = arrayconst_startup_fn ;
806803info -> next_fn = arrayconst_next_fn ;
@@ -810,7 +807,7 @@ predicate_classify(Node *clause, PredIterInfo info)
810807}
811808else if (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{
815812info -> startup_fn = arrayexpr_startup_fn ;
816813info -> next_fn = arrayexpr_next_fn ;