diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-19 20:29:08 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-19 20:30:08 -0400 |
commit | b310b6e31ce5aa9e456c43c0e8e93248b0c84c02 (patch) | |
tree | e5168fcfdb231a9889e87e309f38a9e0f05a7896 /src/backend/parser/parse_clause.c | |
parent | 025f4c72f029242a6aaf3f14bb6d7da4ce070f72 (diff) | |
download | postgresql-b310b6e31ce5aa9e456c43c0e8e93248b0c84c02.tar.gz postgresql-b310b6e31ce5aa9e456c43c0e8e93248b0c84c02.zip |
Revise collation derivation method and expression-tree representation.
All expression nodes now have an explicit output-collation field, unless
they are known to only return a noncollatable data type (such as boolean
or record). Also, nodes that can invoke collation-aware functions store
a separate field that is the collation value to pass to the function.
This avoids confusion that arises when a function has collatable inputs
and noncollatable output type, or vice versa.
Also, replace the parser's on-the-fly collation assignment method with
a post-pass over the completed expression tree. This allows us to use
a more complex (and hopefully more nearly spec-compliant) assignment
rule without paying for it in extra storage in every expression node.
Fix assorted bugs in the planner's handling of collations by making
collation one of the defining properties of an EquivalenceClass and
by converting CollateExprs into discardable RelabelType nodes during
expression preprocessing.
Diffstat (limited to 'src/backend/parser/parse_clause.c')
-rw-r--r-- | src/backend/parser/parse_clause.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 4c5a6fe0b01..6c0a78474cd 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -28,6 +28,7 @@ #include "parser/parsetree.h" #include "parser/parse_clause.h" #include "parser/parse_coerce.h" +#include "parser/parse_collate.h" #include "parser/parse_expr.h" #include "parser/parse_oper.h" #include "parser/parse_relation.h" @@ -558,6 +559,11 @@ transformRangeFunction(ParseState *pstate, RangeFunction *r) funcexpr = transformExpr(pstate, r->funccallnode); /* + * We must assign collations now so that we can fill funccolcollations. + */ + assign_expr_collations(pstate, funcexpr); + + /* * The function parameters cannot make use of any variables from other * FROM items. (Compare to transformRangeSubselect(); the coding is * different though because we didn't parse as a sub-select with its own @@ -1072,6 +1078,7 @@ buildMergedJoinVar(ParseState *pstate, JoinType jointype, else if (l_colvar->vartypmod != outcoltypmod) l_node = (Node *) makeRelabelType((Expr *) l_colvar, outcoltype, outcoltypmod, + InvalidOid, /* fixed below */ COERCE_IMPLICIT_CAST); else l_node = (Node *) l_colvar; @@ -1083,6 +1090,7 @@ buildMergedJoinVar(ParseState *pstate, JoinType jointype, else if (r_colvar->vartypmod != outcoltypmod) r_node = (Node *) makeRelabelType((Expr *) r_colvar, outcoltype, outcoltypmod, + InvalidOid, /* fixed below */ COERCE_IMPLICIT_CAST); else r_node = (Node *) r_colvar; @@ -1121,6 +1129,7 @@ buildMergedJoinVar(ParseState *pstate, JoinType jointype, CoalesceExpr *c = makeNode(CoalesceExpr); c->coalescetype = outcoltype; + /* coalescecollid will get set below */ c->args = list_make2(l_node, r_node); c->location = -1; res_node = (Node *) c; @@ -1132,6 +1141,13 @@ buildMergedJoinVar(ParseState *pstate, JoinType jointype, break; } + /* + * Apply assign_expr_collations to fix up the collation info in the + * coercion and CoalesceExpr nodes, if we made any. This must be done + * now so that the join node's alias vars show correct collation info. + */ + assign_expr_collations(pstate, res_node); + return res_node; } @@ -1936,7 +1952,6 @@ addTargetToSortList(ParseState *pstate, TargetEntry *tle, bool resolveUnknown) { Oid restype = exprType((Node *) tle->expr); - Oid rescollation = exprCollation((Node *) tle->expr); Oid sortop; Oid eqop; bool hashable; @@ -2020,12 +2035,6 @@ addTargetToSortList(ParseState *pstate, TargetEntry *tle, break; } - if (type_is_collatable(restype) && !OidIsValid(rescollation)) - ereport(ERROR, - (errcode(ERRCODE_INDETERMINATE_COLLATION), - errmsg("no collation was derived for the sort expression"), - errhint("Use the COLLATE clause to set the collation explicitly."))); - cancel_parser_errposition_callback(&pcbstate); /* avoid making duplicate sortlist entries */ |