Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 10a509d

Browse files
committed
Move strip_implicit_coercions() from optimizer to nodeFuncs.c.
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.
1 parent ef65566 commit 10a509d

File tree

8 files changed

+60
-62
lines changed

8 files changed

+60
-62
lines changed

src/backend/nodes/nodeFuncs.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,65 @@ relabel_to_typmod(Node *expr, int32 typmod)
571571
COERCE_EXPLICIT_CAST);
572572
}
573573

574+
/*
575+
* strip_implicit_coercions: remove implicit coercions at top level of tree
576+
*
577+
* This doesn't modify or copy the input expression tree, just return a
578+
* pointer to a suitable place within it.
579+
*
580+
* Note: there isn't any useful thing we can do with a RowExpr here, so
581+
* just return it unchanged, even if it's marked as an implicit coercion.
582+
*/
583+
Node *
584+
strip_implicit_coercions(Node *node)
585+
{
586+
if (node == NULL)
587+
return NULL;
588+
if (IsA(node, FuncExpr))
589+
{
590+
FuncExpr *f = (FuncExpr *) node;
591+
592+
if (f->funcformat == COERCE_IMPLICIT_CAST)
593+
return strip_implicit_coercions(linitial(f->args));
594+
}
595+
else if (IsA(node, RelabelType))
596+
{
597+
RelabelType *r = (RelabelType *) node;
598+
599+
if (r->relabelformat == COERCE_IMPLICIT_CAST)
600+
return strip_implicit_coercions((Node *) r->arg);
601+
}
602+
else if (IsA(node, CoerceViaIO))
603+
{
604+
CoerceViaIO *c = (CoerceViaIO *) node;
605+
606+
if (c->coerceformat == COERCE_IMPLICIT_CAST)
607+
return strip_implicit_coercions((Node *) c->arg);
608+
}
609+
else if (IsA(node, ArrayCoerceExpr))
610+
{
611+
ArrayCoerceExpr *c = (ArrayCoerceExpr *) node;
612+
613+
if (c->coerceformat == COERCE_IMPLICIT_CAST)
614+
return strip_implicit_coercions((Node *) c->arg);
615+
}
616+
else if (IsA(node, ConvertRowtypeExpr))
617+
{
618+
ConvertRowtypeExpr *c = (ConvertRowtypeExpr *) node;
619+
620+
if (c->convertformat == COERCE_IMPLICIT_CAST)
621+
return strip_implicit_coercions((Node *) c->arg);
622+
}
623+
else if (IsA(node, CoerceToDomain))
624+
{
625+
CoerceToDomain *c = (CoerceToDomain *) node;
626+
627+
if (c->coercionformat == COERCE_IMPLICIT_CAST)
628+
return strip_implicit_coercions((Node *) c->arg);
629+
}
630+
return node;
631+
}
632+
574633
/*
575634
* expression_returns_set
576635
* Test whether an expression returns a set result.

src/backend/optimizer/util/clauses.c

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,62 +2070,6 @@ CommuteRowCompareExpr(RowCompareExpr *clause)
20702070
clause->rargs = temp;
20712071
}
20722072

2073-
/*
2074-
* strip_implicit_coercions: remove implicit coercions at top level of tree
2075-
*
2076-
* Note: there isn't any useful thing we can do with a RowExpr here, so
2077-
* just return it unchanged, even if it's marked as an implicit coercion.
2078-
*/
2079-
Node *
2080-
strip_implicit_coercions(Node *node)
2081-
{
2082-
if (node == NULL)
2083-
return NULL;
2084-
if (IsA(node, FuncExpr))
2085-
{
2086-
FuncExpr *f = (FuncExpr *) node;
2087-
2088-
if (f->funcformat == COERCE_IMPLICIT_CAST)
2089-
return strip_implicit_coercions(linitial(f->args));
2090-
}
2091-
else if (IsA(node, RelabelType))
2092-
{
2093-
RelabelType *r = (RelabelType *) node;
2094-
2095-
if (r->relabelformat == COERCE_IMPLICIT_CAST)
2096-
return strip_implicit_coercions((Node *) r->arg);
2097-
}
2098-
else if (IsA(node, CoerceViaIO))
2099-
{
2100-
CoerceViaIO *c = (CoerceViaIO *) node;
2101-
2102-
if (c->coerceformat == COERCE_IMPLICIT_CAST)
2103-
return strip_implicit_coercions((Node *) c->arg);
2104-
}
2105-
else if (IsA(node, ArrayCoerceExpr))
2106-
{
2107-
ArrayCoerceExpr *c = (ArrayCoerceExpr *) node;
2108-
2109-
if (c->coerceformat == COERCE_IMPLICIT_CAST)
2110-
return strip_implicit_coercions((Node *) c->arg);
2111-
}
2112-
else if (IsA(node, ConvertRowtypeExpr))
2113-
{
2114-
ConvertRowtypeExpr *c = (ConvertRowtypeExpr *) node;
2115-
2116-
if (c->convertformat == COERCE_IMPLICIT_CAST)
2117-
return strip_implicit_coercions((Node *) c->arg);
2118-
}
2119-
else if (IsA(node, CoerceToDomain))
2120-
{
2121-
CoerceToDomain *c = (CoerceToDomain *) node;
2122-
2123-
if (c->coercionformat == COERCE_IMPLICIT_CAST)
2124-
return strip_implicit_coercions((Node *) c->arg);
2125-
}
2126-
return node;
2127-
}
2128-
21292073
/*
21302074
* Helper for eval_const_expressions: check that datatype of an attribute
21312075
* is still what it was when the expression was parsed. This is needed to

src/backend/parser/parse_clause.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "commands/defrem.h"
2222
#include "nodes/makefuncs.h"
2323
#include "nodes/nodeFuncs.h"
24-
#include "optimizer/clauses.h"
2524
#include "optimizer/tlist.h"
2625
#include "parser/analyze.h"
2726
#include "parser/parsetree.h"

src/backend/parser/parse_relation.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "funcapi.h"
2525
#include "nodes/makefuncs.h"
2626
#include "nodes/nodeFuncs.h"
27-
#include "optimizer/clauses.h"
2827
#include "parser/parsetree.h"
2928
#include "parser/parse_relation.h"
3029
#include "parser/parse_type.h"

src/backend/rewrite/rewriteHandler.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "foreign/fdwapi.h"
2020
#include "nodes/makefuncs.h"
2121
#include "nodes/nodeFuncs.h"
22-
#include "optimizer/clauses.h"
2322
#include "parser/analyze.h"
2423
#include "parser/parse_coerce.h"
2524
#include "parser/parsetree.h"

src/backend/utils/adt/ruleutils.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "funcapi.h"
3939
#include "nodes/makefuncs.h"
4040
#include "nodes/nodeFuncs.h"
41-
#include "optimizer/clauses.h"
4241
#include "optimizer/tlist.h"
4342
#include "parser/keywords.h"
4443
#include "parser/parse_func.h"

src/include/nodes/nodeFuncs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern Oid exprType(const Node *expr);
3030
extern int32 exprTypmod(const Node *expr);
3131
extern bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod);
3232
extern Node *relabel_to_typmod(Node *expr, int32 typmod);
33+
extern Node *strip_implicit_coercions(Node *node);
3334
extern bool expression_returns_set(Node *clause);
3435

3536
extern Oid exprCollation(const Node *expr);

src/include/optimizer/clauses.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ extern int NumRelids(Node *clause);
7777
extern void CommuteOpExpr(OpExpr *clause);
7878
extern void CommuteRowCompareExpr(RowCompareExpr *clause);
7979

80-
extern Node *strip_implicit_coercions(Node *node);
81-
8280
extern Node *eval_const_expressions(PlannerInfo *root, Node *node);
8381

8482
extern Node *estimate_expression_value(PlannerInfo *root, Node *node);

0 commit comments

Comments
 (0)