From 49b2fd7f9e37a90f72e7e582b444ad941ff23e44 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Thu, 14 May 2026 12:32:10 +0400 Subject: [PATCH] MDEV-39575 Protocol::end_statement(): Assertion `0' failed after insert into xmltype union of valid and invalid xml. Field_xmltype::store has to do the my_error when it gets invalid XML, just the warning with the -1 return results in the DBUG_ASSERT. Also the UpdateXML function result reverted back to the STRING as it can legally produce invalid XML, so we can't have columns built from the UpdateXML to be XMLTYPE. --- mysql-test/main/xml.result | 10 +++--- .../type_xmltype/type_xmltype.result | 33 +++++++++++++++---- .../mysql-test/type_xmltype/type_xmltype.test | 32 ++++++++++++++---- .../type_xmltype/type_xmltype_innodb.result | 18 ++++++++++ .../type_xmltype/type_xmltype_innodb.test | 21 ++++++++++++ plugin/type_xmltype/sql_type_xmltype.cc | 5 ++- sql/item_xmlfunc.cc | 20 ----------- sql/item_xmlfunc.h | 4 --- 8 files changed, 98 insertions(+), 45 deletions(-) create mode 100644 plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype_innodb.result create mode 100644 plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype_innodb.test diff --git a/mysql-test/main/xml.result b/mysql-test/main/xml.result index 8e20759a2dd..b64a65a0854 100644 --- a/mysql-test/main/xml.result +++ b/mysql-test/main/xml.result @@ -1343,10 +1343,10 @@ SELECT UpdateXML(1, '/a', '') a FROM t1 GROUP BY a, name; a - - - - - +1 +1 +1 +1 +1 DROP TABLE t1; # End of 12.3 tests 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 6abf651253c..cd75e8e1462 100644 --- a/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.result +++ b/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.result @@ -223,7 +223,7 @@ CREATE TABLE t1 AS SELECT UpdateXML('ccc', '/a', 'fff"); -ERROR 22007: Incorrect XML value: '' +ERROR HY000: Incorrect XMLTYPE value: '' INSERT INTO t1 VALUES(""); INSERT INTO t1 VALUES("JOHN"); -ERROR 22007: Incorrect XML value: 'JOHN' +ERROR HY000: Incorrect XMLTYPE value: 'JOHN' INSERT INTO t1 VALUES('JOHN'); INSERT INTO t1 VALUES(' JOHN'); INSERT INTO t1 VALUES(' JOHN'); -ERROR 22007: Incorrect XML value: ' JOHN' +ERROR HY000: Incorrect XMLTYPE value: ' JOHN' INSERT INTO t1 VALUES('JOHN '); -ERROR 22007: Incorrect XML value: 'JOHN ' +ERROR HY000: Incorrect XMLTYPE value: 'JOHN ' INSERT INTO t1 VALUES(' Lisa'); -ERROR 22007: Incorrect XML value: ' Lisa' +ERROR HY000: Incorrect XMLTYPE value: ' Lisa' INSERT INTO t1 VALUES(' Lisa'); INSERT INTO t1 VALUES(' Lisa'); DROP TABLE t1; @@ -260,4 +260,23 @@ SET @x = CONCAT(REPEAT('', 30), 'leaf', REPEAT('', 30)); INSERT INTO t1 VALUES(@x); DROP TABLE t1; +# +# MDEV-39575 Protocol::end_statement(): Assertion `0' failed after insert into xmltype union of valid and invalid xml. +# +CREATE TABLE t1(x XMLTYPE) Engine=MyISAM; +INSERT INTO t1 SELECT '' UNION SELECT 'a'; +ERROR HY000: Incorrect XMLTYPE value: 'a' +SELECT * FROM t1; +x + +DROP TABLE t1; +# +# MDEV-39577 Protocol::end_statement(): Assertion `0' failed with invalid xmltype + sql_mode='' +# +set sql_mode=''; +CREATE TABLE t1(x XMLTYPE); +INSERT INTO t1 SELECT 'a'; +ERROR HY000: Incorrect XMLTYPE value: 'a' +DROP TABLE t1; +set sql_mode= DEFAULT; # 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 02801151190..f23e02d7cc8 100644 --- a/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.test +++ b/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype.test @@ -164,22 +164,22 @@ INSERT INTO t1 VALUES(11.2); --error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION INSERT INTO t1 VALUES(11e-2); ---error ER_TRUNCATED_WRONG_VALUE +--error ER_WRONG_VALUE INSERT INTO t1 VALUES("one"); ---error ER_TRUNCATED_WRONG_VALUE +--error ER_WRONG_VALUE INSERT INTO t1 VALUES(""); INSERT INTO t1 VALUES(""); ---error ER_TRUNCATED_WRONG_VALUE +--error ER_WRONG_VALUE INSERT INTO t1 VALUES("JOHN"); INSERT INTO t1 VALUES('JOHN'); INSERT INTO t1 VALUES(' JOHN'); ---error ER_TRUNCATED_WRONG_VALUE +--error ER_WRONG_VALUE INSERT INTO t1 VALUES(' JOHN'); ---error ER_TRUNCATED_WRONG_VALUE +--error ER_WRONG_VALUE INSERT INTO t1 VALUES('JOHN '); ---error ER_TRUNCATED_WRONG_VALUE +--error ER_WRONG_VALUE INSERT INTO t1 VALUES(' Lisa'); INSERT INTO t1 VALUES(' Lisa'); INSERT INTO t1 VALUES(' Lisa'); @@ -200,4 +200,24 @@ INSERT INTO t1 VALUES(@x); DROP TABLE t1; + +--echo # +--echo # MDEV-39575 Protocol::end_statement(): Assertion `0' failed after insert into xmltype union of valid and invalid xml. +--echo # +CREATE TABLE t1(x XMLTYPE) Engine=MyISAM; +--error ER_WRONG_VALUE +INSERT INTO t1 SELECT '' UNION SELECT 'a'; +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-39577 Protocol::end_statement(): Assertion `0' failed with invalid xmltype + sql_mode='' +--echo # +set sql_mode=''; +CREATE TABLE t1(x XMLTYPE); +--error ER_WRONG_VALUE +INSERT INTO t1 SELECT 'a'; +DROP TABLE t1; +set sql_mode= DEFAULT; + --echo # End of 12.3 tests diff --git a/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype_innodb.result b/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype_innodb.result new file mode 100644 index 00000000000..5a1cf82cb5b --- /dev/null +++ b/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype_innodb.result @@ -0,0 +1,18 @@ +# +# MDEV-39575 Protocol::end_statement(): Assertion `0' failed after insert into xmltype union of valid and invalid xml. +# +CREATE TABLE t1(x XMLTYPE) Engine=InnoDB; +INSERT INTO t1 SELECT '' UNION SELECT 'a'; +ERROR HY000: Incorrect XMLTYPE value: 'a' +SELECT * FROM t1; +x +DROP TABLE t1; +SET sql_mode=''; +CREATE TABLE t1(x XMLTYPE) Engine=InnoDB; +INSERT INTO t1 SELECT '' UNION SELECT 'a'; +ERROR HY000: Incorrect XMLTYPE value: 'a' +SELECT * FROM t1; +x +DROP TABLE t1; +set sql_mode=default; +# End of 12.3 tests diff --git a/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype_innodb.test b/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype_innodb.test new file mode 100644 index 00000000000..6878fce746f --- /dev/null +++ b/plugin/type_xmltype/mysql-test/type_xmltype/type_xmltype_innodb.test @@ -0,0 +1,21 @@ +source include/have_innodb.inc; + +--echo # +--echo # MDEV-39575 Protocol::end_statement(): Assertion `0' failed after insert into xmltype union of valid and invalid xml. +--echo # + +CREATE TABLE t1(x XMLTYPE) Engine=InnoDB; +--error ER_WRONG_VALUE +INSERT INTO t1 SELECT '' UNION SELECT 'a'; +SELECT * FROM t1; +DROP TABLE t1; + +SET sql_mode=''; +CREATE TABLE t1(x XMLTYPE) Engine=InnoDB; +--error ER_WRONG_VALUE +INSERT INTO t1 SELECT '' UNION SELECT 'a'; +SELECT * FROM t1; +DROP TABLE t1; +set sql_mode=default; + +--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 af46bf5d448..d54bb5888f8 100644 --- a/plugin/type_xmltype/sql_type_xmltype.cc +++ b/plugin/type_xmltype/sql_type_xmltype.cc @@ -215,9 +215,8 @@ int Field_xmltype::store(const char *from, size_t length, CHARSET_INFO *cs) return Field_blob::store(from, length, cs); err: - get_thd()->push_warning_wrong_value( - Sql_condition::WARN_LEVEL_WARN, "XML", - ErrConvString(from, length, cs).ptr()); + my_error(ER_WRONG_VALUE, MYF(0), + "XMLTYPE", ErrConvString(from, length, cs).ptr()); return -1; } diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc index a52702bed8e..e70415d8a20 100644 --- a/sql/item_xmlfunc.cc +++ b/sql/item_xmlfunc.cc @@ -3089,26 +3089,6 @@ String *Item_func_xml_extractvalue::val_str(String *str) } -const Type_handler *Item_func_xml_update::xml_handler= NULL; - - -bool Item_func_xml_update::fix_length_and_dec(THD *thd) -{ - static LEX_CSTRING name= {STRING_WITH_LEN("XMLTYPE")}; - - if (!xml_handler) - xml_handler= Type_handler::handler_by_name(thd, name); - - return Item_xml_str_func::fix_length_and_dec(thd); -} - - -const Type_handler *Item_func_xml_update::type_handler() const -{ - return xml_handler ? xml_handler : Item_xml_str_func::type_handler(); -} - - bool Item_func_xml_update::collect_result(String *str, const MY_XML_NODE *cut, const String *replace) diff --git a/sql/item_xmlfunc.h b/sql/item_xmlfunc.h index 25fbaa61eaa..2e7e908a106 100644 --- a/sql/item_xmlfunc.h +++ b/sql/item_xmlfunc.h @@ -159,10 +159,6 @@ public: static LEX_CSTRING name= {STRING_WITH_LEN("updatexml") }; return name; } - static const Type_handler *xml_handler; - const Type_handler *type_handler() const override; - bool fix_length_and_dec(THD *thd) override; - String *val_str(String *) override; protected: