diff options
author | Ramil Kalimullin <ramil@mysql.com> | 2008-09-03 15:17:19 +0500 |
---|---|---|
committer | Ramil Kalimullin <ramil@mysql.com> | 2008-09-03 15:17:19 +0500 |
commit | f0a50bd969fe707c5e210d321c197adb38cf250b (patch) | |
tree | 08bc35454926b84d4309eaa63e52c470e147bb74 | |
parent | 31d76e8d526da59070f0c75cae0b9672c11a1b03 (diff) | |
download | mariadb-git-f0a50bd969fe707c5e210d321c197adb38cf250b.tar.gz |
Fix for bug#38821: Assert table->auto_increment_field_not_null failed
in open_table()
Problem: repeating "CREATE... ( AUTOINCREMENT) ... SELECT" may lead to
an assertion failure.
Fix: reset table->auto_increment_field_not_null after each record
writing.
mysql-test/r/create.result:
Fix for bug#38821: Assert table->auto_increment_field_not_null failed
in open_table()
- test result.
mysql-test/t/create.test:
Fix for bug#38821: Assert table->auto_increment_field_not_null failed
in open_table()
- test case.
sql/sql_insert.cc:
Fix for bug#38821: Assert table->auto_increment_field_not_null failed
in open_table()
- reset table->auto_increment_field_not_null after writing a record
for "{CREATE, INSERT}..SELECT".
-rw-r--r-- | mysql-test/r/create.result | 11 | ||||
-rw-r--r-- | mysql-test/t/create.test | 18 | ||||
-rw-r--r-- | sql/sql_insert.cc | 6 |
3 files changed, 34 insertions, 1 deletions
diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 53c2058f3ec..2d668499df3 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -1546,4 +1546,15 @@ SHOW INDEX FROM t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 1 c1 1 c1 A NULL NULL NULL YES BTREE DROP TABLE t1; +CREATE TABLE t1 (a INTEGER AUTO_INCREMENT PRIMARY KEY, b INTEGER NOT NULL); +INSERT IGNORE INTO t1 (b) VALUES (5); +CREATE TABLE IF NOT EXISTS t2 (a INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY) +SELECT a FROM t1; +CREATE TABLE IF NOT EXISTS t2 (a INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY) +SELECT a FROM t1; +ERROR 23000: Duplicate entry '1' for key 1 +CREATE TABLE IF NOT EXISTS t2 (a INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY) +SELECT a FROM t1; +ERROR 23000: Duplicate entry '1' for key 1 +DROP TABLE t1, t2; End of 5.0 tests diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 97a7ea71b29..61ee40477ee 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -1172,4 +1172,22 @@ SHOW INDEX FROM t1; DROP TABLE t1; +# +# Bug#38821: Assert table->auto_increment_field_not_null failed in open_table() +# +CREATE TABLE t1 (a INTEGER AUTO_INCREMENT PRIMARY KEY, b INTEGER NOT NULL); +INSERT IGNORE INTO t1 (b) VALUES (5); + +CREATE TABLE IF NOT EXISTS t2 (a INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY) + SELECT a FROM t1; +--error 1062 +CREATE TABLE IF NOT EXISTS t2 (a INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY) + SELECT a FROM t1; +--error 1062 +CREATE TABLE IF NOT EXISTS t2 (a INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY) + SELECT a FROM t1; + +DROP TABLE t1, t2; + + --echo End of 5.0 tests diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 746a04e03f3..3f43c902faa 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2897,7 +2897,11 @@ bool select_insert::send_data(List<Item> &values) DBUG_RETURN(1); } } - if (!(error= write_record(thd, table, &info))) + + error= write_record(thd, table, &info); + table->auto_increment_field_not_null= FALSE; + + if (!error) { if (table->triggers || info.handle_duplicates == DUP_UPDATE) { |