From 89d044062c1daa3f12358b003478cbaa5df91e3b Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Thu, 27 Nov 2008 17:57:34 +0400 Subject: [PATCH 1/4] Bug#37460 Assertion failed: !table->file || table->file->inited == handler::NONE enable uncacheable flag if we update a view with check option and check option has a subselect, otherwise, the check option can be evaluated after the subselect was freed as independent (See full_local in JOIN::join_free()) mysql-test/r/subselect.result: test result mysql-test/t/subselect.test: test case sql/mysql_priv.h: added UNCACHEABLE_CHECKOPTION flag sql/sql_update.cc: enable uncacheable flag if we update a view with check option and check option has a subselect, otherwise, the check option can be evaluated after the subselect was freed as independent (See full_local in JOIN::join_free()) --- mysql-test/r/subselect.result | 30 ++++++++++++++++++++++++++++++ mysql-test/t/subselect.test | 35 +++++++++++++++++++++++++++++++++++ sql/mysql_priv.h | 1 + sql/sql_update.cc | 26 ++++++++++++++++++++++++++ 4 files changed, 92 insertions(+) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 6eeb652e3c1..8830ea11f97 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -4422,4 +4422,34 @@ id 2 3 DROP TABLE t1, t2; +CREATE TABLE t1 (id int); +CREATE TABLE t2 (id int, c int); +INSERT INTO t1 (id) VALUES (1); +INSERT INTO t2 (id) VALUES (1); +INSERT INTO t1 (id) VALUES (1); +INSERT INTO t2 (id) VALUES (1); +CREATE VIEW v1 AS +SELECT t2.c AS c FROM t1, t2 +WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; +UPDATE v1 SET c=1; +CREATE VIEW v2 (a,b) AS +SELECT t2.id, t2.c AS c FROM t1, t2 +WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; +INSERT INTO v2(a,b) VALUES (2,2); +ERROR HY000: CHECK OPTION failed 'test.v2' +INSERT INTO v2(a,b) VALUES (1,2); +SELECT * FROM v1; +c +1 +1 +1 +1 +2 +2 +CREATE VIEW v3 AS +SELECT t2.c AS c FROM t2 +WHERE 1 IN (SELECT id FROM t1) WITH CHECK OPTION; +DELETE FROM v3; +DROP VIEW v1,v2,v3; +DROP TABLE t1,t2; End of 5.0 tests. diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index d28e31fb545..ea911e4912d 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -3325,4 +3325,39 @@ INSERT INTO t2 VALUES (2,1),(3,1); SELECT * FROM t1 i WHERE 1 IN (SELECT l.id2 FROM t2 l WHERE i.id=l.id1); DROP TABLE t1, t2; +# +# Bug#37460 Assertion failed: +# !table->file || table->file->inited == handler::NONE +# +CREATE TABLE t1 (id int); +CREATE TABLE t2 (id int, c int); + +INSERT INTO t1 (id) VALUES (1); +INSERT INTO t2 (id) VALUES (1); +INSERT INTO t1 (id) VALUES (1); +INSERT INTO t2 (id) VALUES (1); + +CREATE VIEW v1 AS + SELECT t2.c AS c FROM t1, t2 + WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; +UPDATE v1 SET c=1; + +CREATE VIEW v2 (a,b) AS + SELECT t2.id, t2.c AS c FROM t1, t2 + WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; + +--error 1369 +INSERT INTO v2(a,b) VALUES (2,2); +INSERT INTO v2(a,b) VALUES (1,2); +SELECT * FROM v1; + +CREATE VIEW v3 AS + SELECT t2.c AS c FROM t2 + WHERE 1 IN (SELECT id FROM t1) WITH CHECK OPTION; + +DELETE FROM v3; + +DROP VIEW v1,v2,v3; +DROP TABLE t1,t2; + --echo End of 5.0 tests. diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 1568f042b7e..75c95834ac9 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -435,6 +435,7 @@ MY_LOCALE *my_locale_by_number(uint number); #define UNCACHEABLE_PREPARE 16 /* For uncorrelated SELECT in an UNION with some correlated SELECTs */ #define UNCACHEABLE_UNITED 32 +#define UNCACHEABLE_CHECKOPTION 64 /* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */ #define UNDEF_POS (-1) diff --git a/sql/sql_update.cc b/sql/sql_update.cc index eb4e9b7ed73..f15db220a3b 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1249,6 +1249,32 @@ multi_update::initialize_tables(JOIN *join) } } + /* + enable uncacheable flag if we update a view with check option + and check option has a subselect, otherwise, the check option + can be evaluated after the subselect was freed as independent + (See full_local in JOIN::join_free()). + */ + if (table_ref->check_option && !join->select_lex->uncacheable) + { + SELECT_LEX_UNIT *tmp_unit; + SELECT_LEX *sl; + for (tmp_unit= join->select_lex->first_inner_unit(); + tmp_unit; + tmp_unit= tmp_unit->next_unit()) + { + for (sl= tmp_unit->first_select(); sl; sl= sl->next_select()) + { + if (sl->master_unit()->item) + { + join->select_lex->uncacheable|= UNCACHEABLE_CHECKOPTION; + goto loop_end; + } + } + } + } +loop_end: + if (table == first_table_for_update && table_ref->check_option) { table_map unupdated_tables= table_ref->check_option->used_tables() & From 3a3d3527a333f83eb454efa8fd1e7f34e06b578c Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Thu, 27 Nov 2008 18:26:22 +0400 Subject: [PATCH 2/4] removed unused variable --- tests/mysql_client_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index a9ec7eb358a..ee3a053f8bd 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -16220,7 +16220,7 @@ static void test_bug38486(void) static void test_bug40365(void) { - uint rc, i, count= 1; + uint rc, i; MYSQL_STMT *stmt= 0; MYSQL_BIND my_bind[2]; my_bool is_null[2]= {0}; From 5cd6c9428931348c7b4f473a0b55a89ff8df4153 Mon Sep 17 00:00:00 2001 From: Horst Hunger Date: Thu, 27 Nov 2008 15:51:48 +0100 Subject: [PATCH 3/4] Fix for Bug#37766: Inserted review results. Reason for the failing test was that "SELECT count(*) from mysql.general_log;" was not always the same number. That was fixed by "...count(*)>4..." as the minimal fulfilled condition. As Bug 35371 was fixed the testcase with "log_output = 'FILE'" was enabled and changed to have always the same result. --- mysql-test/r/log_output_func.result | 38 +++++++++------ mysql-test/t/log_output_func.test | 75 +++++++++++++++++------------ 2 files changed, 66 insertions(+), 47 deletions(-) diff --git a/mysql-test/r/log_output_func.result b/mysql-test/r/log_output_func.result index 8af7f471195..060f930a161 100644 --- a/mysql-test/r/log_output_func.result +++ b/mysql-test/r/log_output_func.result @@ -1,13 +1,11 @@ +SET @start_value= @@global.log_output; +SET @start_general_log= @@global.general_log; +SET @start_general_log_file= @@global.general_log_file; '#--------------------FN_DYNVARS_065_01-------------------------#' SET @@global.log_output = 'NONE'; 'connect (con1,localhost,root,,,,)' -'connection con1' -SELECT @@global.log_output; -@@global.log_output -NONE SET @@global.log_output = 'TABLE,FILE'; 'connect (con2,localhost,root,,,,)' -'connection con2' SELECT @@global.log_output; @@global.log_output FILE,TABLE @@ -18,7 +16,7 @@ SET @@global.log_output = 'NONE'; TRUNCATE TABLE mysql.general_log; DROP TABLE IF EXISTS t1; CREATE TABLE t1(a INT); -INSERT INTO t1 value(1); +INSERT INTO t1 VALUE(1); SELECT 'abc'; abc abc @@ -29,25 +27,33 @@ count(*) SET @@global.log_output = 'TABLE'; TRUNCATE TABLE mysql.general_log; DROP TABLE IF EXISTS t1; -create table t1(a int); -INSERT INTO t1 value(1); +CREATE TABLE t1(a int); +INSERT INTO t1 VALUE(1); SELECT 'abc'; abc abc -SELECT count(*) from mysql.general_log; -count(*) -5 -'Bug#35371: Changing general_log file is crashing server' -'SET @@global.general_log_file = @log_file;' +SELECT count(*)>4 FROM mysql.general_log; +count(*)>4 +1 +SET @@global.general_log = 'OFF'; +FLUSH LOGS; +SET @@global.general_log_file = 'MYSQLTEST_VARDIR/run/mytest.log'; +SET @@global.general_log = 'ON'; SET @@global.log_output = 'FILE'; TRUNCATE TABLE mysql.general_log; DROP TABLE IF EXISTS t1; -create table t1(a int); -INSERT INTO t1 value(1); +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUE(1); SELECT 'abc'; abc abc -SELECT count(*) from mysql.general_log; +SELECT count(*) FROM mysql.general_log; count(*) 0 DROP TABLE t1; +connection default; +SET @@global.general_log= 'OFF'; +SET @@global.general_log_file= @start_general_log_file; +SET @@global.log_output= @start_value; +SET @@global.general_log= @start_general_log; +SET @@global.general_log= 'ON'; diff --git a/mysql-test/t/log_output_func.test b/mysql-test/t/log_output_func.test index 32026d8de59..007c4f38659 100644 --- a/mysql-test/t/log_output_func.test +++ b/mysql-test/t/log_output_func.test @@ -10,12 +10,13 @@ # # # Creation Date: 2008-03-08 # # Author: Rizwan # +# Modified: HHunger 2008-08-29 # # # Description: Test Cases of Dynamic System Variable log_output # # that checks the behavior of this variable # # # -# Reference: http://dev.mysql.com/doc/refman/5.1/en/ # -# server-system-variables.html # +# Reference: # +# http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html # # # ############################################################################### @@ -23,6 +24,10 @@ # ps-protocol. So, it is switched off. --disable_ps_protocol +SET @start_value= @@global.log_output; +SET @start_general_log= @@global.general_log; +SET @start_general_log_file= @@global.general_log_file; + --echo '#--------------------FN_DYNVARS_065_01-------------------------#' ################################################################## # Check if setting log_output is changed in every new connection # @@ -32,17 +37,12 @@ SET @@global.log_output = 'NONE'; # con1 will be default connection from now on --echo 'connect (con1,localhost,root,,,,)' connect (con1,localhost,root,,,,); ---echo 'connection con1' -connection con1; -SELECT @@global.log_output; SET @@global.log_output = 'TABLE,FILE'; + +# Test that the effect is global --echo 'connect (con2,localhost,root,,,,)' connect (con2,localhost,root,,,,); ---echo 'connection con2' -connection con2; SELECT @@global.log_output; -disconnect con2; - --echo '#--------------------FN_DYNVARS_065_02-------------------------#' #################################################### @@ -52,10 +52,9 @@ disconnect con2; --echo 'connection con1' connection con1; - -#======================================================================= +#=============================================================== --echo '---Checking general_log when log_output is NONE---' -#======================================================================= +#=============================================================== SET @@global.log_output = 'NONE'; TRUNCATE TABLE mysql.general_log; @@ -64,13 +63,13 @@ TRUNCATE TABLE mysql.general_log; DROP TABLE IF EXISTS t1; --enable_warnings CREATE TABLE t1(a INT); -INSERT INTO t1 value(1); +INSERT INTO t1 VALUE(1); SELECT 'abc'; SELECT count(*) FROM mysql.general_log; -#============================================================================== +#=============================================================== --echo '---Checking general_log when log_output is TABLE---' -#============================================================================== +#=============================================================== SET @@global.log_output = 'TABLE'; TRUNCATE TABLE mysql.general_log; @@ -78,35 +77,49 @@ TRUNCATE TABLE mysql.general_log; --disable_warnings DROP TABLE IF EXISTS t1; --enable_warnings -create table t1(a int); -INSERT INTO t1 value(1); +CREATE TABLE t1(a int); +INSERT INTO t1 VALUE(1); SELECT 'abc'; -SELECT count(*) from mysql.general_log; +# At least the last 4 statement should be logged. +SELECT count(*)>4 FROM mysql.general_log; -#=========================================================== +#=============================================================== # Checking general_log when log_output is FILE -#=========================================================== - -#SET @log_file = "mytest.log"; -#SET @@global.general_log = 0; -#FLUSH LOGS; -#SET @@global.general_log_file = @log_file; ---echo 'Bug#35371: Changing general_log file is crashing server' ---echo 'SET @@global.general_log_file = @log_file;' +#=============================================================== +SET @@global.general_log = 'OFF'; +FLUSH LOGS; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval SET @@global.general_log_file = '$MYSQLTEST_VARDIR/run/mytest.log'; +SET @@global.general_log = 'ON'; SET @@global.log_output = 'FILE'; TRUNCATE TABLE mysql.general_log; --disable_warnings DROP TABLE IF EXISTS t1; --enable_warnings -create table t1(a int); -INSERT INTO t1 value(1); +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUE(1); SELECT 'abc'; -SELECT count(*) from mysql.general_log; +SELECT count(*) FROM mysql.general_log; DROP TABLE t1; +file_exists $MYSQLTEST_VARDIR/run/mytest.log ; + +#============================================================== +# Clean up +#============================================================== + +--echo connection default; +connection default; +SET @@global.general_log= 'OFF'; +SET @@global.general_log_file= @start_general_log_file; +SET @@global.log_output= @start_value; +SET @@global.general_log= @start_general_log; +SET @@global.general_log= 'ON'; + --enable_ps_protocol #################################################### -# Endo of functionality Testing for log_output # +# End of functionality Testing for log_output # #################################################### + From 1182c0979a5d9acc345c2cba83cac0aa32d42bca Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Thu, 27 Nov 2008 18:54:23 +0400 Subject: [PATCH 4/4] Bug#37284 Crash in Field_string::type() The bug is repeatable with latest(1.0.1) InnoDB plugin on Linux, Win, If MySQL is compiled with valgrind there are errors about using of uninitialized variable(orig_table). The fix is to set field->orig_table correct value. mysql-test/r/innodb_mysql.result: test result mysql-test/t/innodb_mysql.test: test case sql/sql_base.cc: set field->orig_table to 'table' value because it may be bogus and it leads to crash on Field_string::type() function. --- mysql-test/r/innodb_mysql.result | 6 ++++++ mysql-test/t/innodb_mysql.test | 11 +++++++++++ sql/sql_base.cc | 3 +++ 3 files changed, 20 insertions(+) diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index 47fa331c9ab..682cc2e82e2 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -1261,4 +1261,10 @@ a b c 5 1 1 4 1 1 DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a char(50)) ENGINE=InnoDB; +CREATE INDEX i1 on t1 (a(3)); +SELECT * FROM t1 WHERE a = 'abcde'; +a +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/innodb_mysql.test b/mysql-test/t/innodb_mysql.test index e15d1aee08a..b4fc425cb7c 100644 --- a/mysql-test/t/innodb_mysql.test +++ b/mysql-test/t/innodb_mysql.test @@ -1014,4 +1014,15 @@ SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5; DROP TABLE t1; +# +# Bug#37284 Crash in Field_string::type() +# +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +CREATE TABLE t1 (a char(50)) ENGINE=InnoDB; +CREATE INDEX i1 on t1 (a(3)); +SELECT * FROM t1 WHERE a = 'abcde'; +DROP TABLE t1; + --echo End of 5.0 tests diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 873a3eac24e..881c6a421e8 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2102,7 +2102,10 @@ bool reopen_table(TABLE *table,bool locked) for (key=0 ; key < table->s->keys ; key++) { for (part=0 ; part < table->key_info[key].usable_key_parts ; part++) + { table->key_info[key].key_part[part].field->table= table; + table->key_info[key].key_part[part].field->orig_table= table; + } } if (table->triggers) table->triggers->set_table(table);