From 2883bccc7d93ca169df8d621f823aa6be74bd05e Mon Sep 17 00:00:00 2001 From: "Alexey (Holyfoot) Botchkov" Date: Mon, 6 Jul 2026 20:28:24 +0300 Subject: [PATCH] MDEV-39683 Numeric aggregates should end up with an error for xmltype. Appropriate xxx_fix_length_and_dec() added to the Type_handler_xmltype. --- .../type_xmltype/type_xmltype.result | 37 ++++++ .../mysql-test/type_xmltype/type_xmltype.test | 42 +++++++ plugin/type_xmltype/sql_type_xmltype.cc | 109 ++++++++++++++++++ plugin/type_xmltype/sql_type_xmltype.h | 23 ++++ 4 files changed, 211 insertions(+) diff --git a/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.result b/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.result index e7416abea47..e5da386c4ff 100644 --- a/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.result +++ b/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.result @@ -380,4 +380,41 @@ CAST('a' AS xmltype) NULL Warnings: Warning 1292 Truncated incorrect xmltype value: 'a' +# +# MDEV-39683 Numeric aggregates should end up with an error for xmltype. +# +CREATE TABLE t (x XMLTYPE); +INSERT INTO t VALUES (''); +INSERT INTO t VALUES (''),('1'),('4.5'),(''); +SELECT round(x) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'round' +SELECT floor(x) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'floor' +SELECT abs(x) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'abs' +SELECT -x FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation '-' +SELECT sum(x) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'sum' +SELECT avg(x) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'avg' +SELECT variance(x) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'variance(' +SELECT cast(x as signed) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'cast_as_signed' +SELECT cast(x as unsigned) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'cast_as_unsigned' +SELECT cast(x as float) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'float_typecast' +SELECT cast(x as double) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'double_typecast' +SELECT cast(x as decimal) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'decimal_typecast' +SELECT cast(x as time) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'cast_as_time' +SELECT cast(x as date) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'cast_as_date' +SELECT cast(x as datetime) FROM t; +ERROR HY000: Illegal parameter data type xmltype for operation 'cast_as_datetime' +DROP TABLE t; # End of 12.3 tests diff --git a/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.test b/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.test index 67f8cb69b0b..4034aa9a2cd 100644 --- a/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.test +++ b/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.test @@ -308,4 +308,46 @@ DROP TABLE t1, t2; SELECT CAST('a' AS xmltype); +--echo # +--echo # MDEV-39683 Numeric aggregates should end up with an error for xmltype. +--echo # + +CREATE TABLE t (x XMLTYPE); +INSERT INTO t VALUES (''); +INSERT INTO t VALUES (''),('1'),('4.5'),(''); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT round(x) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT floor(x) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT abs(x) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT -x FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT sum(x) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT avg(x) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT variance(x) FROM t; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT cast(x as signed) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT cast(x as unsigned) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT cast(x as float) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT cast(x as double) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT cast(x as decimal) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT cast(x as time) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT cast(x as date) FROM t; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT cast(x as datetime) FROM t; + +DROP TABLE t; + --echo # End of 12.3 tests diff --git a/plugin/type_xmltype/sql_type_xmltype.cc b/plugin/type_xmltype/sql_type_xmltype.cc index 0dd2e1ab7d2..af2bc20892c 100644 --- a/plugin/type_xmltype/sql_type_xmltype.cc +++ b/plugin/type_xmltype/sql_type_xmltype.cc @@ -170,6 +170,115 @@ const Type_handler *Type_handler_xmltype:: } +bool Type_handler_xmltype:: + Item_func_round_fix_length_and_dec(Item_func_round *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_func_int_val_fix_length_and_dec(Item_func_int_val *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_func_abs_fix_length_and_dec(Item_func_abs *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_func_neg_fix_length_and_dec(Item_func_neg *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_sum_sum_fix_length_and_dec(Item_sum_sum *item) const +{ + LEX_CSTRING name= {STRING_WITH_LEN("sum") }; + return Item_func_or_sum_illegal_param(name); +} + + +bool Type_handler_xmltype:: + Item_sum_avg_fix_length_and_dec(Item_sum_avg *item) const +{ + LEX_CSTRING name= {STRING_WITH_LEN("avg") }; + return Item_func_or_sum_illegal_param(name); +} + + +bool Type_handler_xmltype:: + Item_sum_variance_fix_length_and_dec(Item_sum_variance *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_func_signed_fix_length_and_dec(Item_func_signed *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_func_unsigned_fix_length_and_dec(Item_func_unsigned *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_double_typecast_fix_length_and_dec(Item_double_typecast *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_float_typecast_fix_length_and_dec(Item_float_typecast *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_decimal_typecast_fix_length_and_dec(Item_decimal_typecast *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_time_typecast_fix_length_and_dec(Item_time_typecast *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_date_typecast_fix_length_and_dec(Item_date_typecast *item) const +{ + return Item_func_or_sum_illegal_param(item); +} + + +bool Type_handler_xmltype:: + Item_datetime_typecast_fix_length_and_dec(Item_datetime_typecast *item) + const +{ + return Item_func_or_sum_illegal_param(item); + +} + + /*****************************************************************/ void Field_xmltype::sql_type(String &res) const diff --git a/plugin/type_xmltype/sql_type_xmltype.h b/plugin/type_xmltype/sql_type_xmltype.h index c393c24caa9..102fe10a704 100644 --- a/plugin/type_xmltype/sql_type_xmltype.h +++ b/plugin/type_xmltype/sql_type_xmltype.h @@ -77,6 +77,29 @@ public: bool can_return_date() const override { return false; } bool can_return_time() const override { return false; } + bool Item_func_round_fix_length_and_dec(Item_func_round *) const override; + bool Item_func_int_val_fix_length_and_dec(Item_func_int_val *) const override; + bool Item_func_abs_fix_length_and_dec(Item_func_abs *) const override; + bool Item_func_neg_fix_length_and_dec(Item_func_neg *) const override; + bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const override; + bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const override; + bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const override; + + bool Item_func_signed_fix_length_and_dec(Item_func_signed *) const override; + bool Item_func_unsigned_fix_length_and_dec(Item_func_unsigned *) const + override; + bool Item_double_typecast_fix_length_and_dec(Item_double_typecast *) const + override; + bool Item_float_typecast_fix_length_and_dec(Item_float_typecast *) const + override; + bool Item_decimal_typecast_fix_length_and_dec(Item_decimal_typecast *) const + override; + bool Item_time_typecast_fix_length_and_dec(Item_time_typecast *) const + override; + bool Item_date_typecast_fix_length_and_dec(Item_date_typecast *) const + override; + bool Item_datetime_typecast_fix_length_and_dec(Item_datetime_typecast *) const + override; }; extern Type_handler_xmltype type_handler_xmltype;