From b7166f33d05a815b320b2783a719c9b3a11a2beb Mon Sep 17 00:00:00 2001 From: Olav Sandstaa Date: Thu, 8 Jul 2010 15:19:05 +0200 Subject: [PATCH] Backporting of jorgen.loland@sun.com-20100618093212-lifp1psig3hbj6jj from mysql-next-mr-opt-backporting. Bug#54515: Crash in opt_range.cc::get_best_group_min_max on SELECT from VIEW with GROUP BY When handling the grouping items in get_best_group_min_max, the items need to be of type Item_field. In this bug, an ASSERT triggered because the item used for grouping was an Item_direct_view_ref (i.e., the group column is from a view). The fix is to get the real_item since Item_ref* pointing to Item_field is ok. --- mysql-test/r/select.result | 19 +++++++++++++++++++ mysql-test/t/select.test | 23 +++++++++++++++++++++++ sql/opt_range.cc | 4 ++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index e594e87694f..b518522e2bf 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -4857,3 +4857,22 @@ SELECT * FROM t1 WHERE 102 < c; a b c DROP TABLE t1; End of 5.1 tests +# +# Bug#54515: Crash in opt_range.cc::get_best_group_min_max on +# SELECT from VIEW with GROUP BY +# +CREATE TABLE t1 ( +col_int_key int DEFAULT NULL, +KEY int_key (col_int_key) +) ; +INSERT INTO t1 VALUES (1),(2); +CREATE VIEW view_t1 AS +SELECT t1.col_int_key AS col_int_key +FROM t1; +SELECT col_int_key FROM view_t1 GROUP BY col_int_key; +col_int_key +1 +2 +DROP VIEW view_t1; +DROP TABLE t1; +# End of test BUG#54515 diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 1e53461f665..6f2d34459eb 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -4118,3 +4118,26 @@ DROP TABLE t1; --echo End of 5.1 tests + +--echo # +--echo # Bug#54515: Crash in opt_range.cc::get_best_group_min_max on +--echo # SELECT from VIEW with GROUP BY +--echo # + +CREATE TABLE t1 ( + col_int_key int DEFAULT NULL, + KEY int_key (col_int_key) +) ; + +INSERT INTO t1 VALUES (1),(2); + +CREATE VIEW view_t1 AS + SELECT t1.col_int_key AS col_int_key + FROM t1; + +SELECT col_int_key FROM view_t1 GROUP BY col_int_key; + +DROP VIEW view_t1; +DROP TABLE t1; + +--echo # End of test BUG#54515 diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 995582fc6ee..f195da9ae02 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -9570,8 +9570,8 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time) first Item? If so, then why? What is the array for? */ /* Above we already checked that all group items are fields. */ - DBUG_ASSERT((*tmp_group->item)->type() == Item::FIELD_ITEM); - Item_field *group_field= (Item_field *) (*tmp_group->item); + DBUG_ASSERT((*tmp_group->item)->real_item()->type() == Item::FIELD_ITEM); + Item_field *group_field= (Item_field *) (*tmp_group->item)->real_item(); if (group_field->field->eq(cur_part->field)) { cur_group_prefix_len+= cur_part->store_length;