Commit 2d32b776 authored by igor@rurik.mysql.com's avatar igor@rurik.mysql.com

distinct.test, distinct.result:

  Added test cases for bug #12625.
sql_select.cc:
  Fixed bug #12625.
  Fixed invalid removal of constant items from the DISTINCT
  list in the function create_distinct_group.
parent 7c99cf1a
...@@ -464,3 +464,43 @@ SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin; ...@@ -464,3 +464,43 @@ SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
html prod html prod
1 0.00 1 0.00
drop table t1; drop table t1;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
SELECT DISTINCT a, 1 FROM t1;
a 1
1 1
2 1
3 1
4 1
5 1
SELECT DISTINCT 1, a FROM t1;
1 a
1 1
1 2
1 3
1 4
1 5
CREATE TABLE t2 (a int, b int);
INSERT INTO t2 VALUES (1,1),(2,2),(2,3),(2,4),(3,5);
SELECT DISTINCT a, b, 2 FROM t2;
a b 2
1 1 2
2 2 2
2 3 2
2 4 2
3 5 2
SELECT DISTINCT 2, a, b FROM t2;
2 a b
2 1 1
2 2 2
2 2 3
2 2 4
2 3 5
SELECT DISTINCT a, 2, b FROM t2;
a 2 b
1 2 1
2 2 2
2 2 3
2 2 4
3 2 5
DROP TABLE t1,t2;
...@@ -333,4 +333,21 @@ INSERT INTO t1 VALUES ('1',1,0); ...@@ -333,4 +333,21 @@ INSERT INTO t1 VALUES ('1',1,0);
SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin; SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
drop table t1; drop table t1;
#
# Test cases for #12625: DISTINCT for a list with constants
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
SELECT DISTINCT a, 1 FROM t1;
SELECT DISTINCT 1, a FROM t1;
CREATE TABLE t2 (a int, b int);
INSERT INTO t2 VALUES (1,1),(2,2),(2,3),(2,4),(3,5);
SELECT DISTINCT a, b, 2 FROM t2;
SELECT DISTINCT 2, a, b FROM t2;
SELECT DISTINCT a, 2, b FROM t2;
DROP TABLE t1,t2;
# End of 4.1 tests # End of 4.1 tests
...@@ -8517,9 +8517,7 @@ create_distinct_group(THD *thd, Item **ref_pointer_array, ...@@ -8517,9 +8517,7 @@ create_distinct_group(THD *thd, Item **ref_pointer_array,
li.rewind(); li.rewind();
while ((item=li++)) while ((item=li++))
{ {
if (item->const_item() || item->with_sum_func) if (!item->const_item() && !item->with_sum_func && !item->marker)
continue;
if (!item->marker)
{ {
ORDER *ord=(ORDER*) thd->calloc(sizeof(ORDER)); ORDER *ord=(ORDER*) thd->calloc(sizeof(ORDER));
if (!ord) if (!ord)
......
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