1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

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
This commit is contained in:
Mattias Jonsson
2008-10-23 22:14:07 +02:00
parent fee8a478f7
commit 620d955e3a
9 changed files with 259 additions and 25 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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