From 569960410f108a77875e655002ccfe47688997af Mon Sep 17 00:00:00 2001 From: "igor@olga.mysql.com" <> Date: Thu, 7 Jun 2007 00:59:08 -0700 Subject: Fixed bug #28449: a crash may happen at some rare conditions when a temporary table has grown out of heap memory reserved for it and the remaining disk space is not big enough to store the table as a MyISAM table. The crash happens because the function create_myisam_from_heap does not handle safely the mem_root structure associated with the converted table in the case when an error has occurred. --- mysql-test/t/error_simulation.test | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 mysql-test/t/error_simulation.test (limited to 'mysql-test/t/error_simulation.test') diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test new file mode 100644 index 00000000000..8c044224b8a --- /dev/null +++ b/mysql-test/t/error_simulation.test @@ -0,0 +1,29 @@ +-- source include/have_debug.inc + +# +# Bug #28499: crash for grouping query when tmp_table_size is too small +# + +DROP TABLE IF EXISTS t1; + +CREATE TABLE t1 ( + a varchar(32) character set utf8 collate utf8_bin NOT NULL, + b varchar(32) character set utf8 collate utf8_bin NOT NULL ) +ENGINE=MyISAM DEFAULT CHARSET=utf8; + +INSERT INTO t1 VALUES + ('AAAAAAAAAA','AAAAAAAAAA'), ('AAAAAAAAAB','AAAAAAAAAB '), + ('AAAAAAAAAB','AAAAAAAAAB'), ('AAAAAAAAAC','AAAAAAAAAC'), + ('AAAAAAAAAD','AAAAAAAAAD'), ('AAAAAAAAAE','AAAAAAAAAE'), + ('AAAAAAAAAF','AAAAAAAAAF'), ('AAAAAAAAAG','AAAAAAAAAG'), + ('AAAAAAAAAH','AAAAAAAAAH'), ('AAAAAAAAAI','AAAAAAAAAI'), + ('AAAAAAAAAJ','AAAAAAAAAJ'), ('AAAAAAAAAK','AAAAAAAAAK'); + +set tmp_table_size=1024; + +--error ER_DUP_KEY +SELECT MAX(a) FROM t1 GROUP BY a,b; + +set tmp_table_size=default; + +DROP TABLE t1; -- cgit v1.2.1 From e1cde8aabe769af403c70842de3707a1455b8884 Mon Sep 17 00:00:00 2001 From: "evgen@moonbone.local" <> Date: Mon, 11 Jun 2007 17:02:16 +0400 Subject: error_simulation.result, item.cc, subselect.result, error_simulation.test: Post merge fix. --- mysql-test/t/error_simulation.test | 1 + 1 file changed, 1 insertion(+) (limited to 'mysql-test/t/error_simulation.test') diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test index 8c044224b8a..2f6ea5eac87 100644 --- a/mysql-test/t/error_simulation.test +++ b/mysql-test/t/error_simulation.test @@ -21,6 +21,7 @@ INSERT INTO t1 VALUES set tmp_table_size=1024; +--replace_regex /in table '[^']+'/in table 'tmp_table'/ --error ER_DUP_KEY SELECT MAX(a) FROM t1 GROUP BY a,b; -- cgit v1.2.1 From f1312d30bba46b199ca94eaa44153bf2c6f99545 Mon Sep 17 00:00:00 2001 From: "msvensson@shellback.(none)" <> Date: Thu, 3 Apr 2008 10:27:56 +0200 Subject: Dynamically set debug flag for session only - avoid restart - keep all in one file - fix --check-testcase --- mysql-test/t/error_simulation.test | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mysql-test/t/error_simulation.test') diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test index 2f6ea5eac87..f730c95208e 100644 --- a/mysql-test/t/error_simulation.test +++ b/mysql-test/t/error_simulation.test @@ -21,10 +21,15 @@ INSERT INTO t1 VALUES set tmp_table_size=1024; +# Set debug flag so an error is returned when +# tmp table in query is converted from heap to myisam +set session debug="d,raise_error"; + --replace_regex /in table '[^']+'/in table 'tmp_table'/ --error ER_DUP_KEY SELECT MAX(a) FROM t1 GROUP BY a,b; set tmp_table_size=default; - DROP TABLE t1; + + -- cgit v1.2.1 From 4a1a64ec537bc6d9585cd566af71fc9d50c3b8d6 Mon Sep 17 00:00:00 2001 From: Ramil Kalimullin Date: Sun, 25 Apr 2010 15:06:40 +0400 Subject: Fix for bug#50946: fast index creation still seems to copy the table Problem: ALTER TABLE ADD INDEX may lead to table copying if there's numeric field(s) with non-default display width modificator specified. Fix: compare numeric field's storage lenghts when we decide whether they can be considered 'equal' for table alteration purposes. --- mysql-test/t/error_simulation.test | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'mysql-test/t/error_simulation.test') diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test index f730c95208e..7cd16a6bc5a 100644 --- a/mysql-test/t/error_simulation.test +++ b/mysql-test/t/error_simulation.test @@ -33,3 +33,19 @@ set tmp_table_size=default; DROP TABLE t1; +--echo # +--echo # Bug #50946: fast index creation still seems to copy the table +--echo # +CREATE TABLE t1 (a INT(100) NOT NULL); +INSERT INTO t1 VALUES (1), (0), (2); +SET SESSION debug='+d,alter_table_only_index_change'; +ALTER TABLE t1 ADD INDEX a(a); +SET SESSION debug=DEFAULT; +SHOW CREATE TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # End of 5.1 tests +--echo # -- cgit v1.2.1 From 779e2a968632a5e73c660307892ca6a868399dfc Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Fri, 21 May 2010 15:23:48 +0400 Subject: Bug #42064: low memory crash when importing hex strings, in Item_hex_string::Item_hex_string The status of memory allocation in the Lex_input_stream (called from the Parser_state constructor) was not checked which led to a parser crash in case of the out-of-memory error. The solution is to introduce new init() member function in Parser_state and Lex_input_stream so that status of memory allocation can be returned to the caller. --- mysql-test/t/error_simulation.test | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'mysql-test/t/error_simulation.test') diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test index 7cd16a6bc5a..7a48a2e3231 100644 --- a/mysql-test/t/error_simulation.test +++ b/mysql-test/t/error_simulation.test @@ -46,6 +46,20 @@ SELECT * FROM t1; DROP TABLE t1; +--echo # +--echo # Bug#42064: low memory crash when importing hex strings, in Item_hex_string::Item_hex_string +--echo # + +CREATE TABLE t1(a BLOB); + +SET SESSION debug="+d,bug42064_simulate_oom"; +# May fail with either ER_OUT_OF_RESOURCES or EE_OUTOFMEMORY +--error ER_OUT_OF_RESOURCES, 5 +INSERT INTO t1 VALUES(""); +SET SESSION debug=DEFAULT; + +DROP TABLE t1; + --echo # --echo # End of 5.1 tests --echo # -- cgit v1.2.1 From dac59fa9c3dab835872b9e9581ed5414d113e09e Mon Sep 17 00:00:00 2001 From: Martin Hansson Date: Thu, 24 Jun 2010 15:21:23 +0200 Subject: Bug#41660: Sort-index_merge for non-first join table may require O(#scans) memory When an index merge operation was restarted, it would re-allocate the Unique object controlling the duplicate row ID elimination. Fixed by making the Unique object a member of QUICK_INDEX_MERGE_SELECT and thus reusing it throughout the lifetime of this object. --- mysql-test/t/error_simulation.test | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'mysql-test/t/error_simulation.test') diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test index 7a48a2e3231..8e65c338f36 100644 --- a/mysql-test/t/error_simulation.test +++ b/mysql-test/t/error_simulation.test @@ -45,6 +45,35 @@ SHOW CREATE TABLE t1; SELECT * FROM t1; DROP TABLE t1; +-- echo # +-- echo # Bug#41660: Sort-index_merge for non-first join table may require +-- echo # O(#scans) memory +-- echo # + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9); + +CREATE TABLE t2 (a INT, b INT, filler CHAR(100), KEY(a), KEY(b)); +INSERT INTO t2 SELECT 1000, 1000, 'filler' FROM t1 A, t1 B, t1 C; +INSERT INTO t2 VALUES (1, 1, 'data'); + +--echo # the example query uses LEFT JOIN only for the sake of being able to +--echo # demonstrate the issue with a very small dataset. (left outer join +--echo # disables the use of join buffering, so we get the second table +--echo # re-scanned for every record in the outer table. if we used inner join, +--echo # we would need to have thousands of records and/or more columns in both +--echo # tables so that the join buffer is filled and re-scans are triggered). + +SET SESSION debug = '+d,only_one_Unique_may_be_created'; + +--replace_column 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x +EXPLAIN +SELECT * FROM t1 LEFT JOIN t2 ON ( t2.a < 10 OR t2.b < 10 ); +SELECT * FROM t1 LEFT JOIN t2 ON ( t2.a < 10 OR t2.b < 10 ); + +SET SESSION debug = DEFAULT; + +DROP TABLE t1, t2; --echo # --echo # Bug#42064: low memory crash when importing hex strings, in Item_hex_string::Item_hex_string -- cgit v1.2.1 From 8a2f3f4b5ed8778c00b6ad169aaad28a4eb6058c Mon Sep 17 00:00:00 2001 From: Martin Hansson Date: Tue, 29 Jun 2010 10:28:17 +0200 Subject: Fix of bad merge of test case for Bug#41660 (test case moved). --- mysql-test/t/error_simulation.test | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'mysql-test/t/error_simulation.test') diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test index 8e65c338f36..f6edacfaa29 100644 --- a/mysql-test/t/error_simulation.test +++ b/mysql-test/t/error_simulation.test @@ -45,6 +45,20 @@ SHOW CREATE TABLE t1; SELECT * FROM t1; DROP TABLE t1; +--echo # +--echo # Bug#42064: low memory crash when importing hex strings, in Item_hex_string::Item_hex_string +--echo # + +CREATE TABLE t1(a BLOB); + +SET SESSION debug="+d,bug42064_simulate_oom"; +# May fail with either ER_OUT_OF_RESOURCES or EE_OUTOFMEMORY +--error ER_OUT_OF_RESOURCES, 5 +INSERT INTO t1 VALUES(""); +SET SESSION debug=DEFAULT; + +DROP TABLE t1; + -- echo # -- echo # Bug#41660: Sort-index_merge for non-first join table may require -- echo # O(#scans) memory @@ -75,20 +89,6 @@ SET SESSION debug = DEFAULT; DROP TABLE t1, t2; ---echo # ---echo # Bug#42064: low memory crash when importing hex strings, in Item_hex_string::Item_hex_string ---echo # - -CREATE TABLE t1(a BLOB); - -SET SESSION debug="+d,bug42064_simulate_oom"; -# May fail with either ER_OUT_OF_RESOURCES or EE_OUTOFMEMORY ---error ER_OUT_OF_RESOURCES, 5 -INSERT INTO t1 VALUES(""); -SET SESSION debug=DEFAULT; - -DROP TABLE t1; - --echo # --echo # End of 5.1 tests --echo # -- cgit v1.2.1 From fcd99c156ba85af9af11c41a0ad8c5abe25e2b8e Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Wed, 5 Oct 2011 13:28:20 +0400 Subject: Bug#11747970 34660: CRASH WHEN FEDERATED TABLE LOSES CONNECTION DURING INSERT ... SELECT Problematic query: insert ignore into `t1_federated` (`c1`) select `c1` from `t1_local` a where not exists (select 1 from `t1_federated` b where a.c1 = b.c1); When this query is killed in another connection it could lead to crash. The problem is follwing: An attempt to obtain table statistics for subselect table in killed query fails with an error. So JOIN::optimize() for subquery is failed but it does not prevent further subquery evaluation. At the first subquery execution JOIN::optimize() is called (see subselect_single_select_engine::exec()) and fails with an error. 'executed' flag is set to TRUE and it prevents further subquery evaluation. At the second call JOIN::optimize() does not happen as 'JOIN::optimized' is TRUE and in case of uncacheable subquery the 'executed' flag is set to FALSE before subquery evaluation. So we loose 'optimize stage' error indication (see subselect_single_select_engine::exec()). In other words 'executed' flag is used for two purposes, for error indication at JOIN::optimize() stage and for an indication of subquery execution. And it seems it's wrong as the flag could be reset. --- mysql-test/t/error_simulation.test | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'mysql-test/t/error_simulation.test') diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test index f6edacfaa29..95ec2c5b21d 100644 --- a/mysql-test/t/error_simulation.test +++ b/mysql-test/t/error_simulation.test @@ -89,6 +89,20 @@ SET SESSION debug = DEFAULT; DROP TABLE t1, t2; + +--echo # +--echo # Bug#11747970 34660: CRASH WHEN FEDERATED TABLE LOSES CONNECTION DURING INSERT ... SELECT +--echo # +CREATE TABLE t1(f1 INT, KEY(f1)); +CREATE TABLE t2(f1 INT); +INSERT INTO t1 VALUES (1),(2); +INSERT INTO t2 VALUES (1),(2); +SET SESSION debug='d,bug11747970_simulate_error'; +INSERT IGNORE INTO t2 SELECT f1 FROM t1 a WHERE NOT EXISTS (SELECT 1 FROM t2 b WHERE a.f1 = b.f1); +SET SESSION debug = DEFAULT; +DROP TABLE t1,t2; + + --echo # --echo # End of 5.1 tests --echo # -- cgit v1.2.1 From 5a587b6d2897e786b515d05a09b37ef81695dab7 Mon Sep 17 00:00:00 2001 From: Nisha Gopalakrishnan Date: Mon, 24 Nov 2014 20:24:18 +0530 Subject: BUG#11747548: DETECT ORPHAN TEMP-POOL FILES, AND HANDLE GRACEFULLY Analysis: -------- Certain queries using intrinsic temporary tables may fail due to name clashes in the file name for the temporary table when the 'temp-pool' enabled. 'temp-pool' tries to reduce the number of different filenames used for temp tables by allocating them from small pool in order to avoid problems in the Linux kernel by using a three part filename: __. The bit corresponding to the temp_pool_slot_num is set in the bit map maintained for the temp-pool when it used for the file name. It is cleared after the temp table is deleted for re-use. The 'create_tmp_table()' function call under error condition tries to clear the same bit twice by calling 'free_tmp_table()' and 'bitmap_lock_clear_bit()'. 'free_tmp_table()' does a delete of the table/file and clears the bit by calling the same function 'bitmap_lock_clear_bit()'. The issue reported can be triggered under the timing window mentioned below for an error condition while creating the temp table: a) THD1: Due to an error clears the temp pool slot number used by it by calling 'free_tmp_table'. b) THD2: In the process of creating the temp table by using an unused slot number in the bit map. c) THD1: Clears the slot number used THD2 by calling 'bitmap_lock_clear_bit()' after completing the call 'free_tmp_table'. d) THD3: Uses the slot number used the THD2 since it is freed by THD1. When it tries to create the temp file using that slot number, an error is reported since it is currently in use by THD2. [The error: Error 'Can't create/write to file '/tmp/#sql_277e_0.MYD' (Errcode: 17)'] Another issue which may occur in 5.6 and trunk is that: When the open temporary table fails after its creation(due to ulimit or OOM error), the file is not deleted. Thus further attempts to use the same slot number in the 'temp-pool' results in failure. Fix: --- a) Under the error condition calling the 'bitmap_lock_clear_bit()' function to clear the bit is unnecessary since 'free_tmp_table()' deletes the table/file and clears the bit. Hence removed the redundant call 'bitmap_lock_clear_bit()' in 'create_tmp_table()' This prevents the timing window under which the issue reported can be seen. b) If open of the temporary table fails, then the file is deleted thus allowing the temp-pool slot number to be utilized for the subsequent temporary table creation. c) Also if the attempt to create temp table fails since it already exists, the temp-pool slot for it is marked as used, to avoid the problem from re-appearing. --- mysql-test/t/error_simulation.test | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'mysql-test/t/error_simulation.test') diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test index 95ec2c5b21d..59e3aba9fe1 100644 --- a/mysql-test/t/error_simulation.test +++ b/mysql-test/t/error_simulation.test @@ -1,4 +1,5 @@ -- source include/have_debug.inc +--source include/not_embedded.inc # # Bug #28499: crash for grouping query when tmp_table_size is too small @@ -106,3 +107,35 @@ DROP TABLE t1,t2; --echo # --echo # End of 5.1 tests --echo # + + +--echo # +--echo # BUG#11747548:DETECT ORPHAN TEMP-POOL FILES, AND HANDLE GRACEFULLY. +--echo # + +--echo #Set up. +CREATE TABLE pid_table(pid_no INT); +CREATE TABLE t1 (a BLOB); +INSERT INTO t1 VALUES (1), (2); + +--echo #Create MYD and MYI files for intrinsic temp table. +--let $pid_file=`SELECT @@pid_file` +--replace_result $pid_file pid_file +--eval LOAD DATA LOCAL INFILE '$pid_file' INTO TABLE pid_table +--let $temp_file_MYD= `SELECT CONCAT('#sql_', LCASE(HEX(pid_no)), '_0', '.MYD') FROM pid_table` +--let $temp_file_MYI= `SELECT CONCAT('#sql_', LCASE(HEX(pid_no)), '_0', '.MYI') FROM pid_table` +--write_file $MYSQLTEST_VARDIR/tmp/$temp_file_MYD +EOF +--write_file $MYSQLTEST_VARDIR/tmp/$temp_file_MYI +EOF + +--echo #Reports an error since the temp file already exists. +--replace_regex /.*Can't create\/write *.*/Can't create or write to file/ +--error 1 +SELECT a FROM t1 ORDER BY rand(1); + +--echo #With patch, the query executes successfully. +SELECT a FROM t1 ORDER BY rand(1); + +--echo #cleanup +DROP TABLE t1, pid_table; -- cgit v1.2.1