diff options
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(); } |