From e0e235c3220e2db71f30d8073f2ca69733477599 Mon Sep 17 00:00:00 2001 From: "SergeyV@selena." <> Date: Tue, 30 Aug 2005 17:22:19 +0400 Subject: [PATCH 1/5] Fixes bug #12517. Clear user variables and replication events before closing temp tables in thread cleanup. --- mysql-test/r/connect.result | 16 ++++++++++++++++ mysql-test/t/connect.test | 18 ++++++++++++++++++ sql/sql_class.cc | 4 ++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/connect.result b/mysql-test/r/connect.result index edf30e7f6e4..293ad37c31a 100644 --- a/mysql-test/r/connect.result +++ b/mysql-test/r/connect.result @@ -65,3 +65,19 @@ show tables; Tables_in_test delete from mysql.user where user=_binary"test"; flush privileges; +use test; +drop table if exists t1; +Warnings: +Note 1051 Unknown table 't1' +create table t1 (id integer not null auto_increment primary key); +drop table if exists t2; +Warnings: +Note 1051 Unknown table 't2' +create temporary table t2(id integer not null auto_increment primary key); +set @id := 1; +delete from t1 where id like @id; +use test; +drop table if exists t2; +Warnings: +Note 1051 Unknown table 't2' +drop table if exists t1; diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test index 1a6dca5b69e..9acc18a0cee 100644 --- a/mysql-test/t/connect.test +++ b/mysql-test/t/connect.test @@ -77,4 +77,22 @@ show tables; delete from mysql.user where user=_binary"test"; flush privileges; +# Test for bug #12517. +connect (con2,localhost,root,,test); +connection con2; +use test; +drop table if exists t1; +create table t1 (id integer not null auto_increment primary key); +drop table if exists t2; +create temporary table t2(id integer not null auto_increment primary key); +set @id := 1; +delete from t1 where id like @id; +disconnect con2; +sleep 5; +connect (con1,localhost,root,,test); +connection con1; +use test; +drop table if exists t2; +drop table if exists t1; + # End of 4.1 tests diff --git a/sql/sql_class.cc b/sql/sql_class.cc index e845769d7ad..11b45b848c8 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -353,12 +353,12 @@ void THD::cleanup(void) mysql_ha_flush(this, (TABLE_LIST*) 0, MYSQL_HA_CLOSE_FINAL | MYSQL_HA_FLUSH_ALL); hash_free(&handler_tables_hash); + delete_dynamic(&user_var_events); + hash_free(&user_vars); close_temporary_tables(this); my_free((char*) variables.time_format, MYF(MY_ALLOW_ZERO_PTR)); my_free((char*) variables.date_format, MYF(MY_ALLOW_ZERO_PTR)); my_free((char*) variables.datetime_format, MYF(MY_ALLOW_ZERO_PTR)); - delete_dynamic(&user_var_events); - hash_free(&user_vars); if (global_read_lock) unlock_global_read_lock(this); if (ull) From 668f0e10fabf9779a61bc07df6a329f0f2bd64a8 Mon Sep 17 00:00:00 2001 From: "SergeyV@selena." <> Date: Thu, 8 Sep 2005 12:09:30 +0400 Subject: [PATCH 2/5] Modified test case for bug #12517 --- mysql-test/r/connect.result | 14 ++------------ mysql-test/t/connect.test | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/mysql-test/r/connect.result b/mysql-test/r/connect.result index 293ad37c31a..68c86b80e60 100644 --- a/mysql-test/r/connect.result +++ b/mysql-test/r/connect.result @@ -1,3 +1,4 @@ +drop table if exists t1,t2; show tables; Tables_in_mysql columns_priv @@ -65,19 +66,8 @@ show tables; Tables_in_test delete from mysql.user where user=_binary"test"; flush privileges; -use test; -drop table if exists t1; -Warnings: -Note 1051 Unknown table 't1' create table t1 (id integer not null auto_increment primary key); -drop table if exists t2; -Warnings: -Note 1051 Unknown table 't2' create temporary table t2(id integer not null auto_increment primary key); set @id := 1; delete from t1 where id like @id; -use test; -drop table if exists t2; -Warnings: -Note 1051 Unknown table 't2' -drop table if exists t1; +drop table t1; diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test index 9acc18a0cee..ff15d74e5ac 100644 --- a/mysql-test/t/connect.test +++ b/mysql-test/t/connect.test @@ -6,6 +6,10 @@ # This test makes no sense with the embedded server --source include/not_embedded.inc +--disable_warnings +drop table if exists t1,t2; +--enable_warnings + #connect (con1,localhost,root,,""); #show tables; connect (con1,localhost,root,,mysql); @@ -77,22 +81,18 @@ show tables; delete from mysql.user where user=_binary"test"; flush privileges; -# Test for bug #12517. +# +# Bug#12517: Clear user variables and replication events before +# closing temp tables in thread cleanup. connect (con2,localhost,root,,test); connection con2; -use test; -drop table if exists t1; create table t1 (id integer not null auto_increment primary key); -drop table if exists t2; create temporary table t2(id integer not null auto_increment primary key); set @id := 1; delete from t1 where id like @id; disconnect con2; -sleep 5; -connect (con1,localhost,root,,test); -connection con1; -use test; -drop table if exists t2; -drop table if exists t1; +--sleep 5 +connection default; +drop table t1; # End of 4.1 tests From 98a52fa9a434319a1c8ac1b859ca39fa62faa17e Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 8 Sep 2005 16:47:27 +0200 Subject: [PATCH 3/5] corrected typo --- ndb/src/mgmsrv/MgmtSrvr.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ndb/src/mgmsrv/MgmtSrvr.cpp b/ndb/src/mgmsrv/MgmtSrvr.cpp index e9d3ce19076..011643237f8 100644 --- a/ndb/src/mgmsrv/MgmtSrvr.cpp +++ b/ndb/src/mgmsrv/MgmtSrvr.cpp @@ -2506,6 +2506,7 @@ MgmtSrvr::startBackup(Uint32& backupId, int waitCompleted) #endif if (rep->failNo == nodeId || waitCompleted == 1) + return 1326; // wait for next signal // master node will report aborted backup break; From 0f4bb8e6ff5de3b0637e3336e58913fa8d372c6d Mon Sep 17 00:00:00 2001 From: "tulin@dl145c.mysql.com" <> Date: Thu, 8 Sep 2005 19:27:37 +0200 Subject: [PATCH 4/5] SignalSender.cpp: fixed compile error --- ndb/src/ndbapi/SignalSender.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndb/src/ndbapi/SignalSender.cpp b/ndb/src/ndbapi/SignalSender.cpp index 0a23529dc73..a1c80f22041 100644 --- a/ndb/src/ndbapi/SignalSender.cpp +++ b/ndb/src/ndbapi/SignalSender.cpp @@ -266,5 +266,5 @@ SignalSender::execNodeStatus(void* signalSender, template SimpleSignal* SignalSender::waitFor(unsigned, WaitForNode&); template SimpleSignal* SignalSender::waitFor(unsigned, WaitForAny&); -template Vector; +template class Vector; From 19192328f29abd99155523d24f06a04888578494 Mon Sep 17 00:00:00 2001 From: "igor@rurik.mysql.com" <> Date: Thu, 8 Sep 2005 12:37:16 -0700 Subject: [PATCH 5/5] sql_select.cc: Fixed bug #12885. Forced inheritence of the maybe_null flag for the expressions containing GROUP BY attributes in selects with ROLLUP. olap.test, olap.result: Added test case for bug #12885. --- mysql-test/r/olap.result | 13 +++++++++++++ mysql-test/t/olap.test | 13 +++++++++++++ sql/sql_select.cc | 17 ++++++++++++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/olap.result b/mysql-test/r/olap.result index 7178895cf80..65f7c649624 100644 --- a/mysql-test/r/olap.result +++ b/mysql-test/r/olap.result @@ -516,3 +516,16 @@ a b c count 1 NULL NULL 2 NULL NULL NULL 2 DROP TABLE t1; +CREATE TABLE t1 (a int(11) NOT NULL); +INSERT INTO t1 VALUES (1),(2); +SELECT * FROM (SELECT a, a + 1, COUNT(*) FROM t1 GROUP BY a WITH ROLLUP) t; +a a + 1 COUNT(*) +1 2 1 +2 3 1 +NULL NULL 2 +SELECT * FROM (SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP) t; +a LENGTH(a) COUNT(*) +1 1 1 +2 1 1 +NULL NULL 2 +DROP TABLE t1; diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test index c9a16b897c6..76c62d14621 100644 --- a/mysql-test/t/olap.test +++ b/mysql-test/t/olap.test @@ -250,4 +250,17 @@ SELECT a, b, a AS c, COUNT(*) AS count FROM t1 GROUP BY a, b, c WITH ROLLUP; DROP TABLE t1; +# +# Bug #11885: derived table specified by a subquery with +# ROLLUP over expressions on not nullable group by attributes +# + +CREATE TABLE t1 (a int(11) NOT NULL); +INSERT INTO t1 VALUES (1),(2); + +SELECT * FROM (SELECT a, a + 1, COUNT(*) FROM t1 GROUP BY a WITH ROLLUP) t; +SELECT * FROM (SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP) t; + +DROP TABLE t1; + # End of 4.1 tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e7af2a1aa75..3de546fd619 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -9277,6 +9277,8 @@ void free_underlaid_joins(THD *thd, SELECT_LEX *select) The function replaces occurrences of group by fields in expr by ref objects for these fields unless they are under aggregate functions. + The function also corrects value of the the maybe_null attribute + for the items of all subexpressions containing group by fields. IMPLEMENTATION The function recursively traverses the tree of the expr expression, @@ -9287,6 +9289,9 @@ void free_underlaid_joins(THD *thd, SELECT_LEX *select) This substitution is needed GROUP BY queries with ROLLUP if SELECT list contains expressions over group by attributes. + TODO: Some functions are not null-preserving. For those functions + updating of the maybe_null attribute is an overkill. + EXAMPLES SELECT a+1 FROM t1 GROUP BY a WITH ROLLUP SELECT SUM(a)+a FROM t1 GROUP BY a WITH ROLLUP @@ -9307,6 +9312,7 @@ static bool change_group_ref(THD *thd, Item_func *expr, ORDER *group_list, arg != arg_end; arg++) { Item *item= *arg; + bool arg_changed= FALSE; if (item->type() == Item::FIELD_ITEM || item->type() == Item::REF_ITEM) { ORDER *group_tmp; @@ -9318,15 +9324,20 @@ static bool change_group_ref(THD *thd, Item_func *expr, ORDER *group_list, if(!(new_item= new Item_ref(group_tmp->item, 0, item->name))) return 1; // fatal_error is set thd->change_item_tree(arg, new_item); - *changed= TRUE; + arg_changed= TRUE; } } } else if (item->type() == Item::FUNC_ITEM) { - if (change_group_ref(thd, (Item_func *) item, group_list, changed)) + if (change_group_ref(thd, (Item_func *) item, group_list, &arg_changed)) return 1; } + if (arg_changed) + { + expr->maybe_null= 1; + *changed= TRUE; + } } } return 0; @@ -9389,7 +9400,7 @@ bool JOIN::rollup_init() } if (item->type() == Item::FUNC_ITEM) { - bool changed= 0; + bool changed= FALSE; if (change_group_ref(thd, (Item_func *) item, group_list, &changed)) return 1; /*