Loading mysql-test/r/group_by.result +19 −0 Original line number Diff line number Diff line Loading @@ -722,3 +722,22 @@ WHERE hostname LIKE '%aol%' GROUP BY hostname; hostname no cache-dtc-af05.proxy.aol.com 1 DROP TABLE t1; CREATE TABLE t1 (a int, b int); INSERT INTO t1 VALUES (1,2), (1,3); SELECT a, b FROM t1 GROUP BY 'const'; a b 1 2 SELECT DISTINCT a, b FROM t1 GROUP BY 'const'; a b 1 2 DROP TABLE t1; CREATE TABLE t1 (id INT, dt DATETIME); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); SELECT dt DIV 1 AS f, id FROM t1 GROUP BY f; f id 20050501123000 1 DROP TABLE t1; mysql-test/t/group_by.test +27 −1 Original line number Diff line number Diff line # Initialise --disable_warnings drop table if exists t1,t2,t3; Loading Loading @@ -524,7 +525,7 @@ select min(b) from t1; drop table t1; # # Test for bug #11088: GROUP BY a BLOB colimn with COUNT(DISTINCT column1) # Test for bug #11088: GROUP BY a BLOB column with COUNT(DISTINCT column1) # CREATE TABLE t1 (id int PRIMARY KEY, user_id int, hostname longtext); Loading @@ -539,3 +540,28 @@ SELECT hostname, COUNT(DISTINCT user_id) as no FROM t1 WHERE hostname LIKE '%aol%' GROUP BY hostname; DROP TABLE t1; # # Test for bug #8614: GROUP BY 'const' with DISTINCT # CREATE TABLE t1 (a int, b int); INSERT INTO t1 VALUES (1,2), (1,3); SELECT a, b FROM t1 GROUP BY 'const'; SELECT DISTINCT a, b FROM t1 GROUP BY 'const'; DROP TABLE t1; # # Test for bug #11385: GROUP BY for datetime converted to decimals # CREATE TABLE t1 (id INT, dt DATETIME); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); SELECT dt DIV 1 AS f, id FROM t1 GROUP BY f; DROP TABLE t1; sql/field.h +2 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #endif #define NOT_FIXED_DEC 31 #define DATETIME_DEC 6 class Send_field; class Protocol; Loading Loading @@ -861,6 +862,7 @@ class Field_datetime :public Field_str { enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; } #endif enum Item_result cmp_type () const { return INT_RESULT; } uint decimals() const { return DATETIME_DEC; } int store(const char *to,uint length,CHARSET_INFO *charset); int store(double nr); int store(longlong nr); Loading sql/sql_select.cc +8 −3 Original line number Diff line number Diff line Loading @@ -678,9 +678,14 @@ JOIN::optimize() DBUG_RETURN(1); } simple_group= 0; group_list= remove_const(this, group_list, conds, { ORDER *old_group_list; group_list= remove_const(this, (old_group_list= group_list), conds, rollup.state == ROLLUP::STATE_NONE, &simple_group); if (old_group_list && !group_list) select_distinct= 0; } if (!group_list && group) { order=0; // The output has only one row Loading Loading
mysql-test/r/group_by.result +19 −0 Original line number Diff line number Diff line Loading @@ -722,3 +722,22 @@ WHERE hostname LIKE '%aol%' GROUP BY hostname; hostname no cache-dtc-af05.proxy.aol.com 1 DROP TABLE t1; CREATE TABLE t1 (a int, b int); INSERT INTO t1 VALUES (1,2), (1,3); SELECT a, b FROM t1 GROUP BY 'const'; a b 1 2 SELECT DISTINCT a, b FROM t1 GROUP BY 'const'; a b 1 2 DROP TABLE t1; CREATE TABLE t1 (id INT, dt DATETIME); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); SELECT dt DIV 1 AS f, id FROM t1 GROUP BY f; f id 20050501123000 1 DROP TABLE t1;
mysql-test/t/group_by.test +27 −1 Original line number Diff line number Diff line # Initialise --disable_warnings drop table if exists t1,t2,t3; Loading Loading @@ -524,7 +525,7 @@ select min(b) from t1; drop table t1; # # Test for bug #11088: GROUP BY a BLOB colimn with COUNT(DISTINCT column1) # Test for bug #11088: GROUP BY a BLOB column with COUNT(DISTINCT column1) # CREATE TABLE t1 (id int PRIMARY KEY, user_id int, hostname longtext); Loading @@ -539,3 +540,28 @@ SELECT hostname, COUNT(DISTINCT user_id) as no FROM t1 WHERE hostname LIKE '%aol%' GROUP BY hostname; DROP TABLE t1; # # Test for bug #8614: GROUP BY 'const' with DISTINCT # CREATE TABLE t1 (a int, b int); INSERT INTO t1 VALUES (1,2), (1,3); SELECT a, b FROM t1 GROUP BY 'const'; SELECT DISTINCT a, b FROM t1 GROUP BY 'const'; DROP TABLE t1; # # Test for bug #11385: GROUP BY for datetime converted to decimals # CREATE TABLE t1 (id INT, dt DATETIME); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); INSERT INTO t1 VALUES ( 1, '2005-05-01 12:30:00' ); SELECT dt DIV 1 AS f, id FROM t1 GROUP BY f; DROP TABLE t1;
sql/field.h +2 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #endif #define NOT_FIXED_DEC 31 #define DATETIME_DEC 6 class Send_field; class Protocol; Loading Loading @@ -861,6 +862,7 @@ class Field_datetime :public Field_str { enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; } #endif enum Item_result cmp_type () const { return INT_RESULT; } uint decimals() const { return DATETIME_DEC; } int store(const char *to,uint length,CHARSET_INFO *charset); int store(double nr); int store(longlong nr); Loading
sql/sql_select.cc +8 −3 Original line number Diff line number Diff line Loading @@ -678,9 +678,14 @@ JOIN::optimize() DBUG_RETURN(1); } simple_group= 0; group_list= remove_const(this, group_list, conds, { ORDER *old_group_list; group_list= remove_const(this, (old_group_list= group_list), conds, rollup.state == ROLLUP::STATE_NONE, &simple_group); if (old_group_list && !group_list) select_distinct= 0; } if (!group_list && group) { order=0; // The output has only one row Loading