|
|||||||||||
|
bk commit into 4.1 tree (holyfoot:1.2677) BUG#29717
From: <holyfoot(at)mysql.com>
Date: Mon Jul 30 2007 - 15:44:52 EDT
ChangeSet@1.2677, 2007-07-31 00:44:50+05:00, holyfoot@mysql.com +6 -0 Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself returns empty. As a result of this bug 'SELECT AGGREGATE_FUNCTION(fld) ... GROUP BY' can return one row instead of empty recordset. When GROUP BY only has fields of a 'constant' table (with a single row), optimizer deletes the group_list. After that we lost the information about whether we had an GROUP BY statement. Though it's important as SELECT min(x) from empty_table; and
SELECT min(x) from empty_table GROUP BY y; have to return
different results - first query should return one row,
second - an empty recordset.
mysql-test/r/group_by.result@1.54, 2007-07-31 00:44:36+05:00, holyfoot@mysql.com +16 -0 Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself returns empty. test result mysql-test/r/insert_select.result@1.31, 2007-07-31 00:44:36+05:00, holyfoot@mysql.com +26 -0 Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself returns empty. test result mysql-test/t/group_by.test@1.45, 2007-07-31 00:44:36+05:00, holyfoot@mysql.com +22 -0 Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself returns empty. This is additional testcase that is more basic than the original bug's testcase and has the same reason. mysql-test/t/insert_select.test@1.25, 2007-07-31 00:44:36+05:00, holyfoot@mysql.com +28 -0 Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself returns empty. test case sql/sql_select.cc@1.473, 2007-07-31 00:44:36+05:00, holyfoot@mysql.com +3 -1 Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself returns empty. Remember the 'GROUP BY was optimized away' case in the JOIN::group_optimized and check this in the end_send_group() sql/sql_select.h@1.82, 2007-07-31 00:44:36+05:00, holyfoot@mysql.com +9 -0 Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself returns empty. JOIN::group_optimized member added to remember the 'GROUP BY optimied away' case diff -Nrup a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result --- a/mysql-test/r/group_by.result 2006-10-16 15:10:18 +05:00@@ -818,3 +818,19 @@ a 2 1 DROP TABLE t1; +CREATE TABLE t1 ( +f1 int(10) unsigned NOT NULL auto_increment primary key, +f2 varchar(100) NOT NULL default '' +); +CREATE TABLE t2 ( +f1 varchar(10) NOT NULL default '', +f2 char(3) NOT NULL default '', +PRIMARY KEY (`f1`), +KEY `k1` (`f2`,`f1`) +); +INSERT INTO t1 values(NULL, ''); +INSERT INTO `t2` VALUES ('486878','WDT'),('486910','WDT'); +SELECT SQL_BUFFER_RESULT avg(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1; +avg(t2.f1) +SELECT avg(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1; +avg(t2.f1) diff -Nrup a/mysql-test/r/insert_select.result b/mysql-test/r/insert_select.result --- a/mysql-test/r/insert_select.result 2006-06-19 15:22:38 +05:00@@ -690,3 +690,29 @@ CREATE TABLE t1 (a int PRIMARY KEY); INSERT INTO t1 values (1), (2); INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1; DROP TABLE t1; +CREATE TABLE t1 ( +f1 int(10) unsigned NOT NULL auto_increment PRIMARY KEY, +f2 varchar(100) NOT NULL default '' +); +CREATE TABLE t2 ( +f1 varchar(10) NOT NULL default '', +f2 char(3) NOT NULL default '', +PRIMARY KEY (`f1`), +KEY `k1` (`f2`, `f1`) +); +INSERT INTO t1 values(NULL, ''); +INSERT INTO `t2` VALUES ('486878','WDT'),('486910','WDT'); +SELECT COUNT(*) FROM t1; +COUNT(*) +1 +SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1; +min(t2.f1) +INSERT INTO t1 (f2) +SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1; +SELECT COUNT(*) FROM t1; +COUNT(*) +1 +SELECT * FROM t1; +f1 f2 +1 +DROP TABLE t1, t2; diff -Nrup a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test --- a/mysql-test/t/group_by.test 2006-10-16 15:10:19 +05:00@@ -633,4 +633,26 @@ SELECT a FROM t1 ORDER BY 'a' DESC; SELECT a FROM t1 ORDER BY "a" DESC; SELECT a FROM t1 ORDER BY `a` DESC; DROP TABLE t1; + + +# +# Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself +# returns empty +# +CREATE TABLE t1 ( + f1 int(10) unsigned NOT NULL auto_increment primary key, + f2 varchar(100) NOT NULL default '' +); +CREATE TABLE t2 ( + f1 varchar(10) NOT NULL default '', + f2 char(3) NOT NULL default '', + PRIMARY KEY (`f1`), + KEY `k1` (`f2`,`f1`) +); + +INSERT INTO t1 values(NULL, ''); +INSERT INTO `t2` VALUES ('486878','WDT'),('486910','WDT'); +SELECT SQL_BUFFER_RESULT avg(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1; +SELECT avg(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1; + # End of 4.1 tests diff -Nrup a/mysql-test/t/insert_select.test b/mysql-test/t/insert_select.test --- a/mysql-test/t/insert_select.test 2006-06-19 15:22:38 +05:00@@ -239,4 +239,32 @@ INSERT INTO t1 SELECT a + 2 FROM t1 LIMI DROP TABLE t1; +# --- a/sql/sql_select.cc 2007-05-15 11:55:16 +05:00 + group_optimized_away= 1; }
calc_group_buffer(this, group_list);
if (!join->first_record || end_of_records ||
(idx=test_if_group_changed(join->group_fields)) >= 0)
{
{
if (join->procedure)
join->procedure->end_group();
diff -Nrup a/sql/sql_select.h b/sql/sql_select.h
--- a/sql/sql_select.h 2006-06-28 18:28:25 +05:00
+ /* + If we have the GROUP BY statement in the query, + but the group_list was emptied by optimizer, this + flag is TRUE. + It happens when fields in the GROUP BY are from + constant table + */ + bool group_optimized_away;
/*
ref_pointer_array_size= 0;
zero_result_cause= 0;
optimized= 0;
+ group_optimized_away= 0;
fields_list= fields_arg;
bzero((char*) &keyuse,sizeof(keyuse));
-- MySQL Code Commits Mailing List For list archives: http://lists.mysql.com/commits To unsubscribe: http://lists.mysql.com/commits?unsub=lists@pantek.comReceived on Mon Jul 30 16:46:40 2007 This archive was generated by hypermail 2.1.8 : Thu Aug 09 2007 - 19:19:02 EDT |
||||||||||
|
|||||||||||