Save one syscache lookup when examining volatility or strictness of
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 22 Nov 2007 19:09:23 +0000 (19:09 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 22 Nov 2007 19:09:23 +0000 (19:09 +0000)
OpExpr and related nodes.  We're going to have to set the opfuncid of
such nodes eventually (if we haven't already), so we might as well
exploit the opportunity to cache the function OID.  Buys back some
of the extra planner overhead noted by Guillaume Smet, though I still
need to fool with equivclass.c to really respond to that.

src/backend/optimizer/util/clauses.c

index 8d1ca2a77664baefa8a5ec4abd25a16f9ca489e2..f85782d553da07056d4e49dad189c24a63a18c04 100644 (file)
@@ -715,7 +715,8 @@ contain_mutable_functions_walker(Node *node, void *context)
        {
                OpExpr     *expr = (OpExpr *) node;
 
-               if (op_volatile(expr->opno) != PROVOLATILE_IMMUTABLE)
+               set_opfuncid(expr);
+               if (func_volatile(expr->opfuncid) != PROVOLATILE_IMMUTABLE)
                        return true;
                /* else fall through to check args */
        }
@@ -723,7 +724,8 @@ contain_mutable_functions_walker(Node *node, void *context)
        {
                DistinctExpr *expr = (DistinctExpr *) node;
 
-               if (op_volatile(expr->opno) != PROVOLATILE_IMMUTABLE)
+               set_opfuncid((OpExpr *) expr);  /* rely on struct equivalence */
+               if (func_volatile(expr->opfuncid) != PROVOLATILE_IMMUTABLE)
                        return true;
                /* else fall through to check args */
        }
@@ -731,7 +733,8 @@ contain_mutable_functions_walker(Node *node, void *context)
        {
                ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
 
-               if (op_volatile(expr->opno) != PROVOLATILE_IMMUTABLE)
+               set_sa_opfuncid(expr);
+               if (func_volatile(expr->opfuncid) != PROVOLATILE_IMMUTABLE)
                        return true;
                /* else fall through to check args */
        }
@@ -767,7 +770,8 @@ contain_mutable_functions_walker(Node *node, void *context)
        {
                NullIfExpr *expr = (NullIfExpr *) node;
 
-               if (op_volatile(expr->opno) != PROVOLATILE_IMMUTABLE)
+               set_opfuncid((OpExpr *) expr);  /* rely on struct equivalence */
+               if (func_volatile(expr->opfuncid) != PROVOLATILE_IMMUTABLE)
                        return true;
                /* else fall through to check args */
        }
@@ -826,7 +830,8 @@ contain_volatile_functions_walker(Node *node, void *context)
        {
                OpExpr     *expr = (OpExpr *) node;
 
-               if (op_volatile(expr->opno) == PROVOLATILE_VOLATILE)
+               set_opfuncid(expr);
+               if (func_volatile(expr->opfuncid) == PROVOLATILE_VOLATILE)
                        return true;
                /* else fall through to check args */
        }
@@ -834,7 +839,8 @@ contain_volatile_functions_walker(Node *node, void *context)
        {
                DistinctExpr *expr = (DistinctExpr *) node;
 
-               if (op_volatile(expr->opno) == PROVOLATILE_VOLATILE)
+               set_opfuncid((OpExpr *) expr);  /* rely on struct equivalence */
+               if (func_volatile(expr->opfuncid) == PROVOLATILE_VOLATILE)
                        return true;
                /* else fall through to check args */
        }
@@ -842,7 +848,8 @@ contain_volatile_functions_walker(Node *node, void *context)
        {
                ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
 
-               if (op_volatile(expr->opno) == PROVOLATILE_VOLATILE)
+               set_sa_opfuncid(expr);
+               if (func_volatile(expr->opfuncid) == PROVOLATILE_VOLATILE)
                        return true;
                /* else fall through to check args */
        }
@@ -878,7 +885,8 @@ contain_volatile_functions_walker(Node *node, void *context)
        {
                NullIfExpr *expr = (NullIfExpr *) node;
 
-               if (op_volatile(expr->opno) == PROVOLATILE_VOLATILE)
+               set_opfuncid((OpExpr *) expr);  /* rely on struct equivalence */
+               if (func_volatile(expr->opfuncid) == PROVOLATILE_VOLATILE)
                        return true;
                /* else fall through to check args */
        }
@@ -951,7 +959,8 @@ contain_nonstrict_functions_walker(Node *node, void *context)
        {
                OpExpr     *expr = (OpExpr *) node;
 
-               if (!op_strict(expr->opno))
+               set_opfuncid(expr);
+               if (!func_strict(expr->opfuncid))
                        return true;
                /* else fall through to check args */
        }
@@ -1091,7 +1100,8 @@ find_nonnullable_rels_walker(Node *node, bool top_level)
        {
                OpExpr     *expr = (OpExpr *) node;
 
-               if (op_strict(expr->opno))
+               set_opfuncid(expr);
+               if (func_strict(expr->opfuncid))
                        result = find_nonnullable_rels_walker((Node *) expr->args, false);
        }
        else if (IsA(node, ScalarArrayOpExpr))
@@ -1228,7 +1238,8 @@ is_strict_saop(ScalarArrayOpExpr *expr, bool falseOK)
        Node       *rightop;
 
        /* The contained operator must be strict. */
-       if (!op_strict(expr->opno))
+       set_sa_opfuncid(expr);
+       if (!func_strict(expr->opfuncid))
                return false;
        /* If ANY and falseOK, that's all we need to check. */
        if (expr->useOr && falseOK)