mirror of
https://github.com/postgres/postgres.git
synced 2025-06-22 02:52:08 +03:00
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.
This commit is contained in:
@ -883,17 +883,34 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
|
||||
}
|
||||
|
||||
/*
|
||||
* Collation override
|
||||
* Apply collation override if any
|
||||
*/
|
||||
if (attribute->collation)
|
||||
attcollation = get_collation_oid(attribute->collation, false);
|
||||
|
||||
/*
|
||||
* Check we have a collation iff it's a collatable type. The only
|
||||
* expected failures here are (1) COLLATE applied to a noncollatable
|
||||
* type, or (2) index expression had an unresolved collation. But
|
||||
* we might as well code this to be a complete consistency check.
|
||||
*/
|
||||
if (type_is_collatable(atttype))
|
||||
{
|
||||
if (!type_is_collatable(atttype))
|
||||
if (!OidIsValid(attcollation))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
(errcode(ERRCODE_INDETERMINATE_COLLATION),
|
||||
errmsg("no collation was derived for the index expression"),
|
||||
errhint("Use the COLLATE clause to set the collation explicitly.")));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (OidIsValid(attcollation))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("collations are not supported by type %s",
|
||||
format_type_be(atttype))));
|
||||
attcollation = get_collation_oid(attribute->collation, false);
|
||||
}
|
||||
|
||||
collationOidP[attn] = attcollation;
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user