From a470fd7ba487de1a9a3b44085fa8c3db697d2878 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 3 Oct 2008 20:08:40 +0200 Subject: [PATCH 1/3] Bug#37719: Crash if rename Archive table to same name with different case and then select Problem was that the archive share was using a case insensitive charset when comparing table names Solution was to use a case sensitive char set when the table names are case sensitive mysql-test/suite/parts/r/partition_mgm_lc0_archive.result: Bug#37719: Crash if rename Archive table to same name with different case and then select Updated to correct result. storage/archive/ha_archive.cc: Bug#37719: Crash if rename Archive table to same name with different case and then select system_charset_info is case insensitive, table_alias_charset depends on the filesystem/lower_case_table_names variable. since there could be two tables that used the same share, unpredicted things could happen. --- .../parts/r/partition_mgm_lc0_archive.result | 66 ------------------- storage/archive/ha_archive.cc | 2 +- 2 files changed, 1 insertion(+), 67 deletions(-) diff --git a/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result b/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result index 2bb6e7421b1..5350d11c7a1 100644 --- a/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result +++ b/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result @@ -157,22 +157,10 @@ tablea SELECT * FROM tablea; a 1 -1 10 -10 -11 -12 2 -2 -3 -4 -5 -6 -7 7 8 -8 -9 9 SHOW CREATE TABLE tablea; Table Create Table @@ -185,7 +173,6 @@ ALTER TABLE TableA REMOVE PARTITIONING; SELECT * FROM TableA; a 1 -1 10 11 12 @@ -195,10 +182,7 @@ a 5 6 7 -7 8 -8 -9 9 SHOW CREATE TABLE TableA; Table Create Table @@ -372,22 +356,10 @@ tablea SELECT * FROM tablea; a 1 -1 10 -10 -11 -12 2 -2 -3 -4 -5 -6 -7 7 8 -8 -9 9 SHOW CREATE TABLE tablea; Table Create Table @@ -400,21 +372,16 @@ ALTER TABLE TableA REMOVE PARTITIONING; SELECT * FROM TableA; a 1 -1 -10 10 11 12 2 -2 3 4 5 6 7 8 -8 -9 9 SHOW CREATE TABLE TableA; Table Create Table @@ -580,22 +547,10 @@ tablea SELECT * FROM tablea; a 1 -1 10 -10 -11 -12 2 -2 -3 -4 -5 -6 -7 7 8 -8 -9 9 SHOW CREATE TABLE tablea; Table Create Table @@ -608,22 +563,16 @@ ALTER TABLE TableA REMOVE PARTITIONING; SELECT * FROM TableA; a 1 -1 -10 10 11 12 2 -2 3 4 5 6 7 -7 8 -8 -9 9 SHOW CREATE TABLE TableA; Table Create Table @@ -783,19 +732,10 @@ tablea SELECT * FROM tablea; a 1 -1 10 -12 2 -3 -4 -5 -6 -7 7 8 -8 -9 9 SHOW CREATE TABLE tablea; Table Create Table @@ -808,19 +748,13 @@ ALTER TABLE TableA REMOVE PARTITIONING; SELECT * FROM TableA; a 1 -1 -10 12 -2 3 4 5 6 7 -7 8 -8 -9 9 SHOW CREATE TABLE TableA; Table Create Table diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index 967e315d4a4..7edfca53751 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -171,7 +171,7 @@ int archive_db_init(void *p) if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST)) goto error; - if (hash_init(&archive_open_tables, system_charset_info, 32, 0, 0, + if (hash_init(&archive_open_tables, table_alias_charset, 32, 0, 0, (hash_get_key) archive_get_key, 0, 0)) { VOID(pthread_mutex_destroy(&archive_mutex)); From 620d955e3ae9dbe6820b18668947805efd6547ec Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Thu, 23 Oct 2008 22:14:07 +0200 Subject: [PATCH 2/3] Bug#40176: update as first partitioning statement breaks auto increment The auto_increment value was not initialized if the first statement after opening a table was an 'UPDATE'. solution was to check initialize if it was not, before trying to increase it in update. mysql-test/suite/parts/inc/partition_auto_increment.inc: Bug#40176: update as first partitioning statement breaks auto increment Added tests for verifying the bug and show some more auto_increment flaws mysql-test/suite/parts/r/partition_auto_increment_archive.result: Bug#40176: update as first partitioning statement breaks auto increment Updated test results, due to added tests mysql-test/suite/parts/r/partition_auto_increment_blackhole.result: Bug#40176: update as first partitioning statement breaks auto increment Updated test results, due to added tests mysql-test/suite/parts/r/partition_auto_increment_innodb.result: Bug#40176: update as first partitioning statement breaks auto increment Updated test results, due to added tests mysql-test/suite/parts/r/partition_auto_increment_memory.result: Bug#40176: update as first partitioning statement breaks auto increment Updated test results, due to added tests mysql-test/suite/parts/r/partition_auto_increment_myisam.result: Bug#40176: update as first partitioning statement breaks auto increment Updated test results, due to added tests mysql-test/suite/parts/r/partition_auto_increment_ndb.result: Bug#40176: update as first partitioning statement breaks auto increment Updated test results, due to added tests sql/ha_partition.cc: Bug#40176: update as first partitioning statement breaks auto increment make sure that the auto_increment value is initialized before updating it. (missed initializing in mysql_update_row). sql/ha_partition.h: Bug#40176: update as first partitioning statement breaks auto increment Assert that it is initialized, before updating the auto_increment value --- .../parts/inc/partition_auto_increment.inc | 28 +++++++++++ .../r/partition_auto_increment_archive.result | 22 +++++++++ .../partition_auto_increment_blackhole.result | 36 +++++++++++++++ .../r/partition_auto_increment_innodb.result | 46 +++++++++++++++++-- .../r/partition_auto_increment_memory.result | 40 +++++++++++++++- .../r/partition_auto_increment_myisam.result | 40 +++++++++++++++- .../r/partition_auto_increment_ndb.result | 40 +++++++++++++++- sql/ha_partition.cc | 30 ++++++------ sql/ha_partition.h | 2 +- 9 files changed, 259 insertions(+), 25 deletions(-) diff --git a/mysql-test/suite/parts/inc/partition_auto_increment.inc b/mysql-test/suite/parts/inc/partition_auto_increment.inc index 341bf7ab860..5e9ad47aa2e 100644 --- a/mysql-test/suite/parts/inc/partition_auto_increment.inc +++ b/mysql-test/suite/parts/inc/partition_auto_increment.inc @@ -43,8 +43,13 @@ SET INSERT_ID = 30; INSERT INTO t1 VALUES (NULL); if (!$skip_update) { +# InnoDB Does not handle this correctly, see bug#14793, bug#21641 UPDATE t1 SET c1 = 50 WHERE c1 = 17; UPDATE t1 SET c1 = 51 WHERE c1 = 19; + FLUSH TABLES; + UPDATE t1 SET c1 = 40 WHERE c1 = 50; + SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; -- error 0, ER_BAD_NULL_ERROR UPDATE t1 SET c1 = NULL WHERE c1 = 4; if (!$mysql_errno) @@ -83,6 +88,16 @@ TRUNCATE TABLE t1; INSERT INTO t1 VALUES (NULL); SHOW CREATE TABLE t1; SELECT * FROM t1 ORDER BY c1; +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +if (!$skip_delete) +{ +DELETE FROM t1 WHERE c1 >= 100; +} +# InnoDB does reset auto_increment on OPTIMIZE, Bug#18274 +# Archive does reset auto_increment on OPTIMIZE, Bug#40216 +OPTIMIZE TABLE t1; +SHOW CREATE TABLE t1; DROP TABLE t1; -- echo # Simple test with NULL @@ -184,6 +199,10 @@ if (!$skip_update) { UPDATE t1 SET c1 = 150 WHERE c1 = 17; UPDATE t1 SET c1 = 151 WHERE c1 = 19; + FLUSH TABLES; + UPDATE t1 SET c1 = 140 WHERE c1 = 150; + SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; -- error 0, ER_BAD_NULL_ERROR UPDATE t1 SET c1 = NULL WHERE c1 = 4; if (!$mysql_errno) @@ -295,6 +314,15 @@ TRUNCATE TABLE t1; INSERT INTO t1 VALUES (NULL); SHOW CREATE TABLE t1; SELECT * FROM t1 ORDER BY c1; +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +if (!$skip_delete) +{ +DELETE FROM t1 WHERE c1 >= 100; +} +# InnoDB does reset auto_increment on OPTIMIZE, Bug#18274 +OPTIMIZE TABLE t1; +SHOW CREATE TABLE t1; DROP TABLE t1; -- echo # Test with two threads diff --git a/mysql-test/suite/parts/r/partition_auto_increment_archive.result b/mysql-test/suite/parts/r/partition_auto_increment_archive.result index edfe408a072..c8d7b2af0c6 100644 --- a/mysql-test/suite/parts/r/partition_auto_increment_archive.result +++ b/mysql-test/suite/parts/r/partition_auto_increment_archive.result @@ -105,6 +105,17 @@ c1 5 6 7 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize status OK +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 DROP TABLE t1; # Simple test with NULL CREATE TABLE t1 ( @@ -362,6 +373,17 @@ c1 25 26 27 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize status OK +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (c1) PARTITIONS 2 */ DROP TABLE t1; # Test with two threads # con default diff --git a/mysql-test/suite/parts/r/partition_auto_increment_blackhole.result b/mysql-test/suite/parts/r/partition_auto_increment_blackhole.result index 73b228c1b72..d3bfbdb3cab 100644 --- a/mysql-test/suite/parts/r/partition_auto_increment_blackhole.result +++ b/mysql-test/suite/parts/r/partition_auto_increment_blackhole.result @@ -36,6 +36,12 @@ SET INSERT_ID = 30; INSERT INTO t1 VALUES (NULL); UPDATE t1 SET c1 = 50 WHERE c1 = 17; UPDATE t1 SET c1 = 51 WHERE c1 = 19; +FLUSH TABLES; +UPDATE t1 SET c1 = 40 WHERE c1 = 50; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; +AUTO_INCREMENT +1 UPDATE t1 SET c1 = NULL WHERE c1 = 4; # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY INSERT INTO t1 VALUES (NULL); @@ -96,6 +102,18 @@ t1 CREATE TABLE `t1` ( ) ENGINE=BLACKHOLE DEFAULT CHARSET=latin1 SELECT * FROM t1 ORDER BY c1; c1 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +DELETE FROM t1 WHERE c1 >= 100; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize note The storage engine for the table doesn't support optimize +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=BLACKHOLE DEFAULT CHARSET=latin1 DROP TABLE t1; # Simple test with NULL CREATE TABLE t1 ( @@ -165,6 +183,12 @@ INSERT INTO t1 VALUES (NULL), (90); INSERT INTO t1 VALUES (NULL); UPDATE t1 SET c1 = 150 WHERE c1 = 17; UPDATE t1 SET c1 = 151 WHERE c1 = 19; +FLUSH TABLES; +UPDATE t1 SET c1 = 140 WHERE c1 = 150; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; +AUTO_INCREMENT +1 UPDATE t1 SET c1 = NULL WHERE c1 = 4; # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY INSERT INTO t1 VALUES (NULL); @@ -272,6 +296,18 @@ t1 CREATE TABLE `t1` ( ) ENGINE=BLACKHOLE AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (c1) PARTITIONS 2 */ SELECT * FROM t1 ORDER BY c1; c1 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +DELETE FROM t1 WHERE c1 >= 100; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize note The storage engine for the table doesn't support optimize +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=BLACKHOLE DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (c1) PARTITIONS 2 */ DROP TABLE t1; # Test with two threads # con default diff --git a/mysql-test/suite/parts/r/partition_auto_increment_innodb.result b/mysql-test/suite/parts/r/partition_auto_increment_innodb.result index 3cec527c2a6..a65c646cca9 100644 --- a/mysql-test/suite/parts/r/partition_auto_increment_innodb.result +++ b/mysql-test/suite/parts/r/partition_auto_increment_innodb.result @@ -35,6 +35,12 @@ SET INSERT_ID = 30; INSERT INTO t1 VALUES (NULL); UPDATE t1 SET c1 = 50 WHERE c1 = 17; UPDATE t1 SET c1 = 51 WHERE c1 = 19; +FLUSH TABLES; +UPDATE t1 SET c1 = 40 WHERE c1 = 50; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; +AUTO_INCREMENT +31 UPDATE t1 SET c1 = NULL WHERE c1 = 4; INSERT INTO t1 VALUES (NULL); INSERT INTO t1 VALUES (NULL); @@ -52,7 +58,7 @@ c1 30 31 32 -50 +40 51 DROP TABLE t1; CREATE TABLE t1 ( @@ -110,6 +116,19 @@ t1 CREATE TABLE `t1` ( SELECT * FROM t1 ORDER BY c1; c1 1 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +DELETE FROM t1 WHERE c1 >= 100; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize note Table does not support optimize, doing recreate + analyze instead +test.t1 optimize status OK +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 DROP TABLE t1; # Simple test with NULL CREATE TABLE t1 ( @@ -187,6 +206,12 @@ INSERT INTO t1 VALUES (NULL), (90); INSERT INTO t1 VALUES (NULL); UPDATE t1 SET c1 = 150 WHERE c1 = 17; UPDATE t1 SET c1 = 151 WHERE c1 = 19; +FLUSH TABLES; +UPDATE t1 SET c1 = 140 WHERE c1 = 150; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; +AUTO_INCREMENT +141 UPDATE t1 SET c1 = NULL WHERE c1 = 4; INSERT INTO t1 VALUES (NULL); INSERT INTO t1 VALUES (NULL); @@ -207,10 +232,10 @@ c1 60 90 91 -150 +140 +141 +142 151 -152 -153 DROP TABLE t1; # Test with auto_increment_increment and auto_increment_offset. CREATE TABLE t1 ( @@ -353,6 +378,19 @@ t1 CREATE TABLE `t1` ( SELECT * FROM t1 ORDER BY c1; c1 1 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +DELETE FROM t1 WHERE c1 >= 100; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize note Table does not support optimize, doing recreate + analyze instead +test.t1 optimize status OK +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (c1) PARTITIONS 2 */ DROP TABLE t1; # Test with two threads # con default diff --git a/mysql-test/suite/parts/r/partition_auto_increment_memory.result b/mysql-test/suite/parts/r/partition_auto_increment_memory.result index 7a5d80c7758..24137c6c0e2 100644 --- a/mysql-test/suite/parts/r/partition_auto_increment_memory.result +++ b/mysql-test/suite/parts/r/partition_auto_increment_memory.result @@ -35,6 +35,12 @@ SET INSERT_ID = 30; INSERT INTO t1 VALUES (NULL); UPDATE t1 SET c1 = 50 WHERE c1 = 17; UPDATE t1 SET c1 = 51 WHERE c1 = 19; +FLUSH TABLES; +UPDATE t1 SET c1 = 40 WHERE c1 = 50; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; +AUTO_INCREMENT +52 UPDATE t1 SET c1 = NULL WHERE c1 = 4; INSERT INTO t1 VALUES (NULL); INSERT INTO t1 VALUES (NULL); @@ -50,7 +56,7 @@ c1 22 23 30 -50 +40 51 52 53 @@ -110,6 +116,18 @@ t1 CREATE TABLE `t1` ( SELECT * FROM t1 ORDER BY c1; c1 1 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +DELETE FROM t1 WHERE c1 >= 100; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize note The storage engine for the table doesn't support optimize +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=MEMORY AUTO_INCREMENT=102 DEFAULT CHARSET=latin1 DROP TABLE t1; # Simple test with NULL CREATE TABLE t1 ( @@ -187,6 +205,12 @@ INSERT INTO t1 VALUES (NULL), (90); INSERT INTO t1 VALUES (NULL); UPDATE t1 SET c1 = 150 WHERE c1 = 17; UPDATE t1 SET c1 = 151 WHERE c1 = 19; +FLUSH TABLES; +UPDATE t1 SET c1 = 140 WHERE c1 = 150; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; +AUTO_INCREMENT +152 UPDATE t1 SET c1 = NULL WHERE c1 = 4; INSERT INTO t1 VALUES (NULL); INSERT INTO t1 VALUES (NULL); @@ -207,7 +231,7 @@ c1 60 90 91 -150 +140 151 152 153 @@ -353,6 +377,18 @@ t1 CREATE TABLE `t1` ( SELECT * FROM t1 ORDER BY c1; c1 27 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +DELETE FROM t1 WHERE c1 >= 100; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize note The storage engine for the table doesn't support optimize +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=MEMORY AUTO_INCREMENT=102 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (c1) PARTITIONS 2 */ DROP TABLE t1; # Test with two threads # con default diff --git a/mysql-test/suite/parts/r/partition_auto_increment_myisam.result b/mysql-test/suite/parts/r/partition_auto_increment_myisam.result index 7ec76ee014c..2234f2ac7c1 100644 --- a/mysql-test/suite/parts/r/partition_auto_increment_myisam.result +++ b/mysql-test/suite/parts/r/partition_auto_increment_myisam.result @@ -35,6 +35,12 @@ SET INSERT_ID = 30; INSERT INTO t1 VALUES (NULL); UPDATE t1 SET c1 = 50 WHERE c1 = 17; UPDATE t1 SET c1 = 51 WHERE c1 = 19; +FLUSH TABLES; +UPDATE t1 SET c1 = 40 WHERE c1 = 50; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; +AUTO_INCREMENT +52 UPDATE t1 SET c1 = NULL WHERE c1 = 4; INSERT INTO t1 VALUES (NULL); INSERT INTO t1 VALUES (NULL); @@ -50,7 +56,7 @@ c1 22 23 30 -50 +40 51 52 53 @@ -110,6 +116,18 @@ t1 CREATE TABLE `t1` ( SELECT * FROM t1 ORDER BY c1; c1 1 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +DELETE FROM t1 WHERE c1 >= 100; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize status OK +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=MyISAM AUTO_INCREMENT=102 DEFAULT CHARSET=latin1 DROP TABLE t1; # Simple test with NULL CREATE TABLE t1 ( @@ -187,6 +205,12 @@ INSERT INTO t1 VALUES (NULL), (90); INSERT INTO t1 VALUES (NULL); UPDATE t1 SET c1 = 150 WHERE c1 = 17; UPDATE t1 SET c1 = 151 WHERE c1 = 19; +FLUSH TABLES; +UPDATE t1 SET c1 = 140 WHERE c1 = 150; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; +AUTO_INCREMENT +152 UPDATE t1 SET c1 = NULL WHERE c1 = 4; INSERT INTO t1 VALUES (NULL); INSERT INTO t1 VALUES (NULL); @@ -207,7 +231,7 @@ c1 60 90 91 -150 +140 151 152 153 @@ -353,6 +377,18 @@ t1 CREATE TABLE `t1` ( SELECT * FROM t1 ORDER BY c1; c1 27 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +DELETE FROM t1 WHERE c1 >= 100; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize status OK +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=MyISAM AUTO_INCREMENT=102 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (c1) PARTITIONS 2 */ DROP TABLE t1; # Test with two threads # con default diff --git a/mysql-test/suite/parts/r/partition_auto_increment_ndb.result b/mysql-test/suite/parts/r/partition_auto_increment_ndb.result index 37b46ef63ba..bced3a828a4 100644 --- a/mysql-test/suite/parts/r/partition_auto_increment_ndb.result +++ b/mysql-test/suite/parts/r/partition_auto_increment_ndb.result @@ -36,6 +36,12 @@ SET INSERT_ID = 30; INSERT INTO t1 VALUES (NULL); UPDATE t1 SET c1 = 50 WHERE c1 = 17; UPDATE t1 SET c1 = 51 WHERE c1 = 19; +FLUSH TABLES; +UPDATE t1 SET c1 = 40 WHERE c1 = 50; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; +AUTO_INCREMENT +52 UPDATE t1 SET c1 = NULL WHERE c1 = 4; INSERT INTO t1 VALUES (NULL); INSERT INTO t1 VALUES (NULL); @@ -51,7 +57,7 @@ c1 22 23 30 -50 +40 51 52 53 @@ -111,6 +117,18 @@ t1 CREATE TABLE `t1` ( SELECT * FROM t1 ORDER BY c1; c1 1 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +DELETE FROM t1 WHERE c1 >= 100; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize note The storage engine for the table doesn't support optimize +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 DROP TABLE t1; # Simple test with NULL CREATE TABLE t1 ( @@ -188,6 +206,12 @@ INSERT INTO t1 VALUES (NULL), (90); INSERT INTO t1 VALUES (NULL); UPDATE t1 SET c1 = 150 WHERE c1 = 17; UPDATE t1 SET c1 = 151 WHERE c1 = 19; +FLUSH TABLES; +UPDATE t1 SET c1 = 140 WHERE c1 = 150; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; +AUTO_INCREMENT +152 UPDATE t1 SET c1 = NULL WHERE c1 = 4; INSERT INTO t1 VALUES (NULL); INSERT INTO t1 VALUES (NULL); @@ -208,7 +232,7 @@ c1 60 90 91 -150 +140 151 152 153 @@ -354,6 +378,18 @@ t1 CREATE TABLE `t1` ( SELECT * FROM t1 ORDER BY c1; c1 1 +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +DELETE FROM t1 WHERE c1 >= 100; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize note The storage engine for the table doesn't support optimize +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (c1) PARTITIONS 2 */ DROP TABLE t1; # Test with two threads # con default diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 14e321218ca..47de9c50891 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -2996,17 +2996,6 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data) DBUG_PRINT("info", ("Update in partition %d", new_part_id)); tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */ error= m_file[new_part_id]->ha_update_row(old_data, new_data); - /* - if updating an auto_increment column, update - table_share->ha_data->next_auto_inc_val if needed. - (not to be used if auto_increment on secondary field in a multi- - column index) - mysql_update does not set table->next_number_field, so we use - table->found_next_number_field instead. - */ - if (table->found_next_number_field && new_data == table->record[0] && - !table->s->next_number_keypart) - set_auto_increment_if_higher(table->found_next_number_field->val_int()); reenable_binlog(thd); goto exit; } @@ -3016,9 +3005,6 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data) old_part_id, new_part_id)); tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */ error= m_file[new_part_id]->ha_write_row(new_data); - if (table->found_next_number_field && new_data == table->record[0] && - !table->s->next_number_keypart) - set_auto_increment_if_higher(table->found_next_number_field->val_int()); reenable_binlog(thd); if (error) goto exit; @@ -3036,6 +3022,22 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data) } exit: + /* + if updating an auto_increment column, update + table_share->ha_data->next_auto_inc_val if needed. + (not to be used if auto_increment on secondary field in a multi-column + index) + mysql_update does not set table->next_number_field, so we use + table->found_next_number_field instead. + */ + if (table->found_next_number_field && new_data == table->record[0] && + !table->s->next_number_keypart) + { + HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; + if (!ha_data->auto_inc_initialized) + info(HA_STATUS_AUTO); + set_auto_increment_if_higher(table->found_next_number_field->val_int()); + } table->timestamp_field_type= orig_timestamp_type; DBUG_RETURN(error); } diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 685f057dfce..31e5169ac7f 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -878,10 +878,10 @@ private: { HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; lock_auto_increment(); + DBUG_ASSERT(ha_data->auto_inc_initialized == TRUE); /* must check when the mutex is taken */ if (nr >= ha_data->next_auto_inc_val) ha_data->next_auto_inc_val= nr + 1; - ha_data->auto_inc_initialized= TRUE; unlock_auto_increment(); } From b72d1507db95326119afdcb4764fa457a7f888b7 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Wed, 29 Oct 2008 21:20:04 +0100 Subject: [PATCH 3/3] Bug#39084: Getting intermittent errors with statement-based binary logging Problem was that partitioning cached the table flags. These flags could change due to TRANSACTION LEVEL changes. Solution was to remove the cache and always return the table flags from the first partition (if the handler was initialized). mysql-test/r/partition_innodb_stmt.result: Bug#39084: Getting intermittent errors with statement-based binary logging New test result file. mysql-test/t/partition_innodb_stmt.test: Bug#39084: Getting intermittent errors with statement-based binary logging New test file. sql/ha_partition.cc: Bug#39084: Getting intermittent errors with statement-based binary logging Removed m_table_flags, and added m_handler_status. Added checks that all partitions have the same table flags. Moved some variable initializations. Updated some comments. Fixed typo initialise -> initialize Changed HA_EXTTA_NO_READCHECK to do nothing, since it is only used in ha_open, which is called for every partition in ::open anyway. sql/ha_partition.h: Bug#39084: Getting intermittent errors with statement-based binary logging Removed m_table_flags, and added m_handler_status. Always return the first partitions table flags, instead of using cached table flags. Added define of enabled/disabled partitioning table flags Fixed type initialise -> initialize Updated some comments. sql/handler.cc: Bug#39084: Getting intermittent errors with statement-based binary logging Fixed type initialise -> initialize. sql/handler.h: Bug#39084: Getting intermittent errors with statement-based binary logging Added comment to understand where the cached value is set. --- mysql-test/r/partition_innodb_stmt.result | 48 ++++++++++ mysql-test/t/partition_innodb_stmt.test | 59 ++++++++++++ sql/ha_partition.cc | 110 +++++++++++++--------- sql/ha_partition.h | 50 +++++++++- sql/handler.cc | 2 +- sql/handler.h | 3 + 6 files changed, 221 insertions(+), 51 deletions(-) create mode 100644 mysql-test/r/partition_innodb_stmt.result create mode 100644 mysql-test/t/partition_innodb_stmt.test diff --git a/mysql-test/r/partition_innodb_stmt.result b/mysql-test/r/partition_innodb_stmt.result new file mode 100644 index 00000000000..2735b0d2193 --- /dev/null +++ b/mysql-test/r/partition_innodb_stmt.result @@ -0,0 +1,48 @@ +# connection default +SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; +CREATE TABLE t1 +( +id SMALLINT NOT NULL, +PRIMARY KEY (id) +) ENGINE=innodb +PARTITION BY RANGE (id) +( +PARTITION p1 VALUES LESS THAN (2), +PARTITION p2 VALUES LESS THAN (4), +PARTITION p3 VALUES LESS THAN (10) +); +INSERT INTO t1 VALUES (1),(2),(3); +# Test READ COMMITTED -> REPEATABLE READ +FLUSH TABLES; +SET TRANSACTION ISOLATION LEVEL READ COMMITTED; +BEGIN; +SELECT * FROM t1; +id +1 +2 +3 +#connection con1 +SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +BEGIN; +INSERT INTO t1 VALUES(7); +COMMIT; +# connection default +COMMIT; +FLUSH TABLES; +# Test REPEATABLE READ -> READ COMMITTED +SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +BEGIN; +SELECT * FROM t1; +id +1 +2 +3 +7 +# connection con1 +SET TRANSACTION ISOLATION LEVEL READ COMMITTED; +BEGIN; +INSERT INTO t1 VALUES(9); +ERROR HY000: Binary logging not possible. Message: Transaction level 'READ-COMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT' +COMMIT; +COMMIT; +DROP TABLE t1; diff --git a/mysql-test/t/partition_innodb_stmt.test b/mysql-test/t/partition_innodb_stmt.test new file mode 100644 index 00000000000..2ed5baee0ac --- /dev/null +++ b/mysql-test/t/partition_innodb_stmt.test @@ -0,0 +1,59 @@ +--source include/have_binlog_format_statement.inc +--source include/have_innodb.inc + +--echo # connection default +SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; + +CREATE TABLE t1 +( + id SMALLINT NOT NULL, + PRIMARY KEY (id) +) ENGINE=innodb +PARTITION BY RANGE (id) +( + PARTITION p1 VALUES LESS THAN (2), + PARTITION p2 VALUES LESS THAN (4), + PARTITION p3 VALUES LESS THAN (10) +); + +INSERT INTO t1 VALUES (1),(2),(3); + +--echo # Test READ COMMITTED -> REPEATABLE READ +FLUSH TABLES; +SET TRANSACTION ISOLATION LEVEL READ COMMITTED; +BEGIN; +SELECT * FROM t1; + +connect (con1, localhost, root,,); +connection con1; + +--echo #connection con1 +SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +BEGIN; +INSERT INTO t1 VALUES(7); +COMMIT; + +connection default; +--echo # connection default +COMMIT; + +FLUSH TABLES; + +--echo # Test REPEATABLE READ -> READ COMMITTED +SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +BEGIN; +SELECT * FROM t1; + +connection con1; + +--echo # connection con1 +SET TRANSACTION ISOLATION LEVEL READ COMMITTED; +BEGIN; +--error ER_BINLOG_LOGGING_IMPOSSIBLE +INSERT INTO t1 VALUES(9); +COMMIT; + +disconnect con1; +connection default; +COMMIT; +DROP TABLE t1; diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 14e321218ca..6a2cd906671 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -107,7 +107,7 @@ static handler *partition_create_handler(handlerton *hton, MEM_ROOT *mem_root) { ha_partition *file= new (mem_root) ha_partition(hton, share); - if (file && file->initialise_partition(mem_root)) + if (file && file->initialize_partition(mem_root)) { delete file; file= 0; @@ -160,8 +160,7 @@ const uint ha_partition::NO_CURRENT_PART_ID= 0xFFFFFFFF; ha_partition::ha_partition(handlerton *hton, TABLE_SHARE *share) :handler(hton, share), m_part_info(NULL), m_create_handler(FALSE), - m_is_sub_partitioned(0), is_clone(FALSE), auto_increment_lock(FALSE), - auto_increment_safe_stmt_log_lock(FALSE) + m_is_sub_partitioned(0) { DBUG_ENTER("ha_partition::ha_partition(table)"); init_handler_variables(); @@ -181,10 +180,8 @@ ha_partition::ha_partition(handlerton *hton, TABLE_SHARE *share) */ ha_partition::ha_partition(handlerton *hton, partition_info *part_info) - :handler(hton, NULL), m_part_info(part_info), - m_create_handler(TRUE), - m_is_sub_partitioned(m_part_info->is_sub_partitioned()), is_clone(FALSE), - auto_increment_lock(FALSE), auto_increment_safe_stmt_log_lock(FALSE) + :handler(hton, NULL), m_part_info(part_info), m_create_handler(TRUE), + m_is_sub_partitioned(m_part_info->is_sub_partitioned()) { DBUG_ENTER("ha_partition::ha_partition(part_info)"); init_handler_variables(); @@ -194,7 +191,7 @@ ha_partition::ha_partition(handlerton *hton, partition_info *part_info) /* - Initialise handler object + Initialize handler object SYNOPSIS init_handler_variables() @@ -231,7 +228,7 @@ void ha_partition::init_handler_variables() m_innodb= FALSE; m_extra_cache= FALSE; m_extra_cache_size= 0; - m_table_flags= HA_FILE_BASED | HA_REC_NOT_IN_SEQ; + m_handler_status= handler_not_initialized; m_low_byte_first= 1; m_part_field_array= NULL; m_ordered_rec_buffer= NULL; @@ -240,6 +237,9 @@ void ha_partition::init_handler_variables() m_last_part= 0; m_rec0= 0; m_curr_key_info= 0; + is_clone= FALSE, + auto_increment_lock= FALSE; + auto_increment_safe_stmt_log_lock= FALSE; /* this allows blackhole to work properly */ @@ -286,10 +286,10 @@ ha_partition::~ha_partition() /* - Initialise partition handler object + Initialize partition handler object SYNOPSIS - initialise_partition() + initialize_partition() mem_root Allocate memory through this RETURN VALUE @@ -319,8 +319,8 @@ ha_partition::~ha_partition() normal storage engine The flag HA_FILE_BASED will be set independent of the underlying handlers 4) Index flags initialisation - When knowledge exists on the indexes it is also possible to initialise the - index flags. Again the index flags must be initialised by using the under- + When knowledge exists on the indexes it is also possible to initialize the + index flags. Again the index flags must be initialized by using the under- lying handlers since this is storage engine dependent. The flag HA_READ_ORDER will be reset for the time being to indicate no ordered output is available from partition handler indexes. Later a merge @@ -330,10 +330,11 @@ ha_partition::~ha_partition() */ -bool ha_partition::initialise_partition(MEM_ROOT *mem_root) +bool ha_partition::initialize_partition(MEM_ROOT *mem_root) { handler **file_array, *file; - DBUG_ENTER("ha_partition::initialise_partition"); + ulonglong check_table_flags; + DBUG_ENTER("ha_partition::initialize_partition"); if (m_create_handler) { @@ -345,11 +346,9 @@ bool ha_partition::initialise_partition(MEM_ROOT *mem_root) else if (!table_share || !table_share->normalized_path.str) { /* - Called with dummy table share (delete, rename and alter table) - Don't need to set-up table flags other than - HA_FILE_BASED here + Called with dummy table share (delete, rename and alter table). + Don't need to set-up anything. */ - m_table_flags|= HA_FILE_BASED | HA_REC_NOT_IN_SEQ; DBUG_RETURN(0); } else if (get_from_handler_file(table_share->normalized_path.str, mem_root)) @@ -361,15 +360,12 @@ bool ha_partition::initialise_partition(MEM_ROOT *mem_root) We create all underlying table handlers here. We do it in this special method to be able to report allocation errors. - Set up table_flags, low_byte_first, primary_key_is_clustered and + Set up low_byte_first, primary_key_is_clustered and has_transactions since they are called often in all kinds of places, other parameters are calculated on demand. - HA_FILE_BASED is always set for partition handler since we use a - special file for handling names of partitions, engine types. - HA_CAN_GEOMETRY, HA_CAN_FULLTEXT, HA_CAN_SQL_HANDLER, HA_DUPLICATE_POS, - HA_CAN_INSERT_DELAYED is disabled until further investigated. + Verify that all partitions have the same table_flags. */ - m_table_flags= (ulong)m_file[0]->ha_table_flags(); + check_table_flags= m_file[0]->ha_table_flags(); m_low_byte_first= m_file[0]->low_byte_first(); m_pkey_is_clustered= TRUE; file_array= m_file; @@ -384,12 +380,13 @@ bool ha_partition::initialise_partition(MEM_ROOT *mem_root) } if (!file->primary_key_is_clustered()) m_pkey_is_clustered= FALSE; - m_table_flags&= file->ha_table_flags(); + if (check_table_flags != file->ha_table_flags()) + { + my_error(ER_MIX_HANDLER_ERROR, MYF(0)); + DBUG_RETURN(1); + } } while (*(++file_array)); - m_table_flags&= ~(HA_CAN_GEOMETRY | HA_CAN_FULLTEXT | HA_DUPLICATE_POS | - HA_CAN_SQL_HANDLER | HA_CAN_INSERT_DELAYED | - HA_PRIMARY_KEY_REQUIRED_FOR_POSITION); - m_table_flags|= HA_FILE_BASED | HA_REC_NOT_IN_SEQ; + m_handler_status= handler_initialized; DBUG_RETURN(0); } @@ -2410,6 +2407,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) handler **file; char name_buff[FN_REFLEN]; bool is_not_tmp_table= (table_share->tmp_table == NO_TMP_TABLE); + ulonglong check_table_flags= 0; DBUG_ENTER("ha_partition::open"); DBUG_ASSERT(table->s == table_share); @@ -2449,7 +2447,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) } } - /* Initialise the bitmap we use to determine what partitions are used */ + /* Initialize the bitmap we use to determine what partitions are used */ if (!is_clone) { if (bitmap_init(&(m_part_info->used_partitions), NULL, m_tot_parts, TRUE)) @@ -2457,8 +2455,6 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) bitmap_set_all(&(m_part_info->used_partitions)); } - /* Recalculate table flags as they may change after open */ - m_table_flags= m_file[0]->ha_table_flags(); file= m_file; do { @@ -2470,11 +2466,26 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) m_no_locks+= (*file)->lock_count(); name_buffer_ptr+= strlen(name_buffer_ptr) + 1; set_if_bigger(ref_length, ((*file)->ref_length)); - m_table_flags&= (*file)->ha_table_flags(); + /* + Verify that all partitions have the same set of table flags. + Mask all flags that partitioning enables/disables. + */ + if (!check_table_flags) + { + check_table_flags= (((*file)->ha_table_flags() & + ~(PARTITION_DISABLED_TABLE_FLAGS)) | + (PARTITION_ENABLED_TABLE_FLAGS)); + } + else if (check_table_flags != (((*file)->ha_table_flags() & + ~(PARTITION_DISABLED_TABLE_FLAGS)) | + (PARTITION_ENABLED_TABLE_FLAGS))) + { + DBUG_PRINT("error", ("check_table_flag 0x%x != 0x%x table_flags()", + check_table_flags, (*file)->ha_table_flags())); + error= HA_ERR_INITIALIZATION; + goto err_handler; + } } while (*(++file)); - m_table_flags&= ~(HA_CAN_GEOMETRY | HA_CAN_FULLTEXT | HA_DUPLICATE_POS | - HA_CAN_SQL_HANDLER | HA_CAN_INSERT_DELAYED); - m_table_flags|= HA_FILE_BASED | HA_REC_NOT_IN_SEQ; key_used_on_scan= m_file[0]->key_used_on_scan; implicit_emptied= m_file[0]->implicit_emptied; /* @@ -2489,7 +2500,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) */ clear_handler_file(); /* - Initialise priority queue, initialised to reading forward. + Initialize priority queue, initialized to reading forward. */ if ((error= init_queue(&m_queue, m_tot_parts, (uint) PARTITION_BYTES_IN_POS, 0, key_rec_cmp, (void*)this))) @@ -2525,6 +2536,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) to ensure we have correct statistics we call info from open after calling open on all individual handlers. */ + m_handler_status= handler_opened; info(HA_STATUS_VARIABLE | HA_STATUS_CONST); DBUG_RETURN(0); @@ -2595,6 +2607,7 @@ repeat: goto repeat; } + m_handler_status= handler_closed; DBUG_RETURN(0); } @@ -3582,7 +3595,7 @@ int ha_partition::rnd_pos_by_record(uchar *record) */ /* - Initialise handler before start of index scan + Initialize handler before start of index scan SYNOPSIS index_init() @@ -4442,7 +4455,7 @@ int ha_partition::handle_ordered_index_scan(uchar *buf, bool reverse_order) { found= TRUE; /* - Initialise queue without order first, simply insert + Initialize queue without order first, simply insert */ queue_element(&m_queue, j++)= (uchar*)queue_buf(i); } @@ -4763,7 +4776,7 @@ int ha_partition::info(uint flag) } } while (*(++file_array)); if (stats.records < 2 && - !(m_table_flags & HA_STATS_RECORDS_IS_EXACT)) + !(m_file[0]->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT)) stats.records= 2; if (stats.records > 0) stats.mean_rec_length= (ulong) (stats.data_file_length / stats.records); @@ -5137,7 +5150,7 @@ void ha_partition::get_dynamic_partition_info(PARTITION_INFO *stat_info, 5) Parameters only used by MyISAM internally -------------------------------------------- HA_EXTRA_REINIT_CACHE: - This call reinitialises the READ CACHE described above if there is one + This call reinitializes the READ CACHE described above if there is one and otherwise the call is ignored. We can thus safely call it on all underlying handlers if they are @@ -5219,7 +5232,6 @@ int ha_partition::extra(enum ha_extra_function operation) break; case HA_EXTRA_NORMAL: case HA_EXTRA_QUICK: - case HA_EXTRA_NO_READCHECK: case HA_EXTRA_PREPARE_FOR_UPDATE: case HA_EXTRA_FORCE_REOPEN: case HA_EXTRA_PREPARE_FOR_DROP: @@ -5229,6 +5241,14 @@ int ha_partition::extra(enum ha_extra_function operation) DBUG_RETURN(loop_extra(operation)); break; } + case HA_EXTRA_NO_READCHECK: + { + /* + This is only done as a part of ha_open, which is also used in + ha_partition::open, so no need to do anything. + */ + break; + } case HA_EXTRA_CACHE: { prepare_extra_cache(0); @@ -6057,7 +6077,7 @@ void ha_partition::release_auto_increment() } /**************************************************************************** - MODULE initialise handler for HANDLER call + MODULE initialize handler for HANDLER call ****************************************************************************/ void ha_partition::init_table_handle_for_HANDLER() @@ -6150,7 +6170,7 @@ int ha_partition::indexes_are_disabled(void) ------------------------------------------------------------------------- Variables for partition share methods. A hash used to track open tables. A mutex for the hash table and an init variable to check if hash table - is initialised. + is initialized. There is also a constant ending of the partition handler file name. */ diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 685f057dfce..2cb1e83de91 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -48,6 +48,13 @@ typedef struct st_ha_data_partition } HA_DATA_PARTITION; #define PARTITION_BYTES_IN_POS 2 +#define PARTITION_ENABLED_TABLE_FLAGS (HA_FILE_BASED | HA_REC_NOT_IN_SEQ) +#define PARTITION_DISABLED_TABLE_FLAGS (HA_CAN_GEOMETRY | \ + HA_CAN_FULLTEXT | \ + HA_DUPLICATE_POS | \ + HA_CAN_SQL_HANDLER | \ + HA_CAN_INSERT_DELAYED | \ + HA_PRIMARY_KEY_REQUIRED_FOR_POSITION) class ha_partition :public handler { private: @@ -85,8 +92,15 @@ private: for this since the MySQL Server sometimes allocating the handler object without freeing them. */ - longlong m_table_flags; ulong m_low_byte_first; + enum enum_handler_status + { + handler_not_initialized= 0, + handler_initialized, + handler_opened, + handler_closed + }; + enum_handler_status m_handler_status; uint m_reorged_parts; // Number of reorganised parts uint m_tot_parts; // Total number of partitions; @@ -182,7 +196,7 @@ public: enable later calls of the methods to retrieve constants from the under- lying handlers. Returns false if not successful. */ - bool initialise_partition(MEM_ROOT *mem_root); + bool initialize_partition(MEM_ROOT *mem_root); /* ------------------------------------------------------------------------- @@ -585,6 +599,8 @@ public: The partition handler will support whatever the underlying handlers support except when specifically mentioned below about exceptions to this rule. + NOTE: This cannot be cached since it can depend on TRANSACTION ISOLATION + LEVEL which is dynamic, see bug#39084. HA_READ_RND_SAME: Not currently used. (Means that the handler supports the rnd_same() call) @@ -709,9 +725,33 @@ public: transfer those calls into index_read and other calls in the index scan module. (NDB) + + HA_PRIMARY_KEY_REQUIRED_FOR_POSITION: + Does the storage engine need a PK for position? + Used with hidden primary key in InnoDB. + Hidden primary keys cannot be supported by partitioning, since the + partitioning expressions columns must be a part of the primary key. + (InnoDB) + + HA_FILE_BASED is always set for partition handler since we use a + special file for handling names of partitions, engine types. + HA_REC_NOT_IN_SEQ is always set for partition handler since we cannot + guarantee that the records will be returned in sequence. + HA_CAN_GEOMETRY, HA_CAN_FULLTEXT, HA_CAN_SQL_HANDLER, HA_DUPLICATE_POS, + HA_CAN_INSERT_DELAYED, HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is disabled + until further investigated. */ - virtual ulonglong table_flags() const - { return m_table_flags; } + virtual Table_flags table_flags() const + { + DBUG_ENTER("ha_partition::table_flags"); + if (m_handler_status < handler_initialized || + m_handler_status >= handler_closed) + DBUG_RETURN(PARTITION_ENABLED_TABLE_FLAGS); + else + DBUG_RETURN((m_file[0]->ha_table_flags() & + ~(PARTITION_DISABLED_TABLE_FLAGS)) | + (PARTITION_ENABLED_TABLE_FLAGS)); + } /* This is a bitmap of flags that says how the storage engine @@ -889,7 +929,7 @@ public: /* ------------------------------------------------------------------------- - MODULE initialise handler for HANDLER call + MODULE initialize handler for HANDLER call ------------------------------------------------------------------------- This method is a special InnoDB method called before a HANDLER query. ------------------------------------------------------------------------- diff --git a/sql/handler.cc b/sql/handler.cc index a988c34b7ca..d3ddc60d3b9 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -263,7 +263,7 @@ handler *get_ha_partition(partition_info *part_info) DBUG_ENTER("get_ha_partition"); if ((partition= new ha_partition(partition_hton, part_info))) { - if (partition->initialise_partition(current_thd->mem_root)) + if (partition->initialize_partition(current_thd->mem_root)) { delete partition; partition= 0; diff --git a/sql/handler.h b/sql/handler.h index b7d4d689d40..b8e7f17e089 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1198,6 +1198,9 @@ public: { return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0; } + /** + The cached_table_flags is set at ha_open and ha_external_lock + */ Table_flags ha_table_flags() const { return cached_table_flags; } /** These functions represent the public interface to *users* of the