pred_test() logic was being too narrow-minded about where it might find
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 5 Nov 2004 20:45:10 +0000 (20:45 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 5 Nov 2004 20:45:10 +0000 (20:45 +0000)
RestrictInfo nodes in the query expression.  Per example from James Robinson.

src/backend/optimizer/path/indxpath.c

index 2a0c3d1c5d64b9373f152b343dabae645772e240..961b382e683daf2b2a437cab9eb1fc3dadd8aeb8 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.165 2004/10/11 22:56:56 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.166 2004/11/05 20:45:10 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -848,13 +848,9 @@ pred_test_restrict_list(Expr *predicate, List *restrictinfo_list)
 
    foreach(item, restrictinfo_list)
    {
-       RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(item);
-
-       Assert(IsA(restrictinfo, RestrictInfo));
-
        /* if any clause implies the predicate, return true */
        if (pred_test_recurse_restrict(predicate,
-                                      (Node *) restrictinfo->clause))
+                                      (Node *) lfirst(item)))
            return true;
    }
    return false;
@@ -865,7 +861,8 @@ pred_test_restrict_list(Expr *predicate, List *restrictinfo_list)
  * pred_test_recurse_restrict
  *   Does the "predicate inclusion test" for one element of a predicate
  *   expression.  Here we recursively deal with the possibility that the
- *   restriction-list element is itself an AND or OR structure.
+ *   restriction-list element is itself an AND or OR structure; also,
+ *   we strip off RestrictInfo nodes to find bare predicate expressions.
  */
 static bool
 pred_test_recurse_restrict(Expr *predicate, Node *clause)
@@ -874,7 +871,14 @@ pred_test_recurse_restrict(Expr *predicate, Node *clause)
    ListCell   *item;
 
    Assert(clause != NULL);
-   if (or_clause(clause))
+   if (IsA(clause, RestrictInfo))
+   {
+       RestrictInfo *restrictinfo = (RestrictInfo *) clause;
+
+       return pred_test_recurse_restrict(predicate,
+                                         (Node *) restrictinfo->clause);
+   }
+   else if (or_clause(clause))
    {
        items = ((BoolExpr *) clause)->args;
        foreach(item, items)