From 8270d9875ff44900f3c57c15711c03d0b83cbe5d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 6 Mar 2008 18:19:47 +0300 Subject: [PATCH 01/15] Fix for bug #34512: CAST( AVG( double ) AS DECIMAL ) returns wrong results Casting AVG() to DECIMAL led to incorrect results when the arguments had a non-DECIMAL type, because in this case Item_sum_avg::val_decimal() performed the division by the number of arguments twice. Fixed by changing Item_sum_avg::val_decimal() to not rely on Item_sum_sum::val_decimal(), i.e. calculate sum and divide using DECIMAL arithmetics for DECIMAL arguments, and utilize val_real() with subsequent conversion to DECIMAL otherwise. mysql-test/r/func_group.result: Added a test case for bug #34512. mysql-test/t/func_group.test: Added a test case for bug #34512. sql/item_sum.cc: Do not use Item_sum_sum::val_decimal() in Item_sum_avg::val_decimal() because the first one, depending on the arguments type, may return either the sum of the arguments, or the average calculated by the virtual val_real() method of Item_sum_avg. Instead, do our own calculation based on the arguments type. --- mysql-test/r/func_group.result | 6 ++++++ mysql-test/t/func_group.test | 10 ++++++++++ sql/item_sum.cc | 10 +++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index 4785ca9919d..772e432355b 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -1419,4 +1419,10 @@ Note 1003 select (`test`.`t1`.`a` + 1) AS `y` from `test`.`t1` group by (`test`. DROP VIEW v1; DROP TABLE t1; SET SQL_MODE=DEFAULT; +CREATE TABLE t1(a DOUBLE); +INSERT INTO t1 VALUES (10), (20); +SELECT AVG(a), CAST(AVG(a) AS DECIMAL) FROM t1; +AVG(a) CAST(AVG(a) AS DECIMAL) +15 15 +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index 75a380c733f..dbe6d3113d5 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -916,5 +916,15 @@ DROP VIEW v1; DROP TABLE t1; SET SQL_MODE=DEFAULT; +# +# Bug #34512: CAST( AVG( double ) AS DECIMAL ) returns wrong results +# + +CREATE TABLE t1(a DOUBLE); +INSERT INTO t1 VALUES (10), (20); +SELECT AVG(a), CAST(AVG(a) AS DECIMAL) FROM t1; + +DROP TABLE t1; + ### --echo End of 5.0 tests diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 3d6d46ab3f4..f583fc7f988 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1206,7 +1206,15 @@ my_decimal *Item_sum_avg::val_decimal(my_decimal *val) null_value=1; return NULL; } - sum_dec= Item_sum_sum::val_decimal(&sum_buff); + + /* + For non-DECIMAL hybrid_type the division will be done in + Item_sum_avg::val_real(). + */ + if (hybrid_type != DECIMAL_RESULT) + return val_decimal_from_real(val); + + sum_dec= dec_buffs + curr_dec_buff; int2my_decimal(E_DEC_FATAL_ERROR, count, 0, &cnt); my_decimal_div(E_DEC_FATAL_ERROR, val, sum_dec, &cnt, prec_increment); return val; From 0ba100d3031d78631b9d56d439f0845887fc880e Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 7 Mar 2008 21:14:34 +0300 Subject: [PATCH 02/15] Fix for bug #34650: Test suite without cluster fails on Mac OS X Leopard. The change_user test failed because results of some statements depended on platform and server build flags. subselect_notembedded failure was a result of a bad merge from 5.0. Fixed the corresponding test cases. mysql-test/r/change_user.result: Fixed the test case. mysql-test/r/subselect.result: Fixed the test case. mysql-test/r/subselect_notembedded.result: Fixed the test case. mysql-test/t/change_user.test: Fixed the test case. mysql-test/t/subselect.test: Fixed the test case. mysql-test/t/subselect_notembedded.test: Fixed the test case. --- mysql-test/r/change_user.result | 4 +- mysql-test/r/subselect.result | 35 ------ mysql-test/r/subselect_notembedded.result | 129 ++++++---------------- mysql-test/t/change_user.test | 7 ++ mysql-test/t/subselect.test | 46 -------- mysql-test/t/subselect_notembedded.test | 126 +++++++-------------- 6 files changed, 80 insertions(+), 267 deletions(-) diff --git a/mysql-test/r/change_user.result b/mysql-test/r/change_user.result index 28b55dfd5e5..a075c01fe61 100644 --- a/mysql-test/r/change_user.result +++ b/mysql-test/r/change_user.result @@ -4,14 +4,14 @@ SELECT @@session.sql_big_selects; 1 SELECT @@global.max_join_size; @@global.max_join_size -18446744073709551615 +HA_POS_ERROR change_user SELECT @@session.sql_big_selects; @@session.sql_big_selects 1 SELECT @@global.max_join_size; @@global.max_join_size -18446744073709551615 +HA_POS_ERROR SET @@global.max_join_size = 10000; SET @@session.max_join_size = default; change_user diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index fe8374d665b..20d44933128 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -4155,41 +4155,6 @@ SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1; 0 0 DROP TABLE t1, t2; -create table t1(a int,b int,key(a),key(b)); -insert into t1(a,b) values (1,2),(2,1),(2,3),(3,4),(5,4),(5,5), -(6,7),(7,4),(5,3); -5 -4 -3 -2 -1 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 -drop table t1; CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5)); INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43); SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1); diff --git a/mysql-test/r/subselect_notembedded.result b/mysql-test/r/subselect_notembedded.result index 90aadcae398..9ef8c492ee3 100644 --- a/mysql-test/r/subselect_notembedded.result +++ b/mysql-test/r/subselect_notembedded.result @@ -4,101 +4,36 @@ purge master logs before adddate(current_timestamp(), interval -4 day); create table t1(a int,b int,key(a),key(b)); insert into t1(a,b) values (1,2),(2,1),(2,3),(3,4),(5,4),(5,5), (6,7),(7,4),(5,3); -select sum(a),a from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 -)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1) -group by a; -sum(a) a -select sum(a),a from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1) -group by a; -ERROR HY000: Thread stack overrun detected -explain select sum(a),a from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 -)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1) -group by a; -id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 index a a 5 NULL 9 Using where; Using index -2 SUBQUERY t1 index a b 5 NULL 9 Using where; Using filesort -3 SUBQUERY t1 index a b 5 NULL 9 Using where; Using filesort -4 SUBQUERY t1 index a b 5 NULL 9 Using where; Using filesort -5 SUBQUERY t1 index a b 5 NULL 9 Using where; Using filesort -6 SUBQUERY t1 index a b 5 NULL 9 Using where; Using filesort -7 SUBQUERY t1 index a b 5 NULL 9 Using where; Using filesort -8 SUBQUERY t1 index a b 5 NULL 9 Using where; Using filesort -9 SUBQUERY t1 index a b 5 NULL 9 Using where; Using filesort -10 SUBQUERY t1 index a b 5 NULL 9 Using where; Using filesort -11 SUBQUERY t1 index a b 5 NULL 9 Using where; Using filesort -12 SUBQUERY t1 range a a 5 NULL 1 Using where; Using temporary; Using filesort -13 SUBQUERY t1 index NULL a 5 NULL 9 Using index -explain select sum(a),a from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( -select sum(a) from t1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1 -)group by b limit 1)group by b limit 1)group by b limit 1) -group by a; -ERROR HY000: Thread stack overrun detected +5 +4 +3 +2 +1 +26 +25 +24 +23 +22 +21 +20 +19 +18 +17 +16 +15 +14 +13 +12 +11 +10 +9 +8 +7 +6 +5 +4 +3 +2 +1 drop table t1; +End of 5.1 tests diff --git a/mysql-test/t/change_user.test b/mysql-test/t/change_user.test index d0cdfc8a741..bc29895eb47 100644 --- a/mysql-test/t/change_user.test +++ b/mysql-test/t/change_user.test @@ -4,17 +4,24 @@ --echo Bug#20023 SELECT @@session.sql_big_selects; +# The exact value depends on the server build flags +--replace_result 4294967295 HA_POS_ERROR 18446744073709551615 HA_POS_ERROR SELECT @@global.max_join_size; --echo change_user --change_user SELECT @@session.sql_big_selects; +# The exact value depends on the server build flags +--replace_result 4294967295 HA_POS_ERROR 18446744073709551615 HA_POS_ERROR SELECT @@global.max_join_size; SET @@global.max_join_size = 10000; SET @@session.max_join_size = default; --echo change_user --change_user SELECT @@session.sql_big_selects; +# May produce a warning depending on server build flags +--disable_warnings SET @@global.max_join_size = -1; +--enable_warnings SET @@session.max_join_size = default; --echo change_user --change_user diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index fb3e59cc9d6..c86b0fefbdc 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -3015,52 +3015,6 @@ INSERT INTO t2 VALUES (103, 203); SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1; DROP TABLE t1, t2; -# -# Bug31048: Many nested subqueries may cause server crash. -# -create table t1(a int,b int,key(a),key(b)); -insert into t1(a,b) values (1,2),(2,1),(2,3),(3,4),(5,4),(5,5), - (6,7),(7,4),(5,3); - -let $nesting= 26; -let $should_work_nesting= 5; -let $start= select sum(a),a from t1 where a> ( select sum(a) from t1 ; -let $end= )group by a ; -let $start_app= where a> ( select sum(a) from t1 ; -let $end_pre= )group by b limit 1 ; - ---disable_result_log ---disable_query_log -# At least 4 level nesting should work without errors -while ($should_work_nesting) -{ ---echo $should_work_nesting - eval $start $end; - eval explain $start $end; - let $start= $start - $start_app; - let $end= $end_pre - $end; - dec $should_work_nesting; -} -# Other may fail with the 'stack overrun error' -while ($nesting) -{ ---echo $nesting ---error 0,1436 - eval $start $end; ---error 0,1436 - eval explain $start $end; - let $start= $start - $start_app; - let $end= $end_pre - $end; - dec $nesting; -} ---enable_result_log ---enable_query_log -drop table t1; - # # Bug #28076: inconsistent binary/varbinary comparison # diff --git a/mysql-test/t/subselect_notembedded.test b/mysql-test/t/subselect_notembedded.test index 040c90452b9..2f1cc261f56 100644 --- a/mysql-test/t/subselect_notembedded.test +++ b/mysql-test/t/subselect_notembedded.test @@ -14,92 +14,44 @@ purge master logs before adddate(current_timestamp(), interval -4 day); create table t1(a int,b int,key(a),key(b)); insert into t1(a,b) values (1,2),(2,1),(2,3),(3,4),(5,4),(5,5), (6,7),(7,4),(5,3); -# test for the stack overflow bug -select sum(a),a from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 - )group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1) -group by a; ---replace_regex /overrun.*$/overrun detected/ ---error 1436 -select sum(a),a from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1) -group by a; -# test for the memory consumption & subquery slowness bug -explain select sum(a),a from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 - )group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1) -group by a; ---replace_regex /overrun.*$/overrun detected/ ---error 1436 -explain select sum(a),a from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 where a> ( select sum(a) from t1 where a> ( - select sum(a) from t1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1 - )group by b limit 1)group by b limit 1)group by b limit 1) -group by a; + +let $nesting= 26; +let $should_work_nesting= 5; +let $start= select sum(a),a from t1 where a> ( select sum(a) from t1 ; +let $end= )group by a ; +let $start_app= where a> ( select sum(a) from t1 ; +let $end_pre= )group by b limit 1 ; + +--disable_result_log +--disable_query_log +# At least 4 level nesting should work without errors +while ($should_work_nesting) +{ +--echo $should_work_nesting + eval $start $end; + eval explain $start $end; + let $start= $start + $start_app; + let $end= $end_pre + $end; + dec $should_work_nesting; +} +# Other may fail with the 'stack overrun error' +while ($nesting) +{ +--echo $nesting +--error 0,1436 + eval $start $end; +--error 0,1436 + eval explain $start $end; + let $start= $start + $start_app; + let $end= $end_pre + $end; + dec $nesting; +} +--enable_result_log +--enable_query_log drop table t1; - +--echo End of 5.1 tests From 45b4d937c6bb7e1483c1fdbaf15bcb20a08ae683 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 14 Mar 2008 14:12:39 +0400 Subject: [PATCH 03/15] Bug#35108 SELECT FROM REFERENTIAL_CONSTRAINTS crashes referenced_key_name field can be uninitialized in the case when referenced table is dropped. Added codition which allows to handle this situation. mysql-test/r/information_schema_inno.result: test result mysql-test/t/information_schema_inno.test: test result sql/sql_show.cc: referenced_key_name field can be uninitialized in the case when referenced table is dropped. Added codition which allows to handle this situation. --- mysql-test/r/information_schema_inno.result | 11 +++++++++++ mysql-test/t/information_schema_inno.test | 13 +++++++++++++ sql/sql_show.cc | 14 ++++++++++---- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/information_schema_inno.result b/mysql-test/r/information_schema_inno.result index 2ea2a0bec0b..4f36fd2b8b5 100644 --- a/mysql-test/r/information_schema_inno.result +++ b/mysql-test/r/information_schema_inno.result @@ -78,3 +78,14 @@ NULL NULL db-1 t-2 NULL NULL drop database `db-1`; +create table t1(id int primary key) engine = Innodb; +create table t2(pid int, foreign key (pid) references t1(id)) engine = Innodb; +set foreign_key_checks = 0; +drop table t1; +select UNIQUE_CONSTRAINT_NAME +from information_schema.referential_constraints +where constraint_schema = schema(); +UNIQUE_CONSTRAINT_NAME +NULL +drop table t2; +set foreign_key_checks = 1; diff --git a/mysql-test/t/information_schema_inno.test b/mysql-test/t/information_schema_inno.test index e73f4ba2792..1a537d740b7 100644 --- a/mysql-test/t/information_schema_inno.test +++ b/mysql-test/t/information_schema_inno.test @@ -76,3 +76,16 @@ select referenced_table_schema, referenced_table_name from information_schema.key_column_usage where constraint_schema = 'db-1'; drop database `db-1`; + +# +# Bug#35108 SELECT FROM REFERENTIAL_CONSTRAINTS crashes +# +create table t1(id int primary key) engine = Innodb; +create table t2(pid int, foreign key (pid) references t1(id)) engine = Innodb; +set foreign_key_checks = 0; +drop table t1; +select UNIQUE_CONSTRAINT_NAME +from information_schema.referential_constraints +where constraint_schema = schema(); +drop table t2; +set foreign_key_checks = 1; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 6e61ee6da5f..6becbe12ed4 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -5276,8 +5276,14 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables, f_key_info->referenced_db->length, cs); table->field[10]->store(f_key_info->referenced_table->str, f_key_info->referenced_table->length, cs); - table->field[5]->store(f_key_info->referenced_key_name->str, - f_key_info->referenced_key_name->length, cs); + if (f_key_info->referenced_key_name) + { + table->field[5]->store(f_key_info->referenced_key_name->str, + f_key_info->referenced_key_name->length, cs); + table->field[5]->set_notnull(); + } + else + table->field[5]->set_null(); table->field[6]->store(STRING_WITH_LEN("NONE"), cs); table->field[7]->store(f_key_info->update_method->str, f_key_info->update_method->length, cs); @@ -6480,8 +6486,8 @@ ST_FIELD_INFO referential_constraints_fields_info[]= OPEN_FULL_TABLE}, {"UNIQUE_CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE}, - {"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, - OPEN_FULL_TABLE}, + {"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, + MY_I_S_MAYBE_NULL, 0, OPEN_FULL_TABLE}, {"MATCH_OPTION", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE}, {"UPDATE_RULE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE}, {"DELETE_RULE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE}, From 9699767c952bf30ab4b18a15e131ba417745f855 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 14 Mar 2008 23:11:59 +0400 Subject: [PATCH 04/15] Fixed bug #34763. Queries like: SELECT ROW(1, 2) IN (SELECT t1.a, 2) FROM t1 GROUP BY t1.a or SELECT ROW(1, 2) IN (SELECT t1.a, 2 FROM t2) FROM t1 GROUP BY t1.a lead to assertion failure in the Item_in_subselect::row_value_transformer method in debugging build, or to unexpected error message in release build: ERROR 1247 (42S22): Reference '' not supported (forward reference in item list) Unexpected error message and assertion failure have been eliminated. mysql-test/r/subselect3.result: Added test case for bug #34763. mysql-test/t/subselect3.test: Added test case for bug #34763. sql/item.cc: Fixed bug #34763. The Item_ref::fix_fields method has been modified to silently ignore not fixed outer references: by the definition, those references should be fixed later by the call to the fix_inner_refs function. sql/item_subselect.cc: Fixed bug #34763. The Item_in_subselect::row_value_transformer method has been modified to eliminate assertion failure on not fixed outer references: by the definition those references are allowed in this context and should be fixed later by the call to the fix_inner_refs function. --- mysql-test/r/subselect3.result | 13 ++++++++++++- mysql-test/t/subselect3.test | 19 ++++++++++++++++++- sql/item.cc | 15 +++++++++------ sql/item_subselect.cc | 12 ++++++++++-- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/mysql-test/r/subselect3.result b/mysql-test/r/subselect3.result index bdf00e4c307..c194ba33756 100644 --- a/mysql-test/r/subselect3.result +++ b/mysql-test/r/subselect3.result @@ -758,5 +758,16 @@ EXPLAIN SELECT a FROM t1 WHERE a NOT IN (SELECT a FROM t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where 2 DEPENDENT SUBQUERY t2 unique_subquery PRIMARY PRIMARY 4 func 1 Using index; Using where -DROP TABLE t1; +DROP TABLE t1, t2; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES(1); +CREATE TABLE t2 (placeholder CHAR(11)); +INSERT INTO t2 VALUES("placeholder"); +SELECT ROW(1, 2) IN (SELECT t1.a, 2) FROM t1 GROUP BY t1.a; +ROW(1, 2) IN (SELECT t1.a, 2) +1 +SELECT ROW(1, 2) IN (SELECT t1.a, 2 FROM t2) FROM t1 GROUP BY t1.a; +ROW(1, 2) IN (SELECT t1.a, 2 FROM t2) +1 +DROP TABLE t1, t2; End of 5.0 tests diff --git a/mysql-test/t/subselect3.test b/mysql-test/t/subselect3.test index 2f844c9cc21..cfbde8c29cd 100644 --- a/mysql-test/t/subselect3.test +++ b/mysql-test/t/subselect3.test @@ -586,6 +586,23 @@ SELECT a FROM t1 WHERE a NOT IN (65,66); SELECT a FROM t1 WHERE a NOT IN (SELECT a FROM t2); EXPLAIN SELECT a FROM t1 WHERE a NOT IN (SELECT a FROM t2); -DROP TABLE t1; +DROP TABLE t1, t2; + +# +# Bug #34763: item_subselect.cc:1235:Item_in_subselect::row_value_transformer: +# Assertion failed, unexpected error message: +# ERROR 1247 (42S22): Reference '' not supported (forward +# reference in item list) +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES(1); + +CREATE TABLE t2 (placeholder CHAR(11)); +INSERT INTO t2 VALUES("placeholder"); + +SELECT ROW(1, 2) IN (SELECT t1.a, 2) FROM t1 GROUP BY t1.a; +SELECT ROW(1, 2) IN (SELECT t1.a, 2 FROM t2) FROM t1 GROUP BY t1.a; + +DROP TABLE t1, t2; --echo End of 5.0 tests diff --git a/sql/item.cc b/sql/item.cc index 53e7f124ccd..36612ddea44 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -5451,13 +5451,16 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) DBUG_ASSERT(*ref); /* Check if this is an incorrect reference in a group function or forward - reference. Do not issue an error if this is an unnamed reference inside an - aggregate function. + reference. Do not issue an error if this is: + 1. outer reference (will be fixed later by the fix_inner_refs function); + 2. an unnamed reference inside an aggregate function. */ - if (((*ref)->with_sum_func && name && - !(current_sel->linkage != GLOBAL_OPTIONS_TYPE && - current_sel->having_fix_field)) || - !(*ref)->fixed) + if (!((*ref)->type() == REF_ITEM && + ((Item_ref *)(*ref))->ref_type() == OUTER_REF) && + (((*ref)->with_sum_func && name && + !(current_sel->linkage != GLOBAL_OPTIONS_TYPE && + current_sel->having_fix_field)) || + !(*ref)->fixed)) { my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, ((*ref)->with_sum_func? diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index b3710841dfb..a03a7d739b2 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1232,7 +1232,11 @@ Item_in_subselect::row_value_transformer(JOIN *join) Item *item_having_part2= 0; for (uint i= 0; i < cols_num; i++) { - DBUG_ASSERT(left_expr->fixed && select_lex->ref_pointer_array[i]->fixed); + DBUG_ASSERT(left_expr->fixed && + select_lex->ref_pointer_array[i]->fixed || + (select_lex->ref_pointer_array[i]->type() == REF_ITEM && + ((Item_ref*)(select_lex->ref_pointer_array[i]))->ref_type() == + Item_ref::OUTER_REF)); if (select_lex->ref_pointer_array[i]-> check_cols(left_expr->element_index(i)->cols())) DBUG_RETURN(RES_ERROR); @@ -1306,7 +1310,11 @@ Item_in_subselect::row_value_transformer(JOIN *join) for (uint i= 0; i < cols_num; i++) { Item *item, *item_isnull; - DBUG_ASSERT(left_expr->fixed && select_lex->ref_pointer_array[i]->fixed); + DBUG_ASSERT(left_expr->fixed && + select_lex->ref_pointer_array[i]->fixed || + (select_lex->ref_pointer_array[i]->type() == REF_ITEM && + ((Item_ref*)(select_lex->ref_pointer_array[i]))->ref_type() == + Item_ref::OUTER_REF)); if (select_lex->ref_pointer_array[i]-> check_cols(left_expr->element_index(i)->cols())) DBUG_RETURN(RES_ERROR); From f467cbaf441b73e0962f602ec7ae8e4c8b8dc24b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 18 Mar 2008 19:42:04 +0400 Subject: [PATCH 05/15] Bug#35406 5.1-opt crashes on select from I_S.REFERENTIAL_CONSTRAINTS added intialization of f_key_info.referenced_key_name for the case when referenced table is dropped storage/innobase/handler/ha_innodb.cc: added intialization of f_key_info.referenced_key_name for the case when referenced table is dropped --- storage/innobase/handler/ha_innodb.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index f81804c0701..cc284893764 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -6207,6 +6207,8 @@ ha_innobase::get_foreign_key_list(THD *thd, List *f_key_list) foreign->referenced_index->name, strlen(foreign->referenced_index->name), 1); } + else + f_key_info.referenced_key_name= 0; FOREIGN_KEY_INFO *pf_key_info = (FOREIGN_KEY_INFO *) thd_memdup(thd, &f_key_info, sizeof(FOREIGN_KEY_INFO)); From 4018b13915c2fa972cf4da90ab1b2272b855a490 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 19 Mar 2008 15:51:22 +0400 Subject: [PATCH 06/15] Bug #33334 mysqltest_embedded crashes when disconnecting before reap. Before breaking the connection we have to check that there's no query executing at the moment. Otherwise it can lead to crash in embedded server. client/mysqltest.c: Bug #33334 mysqltest_embedded crashes when disconnecting before reap. Wait until the query thread is finished before we break the connection. Waiting part moved to a separate wait_query_thread_end() function mysql-test/r/flush.result: Bug #33334 mysqltest_embedded crashes when disconnecting before reap. test result mysql-test/t/flush.test: Bug #33334 mysqltest_embedded crashes when disconnecting before reap. test case --- client/mysqltest.c | 34 +++++++++++++++++++++++++--------- mysql-test/r/flush.result | 1 + mysql-test/t/flush.test | 9 +++++++++ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 88575c26bc6..b028794295c 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -542,6 +542,17 @@ static int do_send_query(struct st_connection *cn, const char *q, int q_len, return 0; } +static void wait_query_thread_end(struct st_connection *con) +{ + if (!con->query_done) + { + pthread_mutex_lock(&con->mutex); + while (!con->query_done) + pthread_cond_wait(&con->cond, &con->mutex); + pthread_mutex_unlock(&con->mutex); + } +} + #else /*EMBEDDED_LIBRARY*/ #define do_send_query(cn,q,q_len,flags) mysql_send_query(&cn->mysql, q, q_len) @@ -3939,7 +3950,14 @@ void do_close_connection(struct st_command *command) con->mysql.net.vio = 0; } } -#endif +#else + /* + As query could be still executed in a separate theread + we need to check if the query's thread was finished and probably wait + (embedded-server specific) + */ + wait_query_thread_end(con); +#endif /*EMBEDDED_LIBRARY*/ if (con->stmt) mysql_stmt_close(con->stmt); con->stmt= 0; @@ -4229,6 +4247,9 @@ void do_connect(struct st_command *command) (int) (sizeof(connections)/sizeof(struct st_connection))); } +#ifdef EMBEDDED_LIBRARY + con_slot->query_done= 1; +#endif if (!mysql_init(&con_slot->mysql)) die("Failed on mysql_init()"); if (opt_compress || con_compress) @@ -5716,16 +5737,11 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, } #ifdef EMBEDDED_LIBRARY /* - Here we handle 'reap' command, so we need to check if the - query's thread was finished and probably wait + Here we handle 'reap' command, so we need to check if the + query's thread was finished and probably wait */ else if (flags & QUERY_REAP_FLAG) - { - pthread_mutex_lock(&cn->mutex); - while (!cn->query_done) - pthread_cond_wait(&cn->cond, &cn->mutex); - pthread_mutex_unlock(&cn->mutex); - } + wait_query_thread_end(cn); #endif /*EMBEDDED_LIBRARY*/ if (!(flags & QUERY_REAP_FLAG)) DBUG_VOID_RETURN; diff --git a/mysql-test/r/flush.result b/mysql-test/r/flush.result index ce64e09c1d3..778f138f29d 100644 --- a/mysql-test/r/flush.result +++ b/mysql-test/r/flush.result @@ -72,3 +72,4 @@ flush tables with read lock; unlock tables; drop table t1, t2; set session low_priority_updates=default; +select benchmark(200, (select sin(1))) > 1000; diff --git a/mysql-test/t/flush.test b/mysql-test/t/flush.test index 72efa8a2ee6..4c6d4265600 100644 --- a/mysql-test/t/flush.test +++ b/mysql-test/t/flush.test @@ -164,4 +164,13 @@ drop table t1, t2; set session low_priority_updates=default; +# +# Bug #33334 mysqltest_embedded crashes when disconnecting before reap +# + +connect (con1,localhost,root,,); +send select benchmark(200, (select sin(1))) > 1000; +disconnect con1; +connection default; + # End of 5.0 tests From 3c5894baaa9dcc2d910d504ef073facfcd329f8e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 19 Mar 2008 14:32:28 +0100 Subject: [PATCH 07/15] Bug#34529: Crash on complex Falcon I_S select after ALTER .. PARTITION BY When swapping out heap I_S tables to disk, this is done after plan refinement. Thus, READ_RECORD::file will still point to the (deleted) heap handler at start of execution. This causes segmentation fault if join buffering is used and the query is a star query where the result is found to be empty before accessing some table. In this case that table has not been initialized (i.e. had its READ_RECORD re-initialized) before the cleanup routine tries to close the handler. Fixed by updating READ_RECORD::file when changing handler. mysql-test/r/information_schema.result: Bug#34529: Test result. mysql-test/t/information_schema.test: Bug#34529: Test case. sql/sql_show.cc: Bug#34529: The fix. --- mysql-test/r/information_schema.result | 10 ++++++++++ mysql-test/t/information_schema.test | 21 +++++++++++++++++++++ sql/sql_show.cc | 2 ++ 3 files changed, 33 insertions(+) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 80f85aee429..2803c5af729 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1422,3 +1422,13 @@ show fields from information_schema.table_names; ERROR 42S02: Unknown table 'table_names' in information_schema show keys from information_schema.table_names; ERROR 42S02: Unknown table 'table_names' in information_schema +USE information_schema; +SET max_heap_table_size = 16384; +CREATE TABLE test.t1( a INT ); +SELECT * +FROM tables ta +JOIN collations co ON ( co.collation_name = ta.table_catalog ) +JOIN character_sets cs ON ( cs.character_set_name = ta.table_catalog ); +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN CHARACTER_SET_NAME DEFAULT_COLLATE_NAME DESCRIPTION MAXLEN +DROP TABLE test.t1; +SET max_heap_table_size = DEFAULT; diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 3d3310e389e..09005a4b145 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -1118,3 +1118,24 @@ show fields from information_schema.table_names; --error 1109 show keys from information_schema.table_names; +# +# Bug#34529: Crash on complex Falcon I_S select after ALTER .. PARTITION BY +# +USE information_schema; +SET max_heap_table_size = 16384; + +CREATE TABLE test.t1( a INT ); + +# What we need to create here is a bit of a corner case: +# We need a star query with information_schema tables, where the first +# branch of the star join produces zero rows, so that reading of the +# second branch never happens. At the same time we have to make sure +# that data for at least the last table is swapped from MEMORY/HEAP to +# MyISAM. This and only this triggers the bug. +SELECT * +FROM tables ta +JOIN collations co ON ( co.collation_name = ta.table_catalog ) +JOIN character_sets cs ON ( cs.character_set_name = ta.table_catalog ); + +DROP TABLE test.t1; +SET max_heap_table_size = DEFAULT; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 36d154181f8..a80319785bd 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -4073,9 +4073,11 @@ bool get_schema_tables_result(JOIN *join, { result= 1; join->error= 1; + tab->read_record.file= table_list->table->file; table_list->schema_table_state= executed_place; break; } + tab->read_record.file= table_list->table->file; table_list->schema_table_state= executed_place; } } From cebb6727b3c8593283f81182d06c45ca69cc0304 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Mar 2008 17:23:17 +0200 Subject: [PATCH 08/15] Bug #26461: Intrinsic data type bool (1 byte) redefined to BOOL (4 bytes) The bool data type was redefined to BOOL (4 bytes on windows). Removed the #define and fixed some of the warnings that were uncovered by this. Note that the fix also disables 2 warnings : 4800 : 'type' : forcing value to bool 'true' or 'false' (performance warning) 4805: 'operation' : unsafe mix of type 'type' and type 'type' in operation These warnings will be handled in a separate bug, as they are performance related or bogus. Fixed to int the return type of functions that return more than 2 distinct values. CMakeLists.txt: Bug #26461: disable the C4800 and C4805 warnings temporarily include/config-win.h: Bug #26461: - no need for this define for Windows. - windows C++ compilers have a bool type include/my_global.h: Bug #26461: removed bool_defined (no longer needed) sql/handler.h: Bug #26461: bool functions must return boolean values sql/mysql_priv.h: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/procedure.h: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_acl.cc: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_acl.h: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_analyse.cc: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_analyse.h: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_base.cc: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_db.cc: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_delete.cc: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_load.cc: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_parse.cc: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_prepare.cc: Bug #26461: fixed return type of functions that return more than 2 distinct values. sql/sql_update.cc: Bug #26461: fixed return type of functions that return more than 2 distinct values. --- CMakeLists.txt | 4 ++++ include/config-win.h | 4 +--- include/my_global.h | 2 +- sql/handler.h | 2 +- sql/mysql_priv.h | 14 +++++++------- sql/procedure.h | 2 +- sql/sql_acl.cc | 6 +++--- sql/sql_acl.h | 6 +++--- sql/sql_analyse.cc | 2 +- sql/sql_analyse.h | 2 +- sql/sql_base.cc | 2 +- sql/sql_db.cc | 2 +- sql/sql_delete.cc | 4 ++-- sql/sql_load.cc | 2 +- sql/sql_parse.cc | 4 ++-- sql/sql_prepare.cc | 6 +++--- sql/sql_update.cc | 2 +- 17 files changed, 34 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27b2bf9b70e..77c95e16a76 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,10 @@ SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DDBUG_OFF") SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDBUG_OFF") +#TODO: update the code and remove the disabled warnings +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4800 /wd4805") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4800 /wd4805") + IF(CMAKE_GENERATOR MATCHES "Visual Studio 8") SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4996") SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /wd4996") diff --git a/include/config-win.h b/include/config-win.h index 45bfeb5ba26..c9c25d44691 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -157,14 +157,12 @@ typedef uint rf_SetTimer; #define Socket_defined #define my_socket SOCKET -#define bool BOOL #define SIGPIPE SIGINT #define RETQSORTTYPE void #define QSORT_TYPE_IS_VOID #define RETSIGTYPE void #define SOCKET_SIZE_TYPE int #define my_socket_defined -#define bool_defined #define byte_defined #define HUGE_PTR #define STDCALL __stdcall /* Used by libmysql.dll */ @@ -457,4 +455,4 @@ inline double ulonglong2double(ulonglong value) #define HAVE_CHARSET_ujis 1 #define HAVE_CHARSET_utf8 1 #define HAVE_UCA_COLLATIONS 1 - +#define HAVE_BOOL 1 diff --git a/include/my_global.h b/include/my_global.h index 08877300d8a..f0f33a7de8b 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -980,7 +980,7 @@ typedef int myf; /* Type of MyFlags in my_funcs */ typedef char byte; /* Smallest addressable unit */ #endif typedef char my_bool; /* Small bool */ -#if !defined(bool) && !defined(bool_defined) && (!defined(HAVE_BOOL) || !defined(__cplusplus)) +#if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus)) typedef char bool; /* Ordinary boolean values 0 1 */ #endif /* Macros for converting *constants* to the right type */ diff --git a/sql/handler.h b/sql/handler.h index 74c09d2d9ee..aa3377c3868 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -815,7 +815,7 @@ public: { return HA_ADMIN_NOT_IMPLEMENTED; } /* end of the list of admin commands */ - virtual bool check_and_repair(THD *thd) { return HA_ERR_WRONG_COMMAND; } + virtual bool check_and_repair(THD *thd) { return TRUE; } virtual int dump(THD* thd, int fd = -1) { return HA_ERR_WRONG_COMMAND; } virtual int disable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; } virtual int enable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; } diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 59ec18e1a3d..0b488900ac5 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -597,8 +597,8 @@ bool check_merge_table_access(THD *thd, char *db, bool check_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc); bool multi_update_precheck(THD *thd, TABLE_LIST *tables); bool multi_delete_precheck(THD *thd, TABLE_LIST *tables); -bool mysql_multi_update_prepare(THD *thd); -bool mysql_multi_delete_prepare(THD *thd); +int mysql_multi_update_prepare(THD *thd); +int mysql_multi_delete_prepare(THD *thd); bool mysql_insert_select_prepare(THD *thd); bool update_precheck(THD *thd, TABLE_LIST *tables); bool delete_precheck(THD *thd, TABLE_LIST *tables); @@ -691,7 +691,7 @@ struct Query_cache_query_flags uint build_table_path(char *buff, size_t bufflen, const char *db, const char *table, const char *ext); -bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent); +int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent); bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create); bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent); void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags); @@ -731,7 +731,7 @@ pthread_handler_t handle_one_connection(void *arg); pthread_handler_t handle_bootstrap(void *arg); void end_thread(THD *thd,bool put_in_cache); void flush_thread_cache(); -bool mysql_execute_command(THD *thd); +int mysql_execute_command(THD *thd); bool dispatch_command(enum enum_server_command command, THD *thd, char* packet, uint packet_length); void log_slow_statement(THD *thd); @@ -862,7 +862,7 @@ void prepare_triggers_for_insert_stmt(THD *thd, TABLE *table, enum_duplicates duplic); void mark_fields_used_by_triggers_for_insert_stmt(THD *thd, TABLE *table, enum_duplicates duplic); -bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds); +int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds); bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order, ha_rows rows, ulonglong options, bool reset_auto_increment); @@ -1106,7 +1106,7 @@ int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order); void wait_for_refresh(THD *thd); int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags); int simple_open_n_lock_tables(THD *thd,TABLE_LIST *tables); -bool open_and_lock_tables(THD *thd,TABLE_LIST *tables); +int open_and_lock_tables(THD *thd,TABLE_LIST *tables); bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags); int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen); TABLE *open_temporary_table(THD *thd, const char *path, const char *db, @@ -1177,7 +1177,7 @@ inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table, bool eval_const_cond(COND *cond); /* sql_load.cc */ -bool mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, +int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, List &fields_vars, List &set_fields, List &set_values_list, enum enum_duplicates handle_duplicates, bool ignore, diff --git a/sql/procedure.h b/sql/procedure.h index 850d5c74db4..f1fb433a6ee 100644 --- a/sql/procedure.h +++ b/sql/procedure.h @@ -144,7 +144,7 @@ public: virtual int send_row(List &fields)=0; virtual bool change_columns(List &fields)=0; virtual void update_refs(void) {} - virtual bool end_of_records() { return 0; } + virtual int end_of_records() { return 0; } }; Procedure *setup_procedure(THD *thd,ORDER *proc_param,select_result *result, diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index e9504f423ad..e773f754e18 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1382,7 +1382,7 @@ bool acl_check_host(const char *host, const char *ip) 1 ERROR ; In this case the error is sent to the client. */ -bool check_change_password(THD *thd, const char *host, const char *user, +int check_change_password(THD *thd, const char *host, const char *user, char *new_password, uint new_password_len) { if (!initialized) @@ -2763,7 +2763,7 @@ table_error: TRUE error */ -bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, +int mysql_table_grant(THD *thd, TABLE_LIST *table_list, List &user_list, List &columns, ulong rights, bool revoke_grant) @@ -5805,7 +5805,7 @@ bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name, < 0 Error. Error message not yet sent. */ -bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, +int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, bool is_proc) { Security_context *sctx= thd->security_ctx; diff --git a/sql/sql_acl.h b/sql/sql_acl.h index b2007ccdf47..1efcd2e3b6b 100644 --- a/sql/sql_acl.h +++ b/sql/sql_acl.h @@ -183,13 +183,13 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, const char *passwd, bool acl_getroot_no_password(Security_context *sctx, char *user, char *host, char *ip, char *db); bool acl_check_host(const char *host, const char *ip); -bool check_change_password(THD *thd, const char *host, const char *user, +int check_change_password(THD *thd, const char *host, const char *user, char *password, uint password_len); bool change_password(THD *thd, const char *host, const char *user, char *password); bool mysql_grant(THD *thd, const char *db, List &user_list, ulong rights, bool revoke); -bool mysql_table_grant(THD *thd, TABLE_LIST *table, List &user_list, +int mysql_table_grant(THD *thd, TABLE_LIST *table, List &user_list, List &column_list, ulong rights, bool revoke); bool mysql_routine_grant(THD *thd, TABLE_LIST *table, bool is_proc, @@ -225,7 +225,7 @@ void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant, const char *db, const char *table); bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name, bool is_proc); -bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, +int sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, bool is_proc); bool check_routine_level_acl(THD *thd, const char *db, const char *name, bool is_proc); diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index 95a7fb3d34d..2e90d00f8aa 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -683,7 +683,7 @@ int analyse::send_row(List &field_list __attribute__((unused))) } // analyse::send_row -bool analyse::end_of_records() +int analyse::end_of_records() { field_info **f = f_info; char buff[MAX_FIELD_WIDTH]; diff --git a/sql/sql_analyse.h b/sql/sql_analyse.h index 21a37209e89..2a4226b2d95 100644 --- a/sql/sql_analyse.h +++ b/sql/sql_analyse.h @@ -350,7 +350,7 @@ public: virtual bool change_columns(List &fields); virtual int send_row(List &fields); virtual void end_group(void) {} - virtual bool end_of_records(void); + virtual int end_of_records(void); friend Procedure *proc_analyse_init(THD *thd, ORDER *param, select_result *result, List &field_list); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index c9f20b3d71b..533b0070fee 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3046,7 +3046,7 @@ int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables) The lock will automaticaly be freed by close_thread_tables() */ -bool open_and_lock_tables(THD *thd, TABLE_LIST *tables) +int open_and_lock_tables(THD *thd, TABLE_LIST *tables) { uint counter; bool need_reopen; diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 91b0c02d23b..e25ede1be03 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -449,7 +449,7 @@ bool load_db_opt_by_name(THD *thd, const char *db_name, */ -bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, +int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, bool silent) { char path[FN_REFLEN+16]; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index a28a39a769d..af895c172ff 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -370,7 +370,7 @@ cleanup: FALSE OK TRUE error */ -bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) +int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) { Item *fake_conds= 0; SELECT_LEX *select_lex= &thd->lex->select_lex; @@ -433,7 +433,7 @@ extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b) TRUE Error */ -bool mysql_multi_delete_prepare(THD *thd) +int mysql_multi_delete_prepare(THD *thd) { LEX *lex= thd->lex; TABLE_LIST *aux_tables= (TABLE_LIST *)lex->auxiliary_table_list.first; diff --git a/sql/sql_load.cc b/sql/sql_load.cc index d687ceff393..4da3c19bb3c 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -110,7 +110,7 @@ static bool write_execute_load_query_log_event(THD *thd, TRUE - error / FALSE - success */ -bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, +int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, List &fields_vars, List &set_fields, List &set_values, enum enum_duplicates handle_duplicates, bool ignore, diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 8bdbd812529..98e04e45bdd 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2500,10 +2500,10 @@ static void reset_one_shot_variables(THD *thd) TRUE Error */ -bool +int mysql_execute_command(THD *thd) { - bool res= FALSE; + int res= FALSE; bool need_start_waiting= FALSE; // have protection against global read lock int up_result= 0; LEX *lex= thd->lex; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 18cfd8d7dfc..220b9a0bcd8 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1403,7 +1403,7 @@ error: */ static bool select_like_stmt_test(Prepared_statement *stmt, - bool (*specific_prepare)(THD *thd), + int (*specific_prepare)(THD *thd), ulong setup_tables_done_option) { DBUG_ENTER("select_like_stmt_test"); @@ -1441,7 +1441,7 @@ static bool select_like_stmt_test(Prepared_statement *stmt, static bool select_like_stmt_test_with_open_n_lock(Prepared_statement *stmt, TABLE_LIST *tables, - bool (*specific_prepare)(THD *thd), + int (*specific_prepare)(THD *thd), ulong setup_tables_done_option) { DBUG_ENTER("select_like_stmt_test_with_open_n_lock"); @@ -1630,7 +1630,7 @@ error: because mysql_handle_derived uses local tables lists. */ -static bool mysql_insert_select_prepare_tester(THD *thd) +static int mysql_insert_select_prepare_tester(THD *thd) { SELECT_LEX *first_select= &thd->lex->select_lex; TABLE_LIST *second_table= ((TABLE_LIST*)first_select->table_list.first)-> diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 84349a40977..541704cfaf1 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -716,7 +716,7 @@ static table_map get_table_map(List *items) TRUE Error */ -bool mysql_multi_update_prepare(THD *thd) +int mysql_multi_update_prepare(THD *thd) { LEX *lex= thd->lex; TABLE_LIST *table_list= lex->query_tables; From 194e43ee68e9f1acb9d1ef380894c4fc4c27f22e Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Mar 2008 12:08:04 -0600 Subject: [PATCH 09/15] Bug#8759 (Stored Procedures: SQLSTATE '00000' should be illegal) Fixed the parser to reject SQLSTATE '00000', since '00000' is the successful completion condition, and can not be caught by an exception handler in SQL. mysql-test/r/sp-error.result: Bug#8759 (Stored Procedures: SQLSTATE '00000' should be illegal) mysql-test/t/sp-error.test: Bug#8759 (Stored Procedures: SQLSTATE '00000' should be illegal) sql/sp_pcontext.cc: Bug#8759 (Stored Procedures: SQLSTATE '00000' should be illegal) --- mysql-test/r/sp-error.result | 12 ++++++++++++ mysql-test/t/sp-error.test | 26 ++++++++++++++++++++++++++ sql/sp_pcontext.cc | 2 ++ 3 files changed, 40 insertions(+) diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index bc2ab13fe5f..5ac61821cea 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -1638,3 +1638,15 @@ Warning 1287 The syntax 'TYPE=storage_engine' is deprecated and will be removed call p1(); call p1(); drop procedure p1; +drop procedure if exists proc_8759; +create procedure proc_8759() +begin +declare should_be_illegal condition for sqlstate '00000'; +declare continue handler for should_be_illegal set @x=0; +end$$ +ERROR 42000: Bad SQLSTATE: '00000' +create procedure proc_8759() +begin +declare continue handler for sqlstate '00000' set @x=0; +end$$ +ERROR 42000: Bad SQLSTATE: '00000' diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index 23bce3805af..6896a1ab832 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -2386,6 +2386,32 @@ call p1(); call p1(); drop procedure p1; +# +# Bug#8759 (Stored Procedures: SQLSTATE '00000' should be illegal) +# + +--disable_warnings +drop procedure if exists proc_8759; +--enable_warnings + +delimiter $$; + +--error ER_SP_BAD_SQLSTATE +create procedure proc_8759() +begin + declare should_be_illegal condition for sqlstate '00000'; + declare continue handler for should_be_illegal set @x=0; +end$$ + +--error ER_SP_BAD_SQLSTATE +create procedure proc_8759() +begin + declare continue handler for sqlstate '00000' set @x=0; +end$$ + +delimiter ;$$ + + # # BUG#NNNN: New bug synopsis # diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc index 8babbd52ff6..414ea12cd7a 100644 --- a/sql/sp_pcontext.cc +++ b/sql/sp_pcontext.cc @@ -51,6 +51,8 @@ sp_cond_check(LEX_STRING *sqlstate) (c < 'A' || 'Z' < c)) return FALSE; } + if (strcmp(sqlstate->str, "00000") == 0) + return FALSE; return TRUE; } From 7bcbc7f2d5078d308c25f7d1c92995c64af7b8bc Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 23 Mar 2008 14:29:35 +0200 Subject: [PATCH 10/15] merge bug 26461 to 5.1-opt --- sql/handler.h | 2 +- sql/log.cc | 2 +- sql/sql_table.cc | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sql/handler.h b/sql/handler.h index 9800f4974c3..a3743c78f34 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1883,7 +1883,7 @@ private: { return HA_ADMIN_NOT_IMPLEMENTED; } virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt) { return HA_ADMIN_NOT_IMPLEMENTED; } - virtual bool check_and_repair(THD *thd) { return HA_ERR_WRONG_COMMAND; } + virtual bool check_and_repair(THD *thd) { return TRUE; } virtual int disable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; } virtual int enable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; } virtual int discard_or_import_tablespace(my_bool discard) diff --git a/sql/log.cc b/sql/log.cc index c2e0c85acfe..67438da6008 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1005,7 +1005,7 @@ bool LOGGER::general_log_write(THD *thd, enum enum_server_command command, current_time= my_time(0); while (*current_handler) - error+= (*current_handler++)-> + error|= (*current_handler++)-> log_general(thd, current_time, user_host_buff, user_host_len, id, command_name[(uint) command].str, diff --git a/sql/sql_table.cc b/sql/sql_table.cc index c62d0545fda..2baf26f5953 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -42,7 +42,7 @@ static int copy_data_between_tables(TABLE *from,TABLE *to, static bool prepare_blob_field(THD *thd, Create_field *sql_field); static bool check_engine(THD *, const char *, HA_CREATE_INFO *); -static bool +static int mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, Alter_info *alter_info, bool tmp_table, @@ -2173,7 +2173,7 @@ int prepare_create_field(Create_field *sql_field, TRUE error */ -static bool +static int mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, Alter_info *alter_info, bool tmp_table, From d62c9e33ca09125a66f226bf7817dc466a547e91 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Mar 2008 19:44:27 +0400 Subject: [PATCH 11/15] information_schema.test, information_schema.result: Minor test case cleanup after bug#34529. mysql-test/r/information_schema.result: Minor test case cleanup after bug#34529. mysql-test/t/information_schema.test: Minor test case cleanup after bug#34529. --- mysql-test/r/information_schema.result | 3 ++- mysql-test/t/information_schema.test | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 2803c5af729..d7ff87bd1eb 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1417,7 +1417,6 @@ select * from `information_schema`.`VIEWS` where `TABLE_SCHEMA` = NULL; TABLE_CATALOG TABLE_SCHEMA TABLE_NAME VIEW_DEFINITION CHECK_OPTION IS_UPDATABLE DEFINER SECURITY_TYPE select * from `information_schema`.`VIEWS` where `TABLE_NAME` = NULL; TABLE_CATALOG TABLE_SCHEMA TABLE_NAME VIEW_DEFINITION CHECK_OPTION IS_UPDATABLE DEFINER SECURITY_TYPE -End of 5.0 tests. show fields from information_schema.table_names; ERROR 42S02: Unknown table 'table_names' in information_schema show keys from information_schema.table_names; @@ -1432,3 +1431,5 @@ JOIN character_sets cs ON ( cs.character_set_name = ta.table_catalog ); TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN CHARACTER_SET_NAME DEFAULT_COLLATE_NAME DESCRIPTION MAXLEN DROP TABLE test.t1; SET max_heap_table_size = DEFAULT; +USE test; +End of 5.0 tests. diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 09005a4b145..caf38945cbc 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -1108,8 +1108,6 @@ select * from `information_schema`.`TRIGGERS` where `EVENT_OBJECT_TABLE` = NULL; select * from `information_schema`.`VIEWS` where `TABLE_SCHEMA` = NULL; select * from `information_schema`.`VIEWS` where `TABLE_NAME` = NULL; ---echo End of 5.0 tests. - # # Bug#30079 A check for "hidden" I_S tables is flawed # @@ -1139,3 +1137,7 @@ JOIN character_sets cs ON ( cs.character_set_name = ta.table_catalog ); DROP TABLE test.t1; SET max_heap_table_size = DEFAULT; +USE test; + +--echo End of 5.0 tests. + From 18801aa8298bfe20a397ec36dd3d72fda694fece Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Mar 2008 11:20:11 -0600 Subject: [PATCH 12/15] Bug#20906 (Multiple assignments in SET in stored routine produce incorrect instructions) This bug can not be reproduced in the current version, adding the test case to the test suite for coverage, no code change. mysql-test/r/sp-code.result: Bug#20906 (Multiple assignments in SET in stored routine produce incorrect instructions) mysql-test/t/sp-code.test: Bug#20906 (Multiple assignments in SET in stored routine produce incorrect instructions) --- mysql-test/r/sp-code.result | 28 ++++++++++++++++++++++++++++ mysql-test/t/sp-code.test | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/mysql-test/r/sp-code.result b/mysql-test/r/sp-code.result index 855cabc25d8..2848306b442 100644 --- a/mysql-test/r/sp-code.result +++ b/mysql-test/r/sp-code.result @@ -842,4 +842,32 @@ Pos Instruction 21 jump 3 drop procedure proc_33618_h; drop procedure proc_33618_c; +drop procedure if exists p_20906_a; +drop procedure if exists p_20906_b; +create procedure p_20906_a() SET @a=@a+1, @b=@b+1; +show procedure code p_20906_a; +Pos Instruction +0 stmt 32 "SET @a=@a+1" +1 stmt 32 "SET @b=@b+1" +set @a=1; +set @b=1; +call p_20906_a(); +select @a, @b; +@a @b +2 2 +create procedure p_20906_b() SET @a=@a+1, @b=@b+1, @c=@c+1; +show procedure code p_20906_b; +Pos Instruction +0 stmt 32 "SET @a=@a+1" +1 stmt 32 "SET @b=@b+1" +2 stmt 32 "SET @c=@c+1" +set @a=1; +set @b=1; +set @c=1; +call p_20906_b(); +select @a, @b, @c; +@a @b @c +2 2 2 +drop procedure p_20906_a; +drop procedure p_20906_b; End of 5.0 tests. diff --git a/mysql-test/t/sp-code.test b/mysql-test/t/sp-code.test index 751282c895a..a76863dd5fa 100644 --- a/mysql-test/t/sp-code.test +++ b/mysql-test/t/sp-code.test @@ -598,4 +598,36 @@ show procedure code proc_33618_c; drop procedure proc_33618_h; drop procedure proc_33618_c; +# +# Bug#20906 (Multiple assignments in SET in stored routine produce incorrect +# instructions) +# + +--disable_warnings +drop procedure if exists p_20906_a; +drop procedure if exists p_20906_b; +--enable_warnings + +create procedure p_20906_a() SET @a=@a+1, @b=@b+1; +show procedure code p_20906_a; + +set @a=1; +set @b=1; + +call p_20906_a(); +select @a, @b; + +create procedure p_20906_b() SET @a=@a+1, @b=@b+1, @c=@c+1; +show procedure code p_20906_b; + +set @a=1; +set @b=1; +set @c=1; + +call p_20906_b(); +select @a, @b, @c; + +drop procedure p_20906_a; +drop procedure p_20906_b; + --echo End of 5.0 tests. From a1d5a59c2af6e031995add81c68e839b2213fa45 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Mar 2008 17:48:05 -0600 Subject: [PATCH 13/15] Manual merge mysql-test/r/sp-code.result: manual merge, adjust test results --- mysql-test/r/sp-code.result | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/sp-code.result b/mysql-test/r/sp-code.result index 7706f18b171..39770dc4f2a 100644 --- a/mysql-test/r/sp-code.result +++ b/mysql-test/r/sp-code.result @@ -847,8 +847,8 @@ drop procedure if exists p_20906_b; create procedure p_20906_a() SET @a=@a+1, @b=@b+1; show procedure code p_20906_a; Pos Instruction -0 stmt 32 "SET @a=@a+1" -1 stmt 32 "SET @b=@b+1" +0 stmt 31 "SET @a=@a+1" +1 stmt 31 "SET @b=@b+1" set @a=1; set @b=1; call p_20906_a(); @@ -858,9 +858,9 @@ select @a, @b; create procedure p_20906_b() SET @a=@a+1, @b=@b+1, @c=@c+1; show procedure code p_20906_b; Pos Instruction -0 stmt 32 "SET @a=@a+1" -1 stmt 32 "SET @b=@b+1" -2 stmt 32 "SET @c=@c+1" +0 stmt 31 "SET @a=@a+1" +1 stmt 31 "SET @b=@b+1" +2 stmt 31 "SET @c=@c+1" set @a=1; set @b=1; set @c=1; From 0b8342ba4e3c0426569f3256a8d951e168a7d52d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 26 Mar 2008 22:43:12 +0400 Subject: [PATCH 14/15] Fixed bug #35193. View definition as SELECT ... FROM DUAL WHERE ... has valid syntax, but use of such view in SELECT or SHOW CREATE VIEW syntax causes unexpected syntax error. Server omits FROM DUAL clause when storing view body string in a .frm file for further evaluation. However, syntax of SELECT-witout-FROM query is more restrictive than SELECT FROM DUAL syntax, and doesn't allow the WHERE clause. NOTE: this syntax difference is not documented. View registration procedure has been modified to preserve original structure of view's body. mysql-test/r/view.result: Added test case for bug #35193. mysql-test/t/view.test: Added test case for bug #35193. sql/sql_select.cc: Fixed bug #35193. The st_select_lex::print function always omits FROM DUAL clause, even if original SELECT query has the WHERE clause. The mysql_register_view function uses this function to reconstruct a body of view's AS clause for further evaluation and stores that reconstructed clause in a .frm file. SELECT without FROM syntax is more restrictive than SELECT FROM DUAL syntax: second one allows the WHERE clause, but first one is not. Use of this view in SELECT or SHOW CREATE VIEW queries causes unexpected syntax errors. The st_select_lex::print function has been modified to reconstruct FROM DUAL clause in queries when needed. TODO: Syntax difference is not documented and should be eliminated, however improvement of the SELECT-without-FROM syntax is not trivial and leads to significant modification of grammar file because of additional shift/reduce conflicts. --- mysql-test/r/view.result | 18 ++++++++++++++++++ mysql-test/t/view.test | 23 +++++++++++++++++++++++ sql/sql_select.cc | 8 ++++++++ 3 files changed, 49 insertions(+) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 520bf9426b8..eb7a89c3d12 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3659,6 +3659,24 @@ DROP TABLE t1; # -- End of test case for Bug#34337. +# ----------------------------------------------------------------- +# -- Bug#35193: VIEW query is rewritten without "FROM DUAL", +# -- causing syntax error +# ----------------------------------------------------------------- + +CREATE VIEW v1 AS SELECT 1 FROM DUAL WHERE 1; + +SELECT * FROM v1; +1 +1 +SHOW CREATE TABLE v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `1` from DUAL where 1 + +DROP VIEW v1; + +# -- End of test case for Bug#35193. + # ----------------------------------------------------------------- # -- End of 5.0 tests. # ----------------------------------------------------------------- diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 23e64b0546f..9fa981ccb9a 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -3537,6 +3537,29 @@ DROP TABLE t1; ########################################################################### +--echo # ----------------------------------------------------------------- +--echo # -- Bug#35193: VIEW query is rewritten without "FROM DUAL", +--echo # -- causing syntax error +--echo # ----------------------------------------------------------------- +--echo + +CREATE VIEW v1 AS SELECT 1 FROM DUAL WHERE 1; + +--echo + +SELECT * FROM v1; +SHOW CREATE TABLE v1; + +--echo + +DROP VIEW v1; + +--echo +--echo # -- End of test case for Bug#35193. +--echo + +########################################################################### + --echo # ----------------------------------------------------------------- --echo # -- End of 5.0 tests. --echo # ----------------------------------------------------------------- diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6392f7c4299..bb3030a721c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -15806,6 +15806,14 @@ void st_select_lex::print(THD *thd, String *str) /* go through join tree */ print_join(thd, str, &top_join_list); } + else if (where) + { + /* + "SELECT 1 FROM DUAL WHERE 2" should not be printed as + "SELECT 1 WHERE 2": the 1st syntax is valid, but the 2nd is not. + */ + str->append(STRING_WITH_LEN(" from DUAL ")); + } // Where Item *cur_where= where; From b90296c70ac526be823d76ffdb2ef2e8cac87179 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Mar 2008 00:55:13 +0400 Subject: [PATCH 15/15] view.result: Post-merge fix (bug #35193). mysql-test/r/view.result: Post-merge fix (bug #35193). --- mysql-test/r/view.result | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 0810b6d9bf1..a0af9fdcf1d 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3665,8 +3665,8 @@ SELECT * FROM v1; 1 1 SHOW CREATE TABLE v1; -View Create View -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `1` from DUAL where 1 +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `1` from DUAL where 1 latin1 latin1_swedish_ci DROP VIEW v1;