Aggregate two collations together taking into account their coercibility (aka derivation).
- Parameters
-
dt | The collation to be aggregated with the current one. |
flags | Modifier flags for the collation aggregation. MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value |
- Returns
- false if the collations can be aggregated, otherwise true.
With successful return, the collation is set according to the rules of collation aggregation.
Collation derivation values are defined as follows:
DERIVATION_EXPLICIT - an explicitly written COLLATE clause
DERIVATION_IMPLICIT - a column
DERIVATION_SYSCONST - a system function
DERIVATION_COERCIBLE - a string constant
DERIVATION_NUMERIC - a numeric constant coerced to a character string
DERIVATION_NULL - a NULL value
DERIVATION_NONE - a mix of two different collations
These are ordered by strength from highest (DERIVATION_EXPLICIT) to lowest (DERIVATION_NONE), and a low enum value means higher strength.
Note that MySQL supports more coercibility types than the SQL standard, which only has explicit, implicit and none collation derivations.
Explicit collation derivation is applied by specifying a COLLATE clause to a character string expression.
Implicit collation derivation is typically used for a column reference.
NONE collation derivation is assigned in some cases where the rules make it impossible to assign a specific collation.
Note that the SYSCONST, COERCIBLE, NUMERIC and NULL collation derivations may be considered as subtypes of IMPLICIT, but with lesser strength.
The function is used in two contexts:
- With collation aggregation, the function is only called with collation descriptions with equal and highest derivation strength. The aggregation is performed only with these collation descriptions.
- For use in resolving of comparison functions, aggregation is performed on two collation descriptions, possibly with different derivation strength. If derivation strength is equal, the rules observed are the same as those above, otherwise strength is copied from collation description with highest strength.
The rules are as follows:
- With different derivation strengths: choose the collation with highest associated strength.
- If collations are the same: choose this collation, and the strongest derivation.
- If there are more than one entry with EXPLICIT derivation strength, and not all collations are equal, report an error.
- If character sets differ and one entry specifies the binary character set: choose this binary character set (with its binary collation).
- If character sets differ and one is a superset of another, choose the collation of the superset character set. A character set is a superset of another if: It is utf8mb4 and the other is any UNICODE character set. It is compatible with ASCII and the other character set is ASCII.
- If character sets differ and none of the above rules apply: report an error.
- If character sets are the same and one collation is binary: choose the binary collation. Exception: if multiple different binary collations are specified, report an error.
- If character sets are the same but collations are different: choose the binary collation and return NONE derivation strength if allowed, otherwise report an error.
Note that different character sets are allowed when strengths are different, even with different character repertoires. However, undefined character set conversions are flagged with errors during execution, thus it is always guaranteed that a character string generated during execution contains only characters in its assigned repertoire.