From 0812385dcc5557e25e09371dedf52bccd0102d4a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Jun 2005 09:45:41 -0700 Subject: [PATCH 1/2] group_by.result, group_by.test: Added a test case for bug #8614. sql_select.cc: Fixed bug #8614. SELECT DISTINCT ... GROUP BY 'const' must be equivalent to SELECT ... GROUP BY 'const'. sql/sql_select.cc: Fixed bug #8614. SELECT DISTINCT ... GROUP BY 'const' must be equivalent to SELECT ... GROUP BY 'const'. mysql-test/t/group_by.test: Added a test case for bug #8614. mysql-test/r/group_by.result: Added a test case for bug #8614. --- mysql-test/r/group_by.result | 10 ++++++++++ mysql-test/t/group_by.test | 15 ++++++++++++++- sql/sql_select.cc | 11 ++++++++--- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 3e082fa04e3..ee4b6a31f2f 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -722,3 +722,13 @@ 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; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 21d5abcc287..f9d113a9c50 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -1,3 +1,4 @@ + # Initialise --disable_warnings drop table if exists t1,t2,t3; @@ -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); @@ -539,3 +540,15 @@ 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; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 352227acc68..5b5dde54bc9 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -676,9 +676,14 @@ JOIN::optimize() DBUG_RETURN(1); } simple_group= 0; - group_list= remove_const(this, group_list, conds, - rollup.state == ROLLUP::STATE_NONE, - &simple_group); + { + 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 From 15b113e186939e091af4c93759dfc1ca66a37fda Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Jun 2005 10:49:04 -0700 Subject: [PATCH 2/2] group_by.result: Added a test case for bug #11385. group_by.test: Added a test case for bug #11385. field.h: Fixed bug #11385. The bug was due to not defined method decimals for the class Field_datetime. sql/field.h: Fixed bug #11385. The bug was due to not defined method decimals for the class Field_datetime. mysql-test/t/group_by.test: Added atest case for bug #11385. mysql-test/r/group_by.result: Added a test case for bug #11385. --- mysql-test/r/group_by.result | 9 +++++++++ mysql-test/t/group_by.test | 15 ++++++++++++++- sql/field.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index ee4b6a31f2f..e279fca2a9d 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -732,3 +732,12 @@ 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; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index f9d113a9c50..382580cbd4e 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -543,7 +543,7 @@ SELECT hostname, COUNT(DISTINCT user_id) as no FROM t1 DROP TABLE t1; # -# Test for bug #8614: GROUP BY 'const with DISTINCT +# Test for bug #8614: GROUP BY 'const' with DISTINCT # CREATE TABLE t1 (a int, b int); @@ -552,3 +552,16 @@ 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; diff --git a/sql/field.h b/sql/field.h index 1d7669d540d..ba963418c7a 100644 --- a/sql/field.h +++ b/sql/field.h @@ -25,6 +25,7 @@ #endif #define NOT_FIXED_DEC 31 +#define DATETIME_DEC 6 class Send_field; class Protocol; @@ -861,6 +862,7 @@ public: 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);