Move strip_implicit_coercions() from optimizer to nodeFuncs.c.
authorTom Lane <[email protected]>
Tue, 23 Jul 2013 22:21:19 +0000 (18:21 -0400)
committerTom Lane <[email protected]>
Tue, 23 Jul 2013 22:21:19 +0000 (18:21 -0400)
Use of this function has spread into the parser and rewriter, so it seems
like time to pull it out of the optimizer and put it into the more central
nodeFuncs module.  This eliminates the need to #include optimizer/clauses.h
in most of the calling files, demonstrating that this function was indeed a
bit outside the normal code reference patterns.

src/backend/nodes/nodeFuncs.c
src/backend/optimizer/util/clauses.c
src/backend/parser/parse_clause.c
src/backend/parser/parse_relation.c
src/backend/rewrite/rewriteHandler.c
src/backend/utils/adt/ruleutils.c
src/include/nodes/nodeFuncs.h
src/include/optimizer/clauses.h

index a896d763b8f3811651a31391d516df8355835cd7..908f397d501ab5b5453d54755cf0c8a398d4b3e9 100644 (file)
@@ -571,6 +571,65 @@ relabel_to_typmod(Node *expr, int32 typmod)
                                                                        COERCE_EXPLICIT_CAST);
 }
 
+/*
+ * strip_implicit_coercions: remove implicit coercions at top level of tree
+ *
+ * This doesn't modify or copy the input expression tree, just return a
+ * pointer to a suitable place within it.
+ *
+ * Note: there isn't any useful thing we can do with a RowExpr here, so
+ * just return it unchanged, even if it's marked as an implicit coercion.
+ */
+Node *
+strip_implicit_coercions(Node *node)
+{
+       if (node == NULL)
+               return NULL;
+       if (IsA(node, FuncExpr))
+       {
+               FuncExpr   *f = (FuncExpr *) node;
+
+               if (f->funcformat == COERCE_IMPLICIT_CAST)
+                       return strip_implicit_coercions(linitial(f->args));
+       }
+       else if (IsA(node, RelabelType))
+       {
+               RelabelType *r = (RelabelType *) node;
+
+               if (r->relabelformat == COERCE_IMPLICIT_CAST)
+                       return strip_implicit_coercions((Node *) r->arg);
+       }
+       else if (IsA(node, CoerceViaIO))
+       {
+               CoerceViaIO *c = (CoerceViaIO *) node;
+
+               if (c->coerceformat == COERCE_IMPLICIT_CAST)
+                       return strip_implicit_coercions((Node *) c->arg);
+       }
+       else if (IsA(node, ArrayCoerceExpr))
+       {
+               ArrayCoerceExpr *c = (ArrayCoerceExpr *) node;
+
+               if (c->coerceformat == COERCE_IMPLICIT_CAST)
+                       return strip_implicit_coercions((Node *) c->arg);
+       }
+       else if (IsA(node, ConvertRowtypeExpr))
+       {
+               ConvertRowtypeExpr *c = (ConvertRowtypeExpr *) node;
+
+               if (c->convertformat == COERCE_IMPLICIT_CAST)
+                       return strip_implicit_coercions((Node *) c->arg);
+       }
+       else if (IsA(node, CoerceToDomain))
+       {
+               CoerceToDomain *c = (CoerceToDomain *) node;
+
+               if (c->coercionformat == COERCE_IMPLICIT_CAST)
+                       return strip_implicit_coercions((Node *) c->arg);
+       }
+       return node;
+}
+
 /*
  * expression_returns_set
  *       Test whether an expression returns a set result.
index 7ec6b0b30bafa93ee50daec09e040742ea20a470..506e9d49fc300f4effa2f9af743d6d1d61a49ec3 100644 (file)
@@ -2070,62 +2070,6 @@ CommuteRowCompareExpr(RowCompareExpr *clause)
        clause->rargs = temp;
 }
 
-/*
- * strip_implicit_coercions: remove implicit coercions at top level of tree
- *
- * Note: there isn't any useful thing we can do with a RowExpr here, so
- * just return it unchanged, even if it's marked as an implicit coercion.
- */
-Node *
-strip_implicit_coercions(Node *node)
-{
-       if (node == NULL)
-               return NULL;
-       if (IsA(node, FuncExpr))
-       {
-               FuncExpr   *f = (FuncExpr *) node;
-
-               if (f->funcformat == COERCE_IMPLICIT_CAST)
-                       return strip_implicit_coercions(linitial(f->args));
-       }
-       else if (IsA(node, RelabelType))
-       {
-               RelabelType *r = (RelabelType *) node;
-
-               if (r->relabelformat == COERCE_IMPLICIT_CAST)
-                       return strip_implicit_coercions((Node *) r->arg);
-       }
-       else if (IsA(node, CoerceViaIO))
-       {
-               CoerceViaIO *c = (CoerceViaIO *) node;
-
-               if (c->coerceformat == COERCE_IMPLICIT_CAST)
-                       return strip_implicit_coercions((Node *) c->arg);
-       }
-       else if (IsA(node, ArrayCoerceExpr))
-       {
-               ArrayCoerceExpr *c = (ArrayCoerceExpr *) node;
-
-               if (c->coerceformat == COERCE_IMPLICIT_CAST)
-                       return strip_implicit_coercions((Node *) c->arg);
-       }
-       else if (IsA(node, ConvertRowtypeExpr))
-       {
-               ConvertRowtypeExpr *c = (ConvertRowtypeExpr *) node;
-
-               if (c->convertformat == COERCE_IMPLICIT_CAST)
-                       return strip_implicit_coercions((Node *) c->arg);
-       }
-       else if (IsA(node, CoerceToDomain))
-       {
-               CoerceToDomain *c = (CoerceToDomain *) node;
-
-               if (c->coercionformat == COERCE_IMPLICIT_CAST)
-                       return strip_implicit_coercions((Node *) c->arg);
-       }
-       return node;
-}
-
 /*
  * Helper for eval_const_expressions: check that datatype of an attribute
  * is still what it was when the expression was parsed.  This is needed to
index cbfb43188c141469969155d2436c8de7cca0a4a1..ea90e58f7107867c5b8ad728b872bb1b52f7f7ab 100644 (file)
@@ -21,7 +21,6 @@
 #include "commands/defrem.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
-#include "optimizer/clauses.h"
 #include "optimizer/tlist.h"
 #include "parser/analyze.h"
 #include "parser/parsetree.h"
index 42de89f510190877b1f6fa357efb08c81eb7acc9..b2b88fc6a976665829fcffa4e1efb9c6ac74780a 100644 (file)
@@ -24,7 +24,6 @@
 #include "funcapi.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
-#include "optimizer/clauses.h"
 #include "parser/parsetree.h"
 #include "parser/parse_relation.h"
 #include "parser/parse_type.h"
index 3c7974adc72152ba4640baa95c4aed1ed15c3d9a..5c6763e17b4c60ec37a39f8ff707f5a6f4b8c714 100644 (file)
@@ -19,7 +19,6 @@
 #include "foreign/fdwapi.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
-#include "optimizer/clauses.h"
 #include "parser/analyze.h"
 #include "parser/parse_coerce.h"
 #include "parser/parsetree.h"
index 762be4e846bfaa581b9895f79d01ac732067c51c..e6a20e3821cb6bba6c85b52281c48a44ace44cf5 100644 (file)
@@ -38,7 +38,6 @@
 #include "funcapi.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
-#include "optimizer/clauses.h"
 #include "optimizer/tlist.h"
 #include "parser/keywords.h"
 #include "parser/parse_func.h"
index d4901caefa69a61b48ec5bf17032d92099f2f468..fe7cfd3880704c92258746fd37108ede7124244f 100644 (file)
@@ -30,6 +30,7 @@ extern Oid    exprType(const Node *expr);
 extern int32 exprTypmod(const Node *expr);
 extern bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod);
 extern Node *relabel_to_typmod(Node *expr, int32 typmod);
+extern Node *strip_implicit_coercions(Node *node);
 extern bool expression_returns_set(Node *clause);
 
 extern Oid     exprCollation(const Node *expr);
index 586f8c8881e19d41a3b645c1d61cbe91f683affc..a08799957a0b9cea835aa1a3e6c49d3661df6e17 100644 (file)
@@ -77,8 +77,6 @@ extern int    NumRelids(Node *clause);
 extern void CommuteOpExpr(OpExpr *clause);
 extern void CommuteRowCompareExpr(RowCompareExpr *clause);
 
-extern Node *strip_implicit_coercions(Node *node);
-
 extern Node *eval_const_expressions(PlannerInfo *root, Node *node);
 
 extern Node *estimate_expression_value(PlannerInfo *root, Node *node);