mirror of
https://github.com/MariaDB/server.git
synced 2026-05-10 00:54:30 +02:00
Fix for MDEV-533: Confusing error code when doing auto-increment insert for out-of-range values
create table t1 (a smallint primary key auto_increment); insert into t1 values(32767); insert into t1 values(NULL); ERROR 1062 (23000): Duplicate entry '32767' for key 'PRIMARY Now on always gets error HA_ERR_AUTOINC_RANGE=167 "Out of range value for column", independent of store engine, SQL Mode or number of inserted rows. This is an unique error that is easier to test for in replication. Another bug fix is that we now get an error when trying to insert a too big auto-generated value, even in non-strict mode. Before one get insted the max column value inserted. This patch also fixes some issues with inserting negative numbers in an auto-increment column. Fixed the ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. Added SQLSTATE errors for handler errors Smaller bug fixes: * Added warnings for duplicate key errors when using INSERT IGNORE * Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" * Allow one to see how cmake is called by using --just-print --just-configure BUILD/FINISH.sh: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. cmake/configure.pl: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. include/CMakeLists.txt: Added handler_state.h include/handler_state.h: SQLSTATE for handler error messages. Required for HA_ERR_AUTOINC_ERANGE, but solves also some other cases. mysql-test/extra/binlog_tests/binlog.test: Fixed old wrong behaviour Added more tests mysql-test/extra/binlog_tests/binlog_insert_delayed.test: Reset binary log to only print what's necessary in show_binlog_events mysql-test/extra/rpl_tests/rpl_auto_increment.test: Update to new error codes mysql-test/extra/rpl_tests/rpl_insert_delayed.test: Ignore warnings as this depends on how the test is run mysql-test/include/strict_autoinc.inc: On now gets an error on overflow mysql-test/r/auto_increment.result: Update results after fixing error message mysql-test/r/auto_increment_ranges_innodb.result: Test new behaviour mysql-test/r/auto_increment_ranges_myisam.result: Test new behaviour mysql-test/r/commit_1innodb.result: Added warnings for duplicate key error mysql-test/r/create.result: Added warnings for duplicate key error mysql-test/r/insert.result: Added warnings for duplicate key error mysql-test/r/insert_select.result: Added warnings for duplicate key error mysql-test/r/insert_update.result: Added warnings for duplicate key error mysql-test/r/mix2_myisam.result: Added warnings for duplicate key error mysql-test/r/myisam_mrr.result: Added warnings for duplicate key error mysql-test/r/null_key.result: Added warnings for duplicate key error mysql-test/r/replace.result: Update to new error codes mysql-test/r/strict_autoinc_1myisam.result: Update to new error codes mysql-test/r/strict_autoinc_2innodb.result: Update to new error codes mysql-test/r/strict_autoinc_3heap.result: Update to new error codes mysql-test/r/trigger.result: Added warnings for duplicate key error mysql-test/r/xtradb_mrr.result: Added warnings for duplicate key error mysql-test/suite/binlog/r/binlog_innodb_row.result: Updated result mysql-test/suite/binlog/r/binlog_row_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result: Updated result mysql-test/suite/binlog/r/binlog_stm_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_unsafe.result: Updated result mysql-test/suite/innodb/r/innodb-autoinc.result: Update to new error codes mysql-test/suite/innodb/r/innodb-lock.result: Updated results mysql-test/suite/innodb/r/innodb.result: Updated results mysql-test/suite/innodb/r/innodb_bug56947.result: Updated results mysql-test/suite/innodb/r/innodb_mysql.result: Updated results mysql-test/suite/innodb/t/innodb-autoinc.test: Update to new error codes mysql-test/suite/maria/maria3.result: Updated result mysql-test/suite/maria/mrr.result: Updated result mysql-test/suite/optimizer_unfixed_bugs/r/bug43617.result: Updated result mysql-test/suite/rpl/r/rpl_auto_increment.result: Update to new error codes mysql-test/suite/rpl/r/rpl_insert_delayed,stmt.rdiff: Updated results mysql-test/suite/rpl/r/rpl_loaddatalocal.result: Updated results mysql-test/t/auto_increment.test: Update to new error codes mysql-test/t/auto_increment_ranges.inc: Test new behaviour mysql-test/t/auto_increment_ranges_innodb.test: Test new behaviour mysql-test/t/auto_increment_ranges_myisam.test: Test new behaviour mysql-test/t/replace.test: Update to new error codes mysys/my_getopt.c: Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" sql/handler.cc: Ignore negative values for signed auto-increment columns Always give an error if we get an overflow for an auto-increment-column (instead of inserting the max value) Ensure that the row number is correct for the out-of-range-value error message. ****** Fixed wrong printing of column namn for "Out of range value" errors Fixed that INSERT_ID is correctly replicated also for out-of-range autoincrement values Fixed that print_keydup_error() can also be used to generate warnings ****** Return HA_ERR_AUTOINC_ERANGE (167) instead of ER_WARN_DATA_OUT_OF_RANGE for auto-increment overflow sql/handler.h: Allow INSERT IGNORE to continue also after out-of-range inserts. Fixed that print_keydup_error() can also be used to generate warnings sql/log_event.cc: Added DBUG_PRINT Fixed the ER_AUTOINC_READ_FAILED, ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. sql/sql_insert.cc: Add warnings for duplicate key errors when using INSERT IGNORE sql/sql_state.c: Added handler errors sql/sql_table.cc: Update call to print_keydup_error() storage/innobase/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB. storage/xtradb/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB.
This commit is contained in:
parent
32e4c7e138
commit
ae5bc05988
57 changed files with 1222 additions and 167 deletions
|
|
@ -205,16 +205,55 @@ DROP PROCEDURE p4;
|
|||
|
||||
--echo End of 5.0 tests
|
||||
|
||||
# Test of a too big SET INSERT_ID: see if the truncated value goes
|
||||
# into binlog (right), or the too big value (wrong); we look at the
|
||||
# binlog further down with SHOW BINLOG EVENTS.
|
||||
# Test of a too big SET INSERT_ID.
|
||||
# This should generate an error and should not be put in binlog
|
||||
# We look at the binlog further down with SHOW BINLOG EVENTS.
|
||||
|
||||
reset master;
|
||||
create table t1 (id tinyint auto_increment primary key);
|
||||
insert into t1 values(5);
|
||||
set insert_id=128;
|
||||
insert into t1 values(null);
|
||||
--error 167
|
||||
insert into t1 values(null) /* Not binlogged */;
|
||||
|
||||
# The followin insert ignore will be put in binlog
|
||||
set insert_id=128;
|
||||
insert ignore into t1 values(null) /* Insert 128 */;
|
||||
|
||||
# Insert with duplicate key error should not go into binglo
|
||||
set insert_id=5;
|
||||
--error ER_DUP_ENTRY
|
||||
insert into t1 values(null) /* Not binlogged */;
|
||||
|
||||
# Insert with autogenerated key + duplicate key error should go into binlog
|
||||
set insert_id=5;
|
||||
insert ignore into t1 values(null) /* Insert 5 */;
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
|
||||
# Same tests but with 2 rows inserted at a time
|
||||
|
||||
create table t1 (id tinyint auto_increment primary key) engine=myisam;
|
||||
set insert_id=128;
|
||||
--error 167
|
||||
insert into t1 values(5),(null) /* Insert_id 128 */;
|
||||
|
||||
# The followin insert ignore will be put in binlog
|
||||
set insert_id=128;
|
||||
insert ignore into t1 values (4),(null) /* Insert_id 128 */;
|
||||
|
||||
# Insert with duplicate key error should not go into binglo
|
||||
set insert_id=5;
|
||||
--error ER_DUP_ENTRY
|
||||
insert into t1 values(3),(null) /* Insert_id 5 */;
|
||||
|
||||
# Insert with autogenerated key + duplicate key error should go into binlog
|
||||
set insert_id=5;
|
||||
insert ignore into t1 values(2),(null) /* Insert_id 5 */;
|
||||
select * from t1 order by id;
|
||||
drop table t1;
|
||||
|
||||
|
||||
# bug#22027
|
||||
create table t1 (a int);
|
||||
create table if not exists t2 select * from t1;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
# BUG#20627: INSERT DELAYED does not honour auto_increment_* variables
|
||||
# Bug in this test: BUG#38068: binlog_stm_binlog fails sporadically in pushbuild
|
||||
|
||||
reset master;
|
||||
|
||||
create table t1 (a int not null auto_increment, primary key (a)) engine=myisam;
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ set auto_increment_increment=11;
|
|||
set auto_increment_offset=4;
|
||||
insert into t1 values(null);
|
||||
insert into t1 values(null);
|
||||
--error ER_DUP_ENTRY
|
||||
--error 167
|
||||
insert into t1 values(null);
|
||||
select a, mod(a-@@auto_increment_offset,@@auto_increment_increment) from t1 order by a;
|
||||
|
||||
|
|
@ -120,6 +120,8 @@ create table t2 (a tinyint unsigned not null auto_increment primary key) engine=
|
|||
set auto_increment_increment=10;
|
||||
set auto_increment_offset=1;
|
||||
set insert_id=1000;
|
||||
insert into t2 values(10);
|
||||
--error 167
|
||||
insert into t2 values(null);
|
||||
select a, mod(a-@@auto_increment_offset,@@auto_increment_increment) from t2 order by a;
|
||||
|
||||
|
|
@ -127,6 +129,7 @@ select a, mod(a-@@auto_increment_offset,@@auto_increment_increment) from t2 orde
|
|||
create table t3 like t1;
|
||||
set auto_increment_increment=1000;
|
||||
set auto_increment_offset=700;
|
||||
--error 167
|
||||
insert into t3 values(null);
|
||||
select * from t3 order by a;
|
||||
sync_slave_with_master;
|
||||
|
|
|
|||
|
|
@ -102,7 +102,9 @@ CREATE TABLE t1(a int, UNIQUE(a));
|
|||
--let $_start= query_get_value(SHOW MASTER STATUS, Position, 1)
|
||||
|
||||
INSERT DELAYED IGNORE INTO t1 VALUES(1);
|
||||
--disable_warnings
|
||||
INSERT DELAYED IGNORE INTO t1 VALUES(1);
|
||||
--enable_warnings
|
||||
flush table t1; # to wait for INSERT DELAYED to be done
|
||||
if (`SELECT @@global.binlog_format = 'STATEMENT'`)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue