Skip to content

Commit b7166f3

Browse files
author
Olav Sandstaa
committed
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.
1 parent 65bdafd commit b7166f3

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

mysql-test/r/select.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4857,3 +4857,22 @@ SELECT * FROM t1 WHERE 102 < c;
48574857
a b c
48584858
DROP TABLE t1;
48594859
End of 5.1 tests
4860+
#
4861+
# Bug#54515: Crash in opt_range.cc::get_best_group_min_max on
4862+
# SELECT from VIEW with GROUP BY
4863+
#
4864+
CREATE TABLE t1 (
4865+
col_int_key int DEFAULT NULL,
4866+
KEY int_key (col_int_key)
4867+
) ;
4868+
INSERT INTO t1 VALUES (1),(2);
4869+
CREATE VIEW view_t1 AS
4870+
SELECT t1.col_int_key AS col_int_key
4871+
FROM t1;
4872+
SELECT col_int_key FROM view_t1 GROUP BY col_int_key;
4873+
col_int_key
4874+
1
4875+
2
4876+
DROP VIEW view_t1;
4877+
DROP TABLE t1;
4878+
# End of test BUG#54515

mysql-test/t/select.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4118,3 +4118,26 @@ DROP TABLE t1;
41184118

41194119

41204120
--echo End of 5.1 tests
4121+
4122+
--echo #
4123+
--echo # Bug#54515: Crash in opt_range.cc::get_best_group_min_max on
4124+
--echo # SELECT from VIEW with GROUP BY
4125+
--echo #
4126+
4127+
CREATE TABLE t1 (
4128+
col_int_key int DEFAULT NULL,
4129+
KEY int_key (col_int_key)
4130+
) ;
4131+
4132+
INSERT INTO t1 VALUES (1),(2);
4133+
4134+
CREATE VIEW view_t1 AS
4135+
SELECT t1.col_int_key AS col_int_key
4136+
FROM t1;
4137+
4138+
SELECT col_int_key FROM view_t1 GROUP BY col_int_key;
4139+
4140+
DROP VIEW view_t1;
4141+
DROP TABLE t1;
4142+
4143+
--echo # End of test BUG#54515

sql/opt_range.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9570,8 +9570,8 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
95709570
first Item? If so, then why? What is the array for?
95719571
*/
95729572
/* Above we already checked that all group items are fields. */
9573-
DBUG_ASSERT((*tmp_group->item)->type() == Item::FIELD_ITEM);
9574-
Item_field *group_field= (Item_field *) (*tmp_group->item);
9573+
DBUG_ASSERT((*tmp_group->item)->real_item()->type() == Item::FIELD_ITEM);
9574+
Item_field *group_field= (Item_field *) (*tmp_group->item)->real_item();
95759575
if (group_field->field->eq(cur_part->field))
95769576
{
95779577
cur_group_prefix_len+= cur_part->store_length;

0 commit comments

Comments
 (0)