]> granicus.if.org Git - postgresql/commitdiff
Fix a number of places that made faulty assumptions about
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 15 Feb 1999 01:06:59 +0000 (01:06 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 15 Feb 1999 01:06:59 +0000 (01:06 +0000)
what is_opclause will accept.

src/backend/optimizer/path/clausesel.c
src/backend/optimizer/path/indxpath.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/initsplan.c
src/backend/optimizer/plan/setrefs.c
src/backend/optimizer/prep/prepqual.c

index e4afad6545e317c545334aa7828f550d54dba6e5..18bb69f53c9e25134010161e993c7252ba575e3e 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.17 1999/02/13 23:16:15 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.18 1999/02/15 01:06:57 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -206,7 +206,7 @@ compute_selec(Query *root, List *clauses, List *or_selectivities)
        Cost            s1 = 0;
        List       *clause = lfirst(clauses);
 
-       if (clauses == NULL)
+       if (clause == NULL)
                s1 = 1.0;
        else if (IsA(clause, Param))
        {
@@ -351,7 +351,7 @@ compute_selec(Query *root, List *clauses, List *or_selectivities)
         * an 'or' clause, but rather that of the single clause.
         */
 
-       if (length(clauses) < 2)
+       if (lnext(clauses) == NIL)
                return s1;
        else
        {
index 8b54b664024c36300fd285310f4bfbbf092690b4..efedd76325c57e74c31b92c26f32685b38b539d3 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.44 1999/02/13 23:16:16 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.45 1999/02/15 01:06:57 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -324,25 +324,25 @@ match_index_orclause(RelOptInfo *rel,
        {
                clause = lfirst(clist);
 
-               if (is_opclause(clause) &&
-                       op_class(((Oper *) ((Expr *) clause)->oper)->opno,
-                                        xclass, index->relam) &&
-                       ((match_index_to_operand(indexkey,
-                                                                        (Expr *) get_leftop((Expr *) clause),
-                                                                        rel,
-                                                                        index) &&
-                         IsA(get_rightop((Expr *) clause), Const)) ||
-                        (match_index_to_operand(indexkey,
-                                                                  (Expr *) get_rightop((Expr *) clause),
-                                                                        rel,
-                                                                        index) &&
-                         IsA(get_leftop((Expr *) clause), Const))))
-                       lfirst(matching_indices) = lcons(index, lfirst(matching_indices));
+               if (is_opclause(clause))
+               {
+                       Expr   *left = (Expr *) get_leftop((Expr *) clause);
+                       Expr   *right = (Expr *) get_rightop((Expr *) clause);
+                       if (left && right &&
+                               op_class(((Oper *) ((Expr *) clause)->oper)->opno,
+                                                xclass, index->relam) &&
+                               ((IsA(right, Const) &&
+                                 match_index_to_operand(indexkey, left, rel, index)) ||
+                                (IsA(left, Const) &&
+                                 match_index_to_operand(indexkey, right, rel, index))))
+                               lfirst(matching_indices) = lcons(index,
+                                                                                                lfirst(matching_indices));
+               }
 
                matching_indices = lnext(matching_indices);
        }
-       return index_list;
 
+       return index_list;
 }
 
 /****************************************************************************
@@ -1019,6 +1019,7 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
        /* Check the basic form; for now, only allow the simplest case */
        if (!is_opclause(clause) ||
                !IsA(clause_var, Var) ||
+               clause_const == NULL ||
                !IsA(clause_const, Const) ||
                !IsA(predicate->oper, Oper) ||
                !IsA(pred_var, Var) ||
index c589b52c15b67c86e5d78542e32dc9c613d43372..2559c376a738a69ff3318b54c98adcd3807a7bcc 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.46 1999/02/13 23:16:27 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.47 1999/02/15 01:06:58 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -780,6 +780,7 @@ switch_outer(List *clauses)
        {
                clause = lfirst(i);
                op = (Node *) get_rightop(clause);
+               Assert(op != (Node*) NULL);
                if (IsA(op, ArrayRef))
                        op = ((ArrayRef *) op)->refexpr;
                Assert(IsA(op, Var));
index a1762ad8dfee10a9a845fe8fcbd7ccc61a68b571..e379a2bbedf36e07d7c2524d976e84891667118f 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.24 1999/02/14 04:56:50 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.25 1999/02/15 01:06:58 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -367,13 +367,30 @@ set_joininfo_mergeable_hashable(List *rel_list)
 static MergeOrder *
 mergejoinop(Expr *clause)
 {
-       Oid                     leftOp,
+       Var                *left,
+                          *right;
+       Oid                     opno,
+                               leftOp,
                                rightOp;
        bool            sortable;
 
-       sortable = op_mergejoinable(((Oper *) clause->oper)->opno,
-                                                               (get_leftop(clause))->vartype,
-                                                               (get_rightop(clause))->vartype,
+       if (!is_opclause((Node*) clause))
+               return NULL;
+
+       left = get_leftop(clause);
+       right = get_rightop(clause);
+
+       /* caution: is_opclause accepts more than I do, so check it */
+       if (!right)
+               return NULL;                    /* unary opclauses need not apply */
+       if (!IsA(left, Var) || !IsA(right, Var))
+               return NULL;
+
+       opno = ((Oper *) clause->oper)->opno;
+
+       sortable = op_mergejoinable(opno,
+                                                               left->vartype,
+                                                               right->vartype,
                                                                &leftOp,
                                                                &rightOp);
 
@@ -381,11 +398,11 @@ mergejoinop(Expr *clause)
        {
                MergeOrder *morder = makeNode(MergeOrder);
 
-               morder->join_operator = ((Oper *) clause->oper)->opno;
+               morder->join_operator = opno;
                morder->left_operator = leftOp;
                morder->right_operator = rightOp;
-               morder->left_type = (get_leftop(clause))->vartype;
-               morder->right_type = (get_rightop(clause))->vartype;
+               morder->left_type = left->vartype;
+               morder->right_type = right->vartype;
                return morder;
        }
        else
@@ -401,7 +418,22 @@ mergejoinop(Expr *clause)
 static Oid
 hashjoinop(Expr *clause)
 {
-       return (op_hashjoinable(((Oper *) clause->oper)->opno,
-                                                       (get_leftop(clause))->vartype,
-                                                       (get_rightop(clause))->vartype));
+       Var                *left,
+                          *right;
+
+       if (!is_opclause((Node*) clause))
+               return InvalidOid;
+
+       left = get_leftop(clause);
+       right = get_rightop(clause);
+
+       /* caution: is_opclause accepts more than I do, so check it */
+       if (!right)
+               return InvalidOid;              /* unary opclauses need not apply */
+       if (!IsA(left, Var) || !IsA(right, Var))
+               return InvalidOid;
+
+       return op_hashjoinable(((Oper *) clause->oper)->opno,
+                                                  left->vartype,
+                                                  right->vartype);
 }
index 78d76960f809a9627f2d4d25c577a4159056a268..e3bfc87586a42dd6cbbc1c4d117c53a5d949582e 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.39 1999/02/13 23:16:33 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.40 1999/02/15 01:06:58 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -290,6 +290,8 @@ replace_clause_joinvar_refs(Expr *clause,
 {
        List       *temp = NULL;
 
+       if (clause == NULL)
+               return NULL;
        if (IsA(clause, Var))
        {
                temp = (List *) replace_joinvar_refs((Var *) clause,
@@ -586,6 +588,8 @@ replace_result_clause(Node *clause,
 {
        List       *t;
 
+       if (clause == NULL)
+               return;
        if (IsA(clause, Var))
        {
                TargetEntry *subplanVar;
index 39f863cde7966c829619359d101ffa7871877879..cea2939a1508a8c5cd15b69037254f613aea1d7c 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepqual.c,v 1.13 1999/02/13 23:16:37 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepqual.c,v 1.14 1999/02/15 01:06:59 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -106,10 +106,17 @@ find_nots(Expr *qual)
 
        if (is_opclause((Node *) qual))
        {
-               return (make_clause(qual->opType, qual->oper,
-                                                       lcons(find_nots((Expr *) get_leftop(qual)),
-                                                        lcons(find_nots((Expr *) get_rightop(qual)),
-                                                                  NIL))));
+               Expr   *left = (Expr *) get_leftop(qual);
+               Expr   *right = (Expr *) get_rightop(qual);
+               if (right)
+                       return make_clause(qual->opType, qual->oper,
+                                                          lcons(find_nots(left),
+                                                                        lcons(find_nots(right),
+                                                                                  NIL)));
+               else
+                       return make_clause(qual->opType, qual->oper,
+                                                          lcons(find_nots(left),
+                                                                        NIL));
        }
        else if (and_clause((Node *) qual))
        {
@@ -155,12 +162,17 @@ normalize(Expr *qual)
 
        if (is_opclause((Node *) qual))
        {
-               Expr       *expr = (Expr *) qual;
-
-               return (make_clause(expr->opType, expr->oper,
-                                                       lcons(normalize((Expr *) get_leftop(qual)),
-                                                        lcons(normalize((Expr *) get_rightop(qual)),
-                                                                  NIL))));
+               Expr   *left = (Expr *) get_leftop(qual);
+               Expr   *right = (Expr *) get_rightop(qual);
+               if (right)
+                       return make_clause(qual->opType, qual->oper,
+                                                          lcons(normalize(left),
+                                                                        lcons(normalize(right),
+                                                                                  NIL)));
+               else
+                       return make_clause(qual->opType, qual->oper,
+                                                          lcons(normalize(left),
+                                                                        NIL));
        }
        else if (and_clause((Node *) qual))
        {
@@ -217,10 +229,17 @@ qual_cleanup(Expr *qual)
 
        if (is_opclause((Node *) qual))
        {
-               return ((List *) make_clause(qual->opType, qual->oper,
-                                                       lcons(qual_cleanup((Expr *) get_leftop(qual)),
-                                                  lcons(qual_cleanup((Expr *) get_rightop(qual)),
-                                                                NIL))));
+               Expr   *left = (Expr *) get_leftop(qual);
+               Expr   *right = (Expr *) get_rightop(qual);
+               if (right)
+                       return (List *) make_clause(qual->opType, qual->oper,
+                                                                               lcons(qual_cleanup(left),
+                                                                                         lcons(qual_cleanup(right),
+                                                                                                       NIL)));
+               else
+                       return (List *) make_clause(qual->opType, qual->oper,
+                                                                               lcons(qual_cleanup(left),
+                                                                                         NIL));
        }
        else if (and_clause((Node *) qual))
        {
@@ -276,10 +295,17 @@ pull_args(Expr *qual)
 
        if (is_opclause((Node *) qual))
        {
-               return (make_clause(qual->opType, qual->oper,
-                                                       lcons(pull_args((Expr *) get_leftop(qual)),
-                                                        lcons(pull_args((Expr *) get_rightop(qual)),
-                                                                  NIL))));
+               Expr   *left = (Expr *) get_leftop(qual);
+               Expr   *right = (Expr *) get_rightop(qual);
+               if (right)
+                       return make_clause(qual->opType, qual->oper,
+                                                          lcons(pull_args(left),
+                                                                        lcons(pull_args(right),
+                                                                                  NIL)));
+               else
+                       return make_clause(qual->opType, qual->oper,
+                                                          lcons(pull_args(left),
+                                                                        NIL));
        }
        else if (and_clause((Node *) qual))
        {
@@ -384,7 +410,7 @@ push_nots(Expr *qual)
                                                                                           0, NULL);
 
                        op->op_fcache = (FunctionCache *) NULL;
-                       return (make_opclause(op, get_leftop(qual), get_rightop(qual)));
+                       return make_opclause(op, get_leftop(qual), get_rightop(qual));
                }
                else
                        return make_notclause(qual);
@@ -511,10 +537,17 @@ remove_ands(Expr *qual)
                return NIL;
        if (is_opclause((Node *) qual))
        {
-               return ((List *) make_clause(qual->opType, qual->oper,
-                                                       lcons(remove_ands((Expr *) get_leftop(qual)),
-                                                  lcons(remove_ands((Expr *) get_rightop(qual)),
-                                                                NIL))));
+               Expr   *left = (Expr *) get_leftop(qual);
+               Expr   *right = (Expr *) get_rightop(qual);
+               if (right)
+                       return (List *) make_clause(qual->opType, qual->oper,
+                                                                               lcons(remove_ands(left),
+                                                                                         lcons(remove_ands(right),
+                                                                                                       NIL)));
+               else
+                       return (List *) make_clause(qual->opType, qual->oper,
+                                                                               lcons(remove_ands(left),
+                                                                                         NIL));
        }
        else if (and_clause((Node *) qual))
        {