Skip to content

Commit 5af5bb2

Browse files
author
oystein.grovlen@sun.com
committed
Bug#51980 mysqld service crashes with a simple COUNT(DISTINCT) query over a view
Problem: Segmentation fault in add_group_and_distinct_keys() when accessing field of what is assumed to be an Item_field object. Cause: In case of views, the item added to list by is_indexed_agg_distinct() was not of type Item_field, but Item_ref. Resolution: Add the real Item_field object, the one referred to by Item_ref object, to the list, instead.
1 parent 9b807ed commit 5af5bb2

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

mysql-test/r/count_distinct.result

+8
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,11 @@ select count(distinct if(f1,3,f2)) from t1;
8686
count(distinct if(f1,3,f2))
8787
2
8888
drop table t1;
89+
create table t1 (i int);
90+
insert into t1 values (0), (1);
91+
create view v1 as select * from t1;
92+
select count(distinct i) from v1;
93+
count(distinct i)
94+
2
95+
drop table t1;
96+
drop view v1;

mysql-test/t/count_distinct.test

+11
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,14 @@ insert into t1 values (0,1),(1,2);
9696
select count(distinct if(f1,3,f2)) from t1;
9797
drop table t1;
9898

99+
#
100+
# Bug #51980 "mysqld service crashes with a simple COUNT(DISTINCT) query
101+
# over a view"
102+
#
103+
104+
create table t1 (i int);
105+
insert into t1 values (0), (1);
106+
create view v1 as select * from t1;
107+
select count(distinct i) from v1;
108+
drop table t1;
109+
drop view v1;

sql/sql_select.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4157,7 +4157,7 @@ is_indexed_agg_distinct(JOIN *join, List<Item_field> *out_args)
41574157
optimization is applicable
41584158
*/
41594159
if (out_args)
4160-
out_args->push_back((Item_field *) expr);
4160+
out_args->push_back((Item_field *) expr->real_item());
41614161
result= true;
41624162
}
41634163
}

0 commit comments

Comments
 (0)