[MDEV-533] Confusing error code when doing auto-increment insert for out-of-range values Created: 2012-09-13 Updated: 2022-09-18 Due: 2012-09-18 Resolved: 2012-09-18 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.5.28, 5.3.8, 5.2.13, 5.1.62 |
| Fix Version/s: | 5.5.28 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Michael Widenius | Assignee: | Michael Widenius |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
All |
||
| Description |
|
When one inserts a row into a table with auto-increment, the error message create table t1 (a smallint primary key auto_increment); In some cases on gets: The task is to ensure that all engines works exactly the same way and that one will always get: To fix this one need to do changes in sql/handler.cc Because of how the auto_increment checking is done, we can fix all issues In this case all engines will report: Another effect of this is that for columns of type bigint unsigned, the max generated auto increment value is 18446744073709551614 |
| Comments |
| Comment by Michael Widenius [ 2012-09-13 ] | ||
|
Fix for this is now pushed into maria-5.5-monty tree | ||
| Comment by Elena Stepanova [ 2012-09-15 ] | ||
|
The following diff in revno 3535 on maria-5.5-monty shows a problem. INSERT_ID is gone from the binary log; it means that a slave will treat the INSERT IGNORE statement with the standard INSERT_ID (in this case, 1), and thus will insert a value successfully, while on master it was ignored; so, we'll have a data discrepancy between master and slave. +++ mysql-test/suite/binlog/r/binlog_stm_binlog.result 2012-09-13 19:04:10 +0000 | ||
| Comment by Elena Stepanova [ 2012-09-16 ] | ||
|
In the scenario below, with the old version the 2nd INSERT succeeds (without any warnings) and inserts 127, while with the new version it fails with "Out of range value". The reason is that after the first INSERT with the old version AUTO_INCREMENT value on the table is set to 127, while with the old version – to 128. The latter (128) is more logical of the two, so I don't think it's a big deal since it's only one value that we can theoretically lose in a rather unlikely scenario, but technically it can be considered a regression. New version: drop table if exists t1;
create table t1 (i tinyint auto_increment primary key) engine=innodb;
insert into t1 values (127),(null);
insert into t1 values (null);
select * from t1;
Old version: drop table if exists t1;
create table t1 (i tinyint auto_increment primary key) engine=innodb;
insert into t1 values (127),(null);
insert into t1 values (null);
select * from t1;
For a note, I find the behavior in general somewhat unfortunate – one could expect that the AUTO_INCREMENT value wouldn't change at all if the INSERT didn't succeed; but even if it can be improved, it goes far beyond the scope of this task. | ||
| Comment by Elena Stepanova [ 2012-09-16 ] | ||
|
As a nice side-effect, this patch fixes a crash which happens on MySQL/MariaDB 5.5 with the following scenario: CREATE TABLE t1 (i TINYINT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB AUTO_INCREMENT=128; On maria-5.5 revno 3533, mysql-5.5.27: InnoDB: Assertion failure in thread 140005269079808 in file ha_innodb.cc line 1478 On maria-5.5-monty revno 3535: Out of range value for column 't1' at row 1 | ||
| Comment by Elena Stepanova [ 2012-09-17 ] | ||
|
Replication old master (5.5.27 and earlier) => new slave (maria-5.5-monty) breaks due to the different error code: On master: drop table if exists t3;
On slave:
[ERROR] Slave SQL: Query caused different errors on master and slave. Error on master: message (format)='Duplicate entry '%-.192s' for key %d' error code=1062 ; Error on slave: actual message='Out of range value for column 't3' at row 3', error code=1264. Default database: 'test'. Query: 'insert into t3 values (126),(null),(null)', Error_code: 0 | ||
| Comment by Elena Stepanova [ 2012-09-17 ] | ||
|
The "out of range" error message contains wrong data: table name instead of a column name: create table t1 (i tinyint auto_increment primary key);
| ||
| Comment by Michael Widenius [ 2012-09-17 ] | ||
|
Regarding the comment about that we now get an out-of-range error when trying to do insert a too big value in an auto-increment column instead of getting the 'max allowed value' inserted. | ||
| Comment by Michael Widenius [ 2012-09-17 ] | ||
|
New patch pushed into maria-5.5-monty. This includes a patch for the wrong usage of table names. | ||
| Comment by Michael Widenius [ 2012-09-18 ] | ||
|
I have now fixed the problem with replication from old master to new slave so that ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are regarded as equal errors. | ||
| Comment by Elena Stepanova [ 2012-09-18 ] | ||
|
Checked on revno 3540, all of OM=>NS replication problem, missing INSERT_ID and the column name are fixed now; no new problems have been found so far. I think the patch can be pushed into maria/5.5 now. | ||
| Comment by Michael Widenius [ 2012-09-18 ] | ||
|
4 day coding, one day testing |