revision-id: 2cdc9a81258adf31bb67b7703331ea7dbe40b885 (mariadb-10.0.30-309-g2cdc9a81258) parent(s): a99dcdf7e9ede3b96466eb1294284141805747fc author: Varun Gupta committer: Varun Gupta timestamp: 2018-04-04 19:31:55 +0530 message: MDEV-14440: Assertion `inited==RND' failed in handler::ha_rnd_end In the function QUICK_RANGE_SELECT::init_ror_merged_scan we create a seperate handler if the handler in head->file cannot be reused. The flag free_file tells us if we have a seperate handler or not. There are cases where you might create a handler and then there might be a failure and then we have to revert the handler back to the original one. The code does that but it does not reset the flag 'free_file' in this case. --- mysql-test/r/range_innodb.result | 52 +++++++++++++++++++++++++++++++++ mysql-test/t/range_innodb.test | 63 ++++++++++++++++++++++++++++++++++++++++ sql/opt_range.cc | 1 + 3 files changed, 116 insertions(+) diff --git a/mysql-test/r/range_innodb.result b/mysql-test/r/range_innodb.result index 794e6c7b3cc..1266547e16b 100644 --- a/mysql-test/r/range_innodb.result +++ b/mysql-test/r/range_innodb.result @@ -37,3 +37,55 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t0 ALL NULL NULL NULL NULL 10 1 SIMPLE t2 range a,b b 5 NULL 201 Using where; Using join buffer (flat, BNL join) drop table t0,t1,t2; +# +# MDEV-14440: Assertion `inited==RND' failed in handler::ha_rnd_end +# +SET @stats.save= @@innodb_stats_persistent; +SET GLOBAL innodb_stats_persistent= ON; +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +CREATE TABLE t2 ( +pk INT AUTO_INCREMENT, +i INT, +t1 TIME, +t2 TIME, +d1 DATETIME, +d2 DATETIME, +v1 VARCHAR(1), +v2 VARCHAR(1), +PRIMARY KEY (pk), +KEY (i) +) ENGINE=InnoDB; +BEGIN; +SELECT * FROM t1; +a +ALTER TABLE t2 PARTITION BY KEY() PARTITIONS 5; +INSERT INTO t2 (i,t1,t2,d1,d2,v1,v2) VALUES +(7, '01:39:40', '01:39:40', '1900-01-01 00:00:00', '1900-01-01 00:00:00', 'w', 'w'), +(2, '18:14:11', '18:14:11', '1980-03-03 15:06:11', '1980-03-03 15:06:11', 'e', 'e'), +(2, '03:28:55', '03:28:55', '2025-06-03 03:14:33', '2025-06-03 03:14:33', 'a', 'a'), +(4, '15:00:03', '15:00:03', '1900-01-01 00:00:00', '1900-01-01 00:00:00', 'r', 'r'), +(6, '17:10:27', '17:10:27', '2014-04-18 18:00:26', '2014-04-18 18:00:26', 'k', 'k'), +(6, '09:50:22', '09:50:22', '2026-10-20 00:00:00', '2026-10-20 00:00:00', 'c', 'c'), +(8, '00:00:00', '00:00:00', '2010-07-24 13:01:33', '2010-07-24 13:01:33', 'k', 'k'), +(4, '09:51:13', '09:51:13', '2006-04-14 03:38:00', '2006-04-14 03:38:00', 'x', 'x'), +(2, '11:25:28', '11:25:28', '2012-12-12 12:12:12', '2012-12-12 12:12:12', 'j', 'j'), +(8, '11:11:11', '11:11:11', '1973-07-16 03:25:43', '1973-07-16 03:25:43', 't', 't'), +(1, '11:14:24', '11:14:24', '1981-12-12 08:27:15', '1981-12-12 08:27:15', 'n', 'n'), +(6, '04:00:47', '04:00:47', '2022-11-25 18:24:30', '2022-11-25 18:24:30', 'z', 'z'), +(3, '21:22:12', '21:22:12', '1991-07-28 18:41:31', '1991-07-28 18:41:31', 'u', 'u'), +(2, '14:29:11', '14:29:11', '2034-09-25 22:51:04', '2034-09-25 22:51:04', 'a', 'a'), +(3, '16:23:38', '16:23:38', '1900-01-01 00:00:00', '1900-01-01 00:00:00', 'g', 'g'), +(4, '20:06:35', '20:06:35', '2011-01-11 07:21:24', '2011-01-11 07:21:24', 'f', 'f'), +(6, '19:33:10', '19:33:10', '1979-09-15 17:25:04', '1979-09-15 17:25:04', 'p', 'p'), +(0, '08:51:41', '08:51:41', '2008-01-07 21:23:06', '2008-01-07 21:23:06', 'm', 'm'), +(8, '22:40:20', '22:40:20', '1974-11-12 05:56:02', '1974-11-12 05:56:02', 't', 't'), +(5, '13:00:50', '13:00:50', '2000-08-27 08:22:13', '2000-08-27 08:22:13', 'i', 'i'), +(4, '22:22:22', '12:12:12', '2015-02-27 00:00:00', '2015-02-27 00:00:00', 'h', 'h'), +(2, '12:54:06', '12:54:06', '1996-09-27 12:06:03', '1996-09-27 12:06:03', 'd', 'd'), +(3, '22:47:40', '22:47:40', '2029-07-13 16:52:43', '2029-07-13 16:52:43', 'b', 'b'), +(7, '03:01:56', '03:01:56', '1973-10-13 00:00:00', '1973-10-13 00:00:00', 'o', 'o'), +(1, '12:35:21', '12:35:21', '2025-12-02 00:57:31', '2025-12-02 00:57:31', 'j', 'j'), +(1, '00:00:00', '00:00:00', '1978-03-12 09:48:05', '1978-03-12 09:48:05', 's', 's'); +SELECT * FROM t2 WHERE pk != 0 AND i = 0; +DROP TABLE t1, t2; +SET GLOBAL innodb_stats_persistent= @stats.save; diff --git a/mysql-test/t/range_innodb.test b/mysql-test/t/range_innodb.test index f76794814ef..760478fab25 100644 --- a/mysql-test/t/range_innodb.test +++ b/mysql-test/t/range_innodb.test @@ -3,6 +3,7 @@ --echo # --source include/have_innodb.inc +--source include/have_partition.inc --disable_warnings drop table if exists t0, t1, t2; @@ -45,3 +46,65 @@ explain select * from t0 left join t2 on t2.a <t0.a and t2.b between 50 and 250; drop table t0,t1,t2; +--echo # +--echo # MDEV-14440: Assertion `inited==RND' failed in handler::ha_rnd_end +--echo # + +SET @stats.save= @@innodb_stats_persistent; +SET GLOBAL innodb_stats_persistent= ON; + +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +CREATE TABLE t2 ( + pk INT AUTO_INCREMENT, + i INT, + t1 TIME, + t2 TIME, + d1 DATETIME, + d2 DATETIME, + v1 VARCHAR(1), + v2 VARCHAR(1), + PRIMARY KEY (pk), + KEY (i) +) ENGINE=InnoDB; + +BEGIN; +SELECT * FROM t1; + +--connect (con1,localhost,root,,test) + +ALTER TABLE t2 PARTITION BY KEY() PARTITIONS 5; + +INSERT INTO t2 (i,t1,t2,d1,d2,v1,v2) VALUES + (7, '01:39:40', '01:39:40', '1900-01-01 00:00:00', '1900-01-01 00:00:00', 'w', 'w'), + (2, '18:14:11', '18:14:11', '1980-03-03 15:06:11', '1980-03-03 15:06:11', 'e', 'e'), + (2, '03:28:55', '03:28:55', '2025-06-03 03:14:33', '2025-06-03 03:14:33', 'a', 'a'), + (4, '15:00:03', '15:00:03', '1900-01-01 00:00:00', '1900-01-01 00:00:00', 'r', 'r'), + (6, '17:10:27', '17:10:27', '2014-04-18 18:00:26', '2014-04-18 18:00:26', 'k', 'k'), + (6, '09:50:22', '09:50:22', '2026-10-20 00:00:00', '2026-10-20 00:00:00', 'c', 'c'), + (8, '00:00:00', '00:00:00', '2010-07-24 13:01:33', '2010-07-24 13:01:33', 'k', 'k'), + (4, '09:51:13', '09:51:13', '2006-04-14 03:38:00', '2006-04-14 03:38:00', 'x', 'x'), + (2, '11:25:28', '11:25:28', '2012-12-12 12:12:12', '2012-12-12 12:12:12', 'j', 'j'), + (8, '11:11:11', '11:11:11', '1973-07-16 03:25:43', '1973-07-16 03:25:43', 't', 't'), + (1, '11:14:24', '11:14:24', '1981-12-12 08:27:15', '1981-12-12 08:27:15', 'n', 'n'), + (6, '04:00:47', '04:00:47', '2022-11-25 18:24:30', '2022-11-25 18:24:30', 'z', 'z'), + (3, '21:22:12', '21:22:12', '1991-07-28 18:41:31', '1991-07-28 18:41:31', 'u', 'u'), + (2, '14:29:11', '14:29:11', '2034-09-25 22:51:04', '2034-09-25 22:51:04', 'a', 'a'), + (3, '16:23:38', '16:23:38', '1900-01-01 00:00:00', '1900-01-01 00:00:00', 'g', 'g'), + (4, '20:06:35', '20:06:35', '2011-01-11 07:21:24', '2011-01-11 07:21:24', 'f', 'f'), + (6, '19:33:10', '19:33:10', '1979-09-15 17:25:04', '1979-09-15 17:25:04', 'p', 'p'), + (0, '08:51:41', '08:51:41', '2008-01-07 21:23:06', '2008-01-07 21:23:06', 'm', 'm'), + (8, '22:40:20', '22:40:20', '1974-11-12 05:56:02', '1974-11-12 05:56:02', 't', 't'), + (5, '13:00:50', '13:00:50', '2000-08-27 08:22:13', '2000-08-27 08:22:13', 'i', 'i'), + (4, '22:22:22', '12:12:12', '2015-02-27 00:00:00', '2015-02-27 00:00:00', 'h', 'h'), + (2, '12:54:06', '12:54:06', '1996-09-27 12:06:03', '1996-09-27 12:06:03', 'd', 'd'), + (3, '22:47:40', '22:47:40', '2029-07-13 16:52:43', '2029-07-13 16:52:43', 'b', 'b'), + (7, '03:01:56', '03:01:56', '1973-10-13 00:00:00', '1973-10-13 00:00:00', 'o', 'o'), + (1, '12:35:21', '12:35:21', '2025-12-02 00:57:31', '2025-12-02 00:57:31', 'j', 'j'), + (1, '00:00:00', '00:00:00', '1978-03-12 09:48:05', '1978-03-12 09:48:05', 's', 's'); + +--connection default +--error 0,ER_TABLE_DEF_CHANGED +SELECT * FROM t2 WHERE pk != 0 AND i = 0; + +DROP TABLE t1, t2; +SET GLOBAL innodb_stats_persistent= @stats.save; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index f1d84e5c623..9c0de1bd1f9 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2161,6 +2161,7 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler, MEM_ROOT *alloc head->column_bitmaps_set(save_read_set, save_write_set); delete file; file= save_file; + free_file= false; DBUG_RETURN(1); }