diff --git a/mysql-test/main/win_sum.result b/mysql-test/main/win_sum.result index a17c17845af..aa376ecf7ba 100644 --- a/mysql-test/main/win_sum.result +++ b/mysql-test/main/win_sum.result @@ -105,3 +105,12 @@ EXISTS (SELECT 1 ORDER BY 1+sum(2) OVER ()) # # End of 10.4 tests # +# +# MDEV-32411 Item_sum arguments incorrectly reset to temp table fields which causes crash +# +CREATE TABLE t1 (a INT NOT NULL) ; +INSERT INTO t1 VALUES (EXISTS(SELECT avg(3) OVER (ORDER BY COUNT(DISTINCT a, HEX(a))))); +DROP TABLE t1; +# +# End of 10.5 tests +# diff --git a/mysql-test/main/win_sum.test b/mysql-test/main/win_sum.test index 9800174f54c..d3924435949 100644 --- a/mysql-test/main/win_sum.test +++ b/mysql-test/main/win_sum.test @@ -57,3 +57,14 @@ SELECT EXISTS (SELECT 1 ORDER BY 1+sum(2) OVER ()); --echo # --echo # End of 10.4 tests --echo # + +--echo # +--echo # MDEV-32411 Item_sum arguments incorrectly reset to temp table fields which causes crash +--echo # +CREATE TABLE t1 (a INT NOT NULL) ; +INSERT INTO t1 VALUES (EXISTS(SELECT avg(3) OVER (ORDER BY COUNT(DISTINCT a, HEX(a))))); +DROP TABLE t1; + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 3b3661004c1..0acf4595058 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -527,27 +527,6 @@ void Item_sum::fix_num_length_and_dec() max_length=float_length(decimals); } -Item *Item_sum::get_tmp_table_item(THD *thd) -{ - Item_sum* sum_item= (Item_sum *) copy_or_same(thd); - if (sum_item && sum_item->result_field) // If not a const sum func - { - Field *result_field_tmp= sum_item->result_field; - for (uint i=0 ; i < sum_item->arg_count ; i++) - { - Item *arg= sum_item->args[i]; - if (!arg->const_item()) - { - if (arg->type() == Item::FIELD_ITEM) - ((Item_field*) arg)->field= result_field_tmp++; - else - sum_item->args[i]= new (thd->mem_root) Item_temptable_field(thd, result_field_tmp++); - } - } - } - return sum_item; -} - void Item_sum::update_used_tables () { diff --git a/sql/item_sum.h b/sql/item_sum.h index 2ebe0b554fb..56a926c841d 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -521,7 +521,6 @@ public: aggregator_clear(); } virtual void make_unique() { force_copy_fields= TRUE; } - Item *get_tmp_table_item(THD *thd) override; virtual Field *create_tmp_field(MEM_ROOT *root, bool group, TABLE *table); Field *create_tmp_field_ex(MEM_ROOT *root, TABLE *table, Tmp_field_src *src, const Tmp_field_param *param) override