1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-16351 JSON_OBJECT() treats hybrid functions with boolean arguments as numbers

Now the boolean data type is preserved in hybrid functions and MIN/MAX,
so COALESCE(bool_expr,bool_expr) and MAX(bool_expr) are correctly
detected by JSON_OBJECT() as being boolean rather than numeric expressions.
This commit is contained in:
Alexander Barkov
2018-05-31 18:52:32 +04:00
parent 3ceb4a54a1
commit ffe83e8e7b
15 changed files with 277 additions and 14 deletions

View File

@ -917,6 +917,27 @@ const Type_handler *
Type_handler::aggregate_for_result_traditional(const Type_handler *a,
const Type_handler *b)
{
if (a == b)
{
/*
If two traditional handlers are equal, quickly return "a".
Some handlers (e.g. Type_handler_bool) pretend to be traditional,
but in fact they are not traditional in full extent, they are
only sub-types for now (and don't have a corresponding Field_xxx yet).
Here we preserve such handlers during aggregation.
As a result, COALESCE(true,true) preserves the "boolean" data type.
Need to do this conversion for deprecated data types,
similar to what field_type_merge_rules[][] does.
*/
switch (a->field_type()) {
case MYSQL_TYPE_DECIMAL: return &type_handler_newdecimal;
case MYSQL_TYPE_DATE: return &type_handler_newdate;
case MYSQL_TYPE_VAR_STRING: return &type_handler_varchar;
default: break;
}
return a;
}
enum_field_types ta= a->traditional_merge_field_type();
enum_field_types tb= b->traditional_merge_field_type();
enum_field_types res= field_types_merge_rules[merge_type2index(ta)]