Commit cf202dec authored by Oleg Smirnov's avatar Oleg Smirnov

MDEV-34683 Types mismatch when cloning items causes debug assertion

New runtime type diagnostic (MDEV-34490) has detected that classes
Item_func_eq, Item_default_value and Item_date_literal_for_invalid_dates
incorrectly return an instance of its ancestor classes when being cloned.
This commit fixes that.

Additionally, it fixes a bug at Item_func_case_simple::do_build_clone()
which led to an endless loop of cloning functions calls.

Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
parent 37119cd2
......@@ -14,3 +14,17 @@ SELECT * FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.c<=>5;
c c
DROP TABLE t1, t2;
SET optimizer_switch=default;
#
# MDEV-34683 Types mismatch when cloning items causes debug assertion
#
CREATE TABLE t1 (a date);
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
SELECT a FROM v1 WHERE a IN ('a', 'b', 'c');
a
CREATE VIEW v2 AS SELECT '' as a;
SELECT * FROM v2 WHERE a='' AND CASE '' WHEN '' THEN '' ELSE a END='';
a
DROP TABLE t1;
DROP VIEW v1, v2;
# End of 10.5 tests
......@@ -13,3 +13,21 @@ SELECT * FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.c<=>5;
DROP TABLE t1, t2;
SET optimizer_switch=default;
--echo #
--echo # MDEV-34683 Types mismatch when cloning items causes debug assertion
--echo #
CREATE TABLE t1 (a date);
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
--disable_warnings
SELECT a FROM v1 WHERE a IN ('a', 'b', 'c');
--enable_warnings
CREATE VIEW v2 AS SELECT '' as a;
SELECT * FROM v2 WHERE a='' AND CASE '' WHEN '' THEN '' ELSE a END='';
DROP TABLE t1;
DROP VIEW v1, v2;
--echo # End of 10.5 tests
......@@ -5225,6 +5225,9 @@ class Item_date_literal_for_invalid_dates: public Item_date_literal
cached_time.copy_to_mysql_time(ltime);
return (null_value= false);
}
Item *do_get_copy(THD *thd) const override
{ return get_item_copy<Item_date_literal_for_invalid_dates>(thd, this); }
Item *do_build_clone(THD *thd) const override { return get_copy(thd); }
};
......@@ -6699,7 +6702,9 @@ class Item_default_value : public Item_field
description
*/
bool associate_with_target_field(THD *thd, Item_field *field) override;
Item *do_get_copy(THD *thd) const override
{ return get_item_copy<Item_default_value>(thd, this); }
Item* do_build_clone(THD *thd) const override { return get_copy(thd); }
private:
bool tie_field(THD *thd);
};
......
......@@ -1814,6 +1814,16 @@ longlong Item_func_eq::val_int()
}
Item *Item_func_eq::do_build_clone(THD *thd) const
{
/*
Clone the parent and cast to the child class since there is nothing
specific for Item_func_eq
*/
return (Item_func_eq*) Item_bool_rowready_func2::do_build_clone(thd);
}
/** Same as Item_func_eq, but NULL = NULL. */
bool Item_func_equal::fix_length_and_dec()
......
......@@ -765,6 +765,7 @@ class Item_func_eq :public Item_bool_rowready_func2
friend class Arg_comparator;
Item *do_get_copy(THD *thd) const override
{ return get_item_copy<Item_func_eq>(thd, this); }
Item *do_build_clone(THD *thd) const override;
};
class Item_func_equal final :public Item_bool_rowready_func2
......@@ -2324,7 +2325,7 @@ class Item_func_case_simple: public Item_func_case,
Item *do_build_clone(THD *thd) const override
{
Item_func_case_simple *clone= (Item_func_case_simple *)
Item_func_case::build_clone(thd);
Item_func_case::do_build_clone(thd);
uint ncases= when_count();
if (clone && clone->Predicant_to_list_comparator::init_clone(thd, ncases))
return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment