From 489bd55741a663f1896fbe7fad5792ef41ed8913 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 11 Jan 2005 11:53:39 +0200 Subject: [PATCH 1/3] error of parsing can occur in any SELECT, so all SELECTs have to be checked --- sql/sql_lex.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index d2ac0df1472..f5a0fef6769 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -163,7 +163,8 @@ void lex_start(THD *thd, uchar *buf,uint length) void lex_end(LEX *lex) { - lex->select_lex.expr_list.delete_elements(); // If error when parsing sql-varargs + for(SELECT_LEX *sl= lex->all_selects_list; sl; sl= sl->next_select_in_list()) + sl->expr_list.delete_elements(); // If error when parsing sql-varargs x_free(lex->yacc_yyss); x_free(lex->yacc_yyvs); } From 7f586778f33c9393c26c5c38e224a83d5e1837c6 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 16 Jan 2005 18:36:13 +0200 Subject: [PATCH 2/3] postreview changes sql/sql_lex.cc: layout fixed --- sql/sql_lex.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index f5a0fef6769..e3137bf3766 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -163,7 +163,9 @@ void lex_start(THD *thd, uchar *buf,uint length) void lex_end(LEX *lex) { - for(SELECT_LEX *sl= lex->all_selects_list; sl; sl= sl->next_select_in_list()) + for (SELECT_LEX *sl= lex->all_selects_list; + sl; + sl= sl->next_select_in_list()) sl->expr_list.delete_elements(); // If error when parsing sql-varargs x_free(lex->yacc_yyss); x_free(lex->yacc_yyvs); From b3cd49f3127f5cf41d2b4e42c6597262ca6a5376 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 20 Jan 2005 13:56:22 +0200 Subject: [PATCH 3/3] fixed problem with distinct select with grouping and subqueries (BUG#7946) mysql-test/r/derived.result: DISTINCT over grouped select on subquery in the FROM clause mysql-test/t/derived.test: DISTINCT over grouped select on subquery in the FROM clause sql/sql_select.cc: used current join copy for test --- mysql-test/r/derived.result | 9 +++++++++ mysql-test/t/derived.test | 10 ++++++++++ sql/sql_select.cc | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result index 7e6b9b44566..61d745d0236 100644 --- a/mysql-test/r/derived.result +++ b/mysql-test/r/derived.result @@ -330,3 +330,12 @@ SELECT MIN(price) min, MAX(price) max, AVG(price) avg FROM (SELECT SUBSTRING( MA min max avg 10.00 10.00 10 DROP TABLE t1; +create table t1 (a integer, b integer); +insert into t1 values (1,4), (2,2),(2,2), (4,1),(4,1),(4,1),(4,1); +select distinct sum(b) from t1 group by a; +sum(b) +4 +select distinct sum(b) from (select a,b from t1) y group by a; +sum(b) +4 +drop table t1; diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test index 64e3fe8929b..8b322746ed6 100644 --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@ -214,3 +214,13 @@ CREATE TABLE `t1` ( `itemid` int(11) NOT NULL default '0', `grpid` varchar(15) N insert into t1 values (128, 'rozn', 2, now(), 10),(128, 'rozn', 1, now(), 10); SELECT MIN(price) min, MAX(price) max, AVG(price) avg FROM (SELECT SUBSTRING( MAX(concat(date_,";",price)), 12) price FROM t1 WHERE itemid=128 AND grpid='rozn' GROUP BY itemid, grpid, vendor) lastprices; DROP TABLE t1; + +# +# DISTINCT over grouped select on subquery in the FROM clause +# +create table t1 (a integer, b integer); +insert into t1 values (1,4), (2,2),(2,2), (4,1),(4,1),(4,1),(4,1); +select distinct sum(b) from t1 group by a; +select distinct sum(b) from (select a,b from t1) y group by a; +drop table t1; + diff --git a/sql/sql_select.cc b/sql/sql_select.cc index aea7cb9ed6d..b2fb7ec0275 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1304,7 +1304,7 @@ JOIN::exec() curr_join->select_distinct=0; /* Each row is unique */ curr_join->join_free(0); /* Free quick selects */ - if (select_distinct && ! group_list) + if (curr_join->select_distinct && ! curr_join->group_list) { thd->proc_info="Removing duplicates"; if (curr_join->tmp_having)