Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when autoincrement value is used for PK #5

Open
guriandoro opened this issue Dec 22, 2017 · 0 comments
Open

Errors when autoincrement value is used for PK #5

guriandoro opened this issue Dec 22, 2017 · 0 comments

Comments

@guriandoro
Copy link
Contributor

mysql [localhost] {msandbox} (sakila) > show create table actor\G
*************************** 1. row ***************************
       Table: actor
Create Table: CREATE TABLE `actor` (
  `actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `first_name` varchar(45) NOT NULL,
  `last_name` varchar(45) NOT NULL,
  `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`actor_id`),
  KEY `idx_actor_last_name` (`last_name`)
) ENGINE=InnoDB AUTO_INCREMENT=65535 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
SELECT COUNT(*) FROM actor;
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

As we can see, the PK is a smallint, the table is empty, and the AUTO_INCREMENT value is at 65535 (this was a table that was full, then all rows were deleted).

If we try to use the tool, it will insert only one row, and will error out with duplicate key errors:

mysql_random_data_load_linux_amd64 sakila actor 5 --host=127.0.0.1 --port=12323 --user=msandbox --password=msandbox 
2017/12/22 00:12:29 Starting
2017/12/22 00:12:29 cannot run insert: Error 1467: Failed to read auto-increment value from storage engine
2017/12/22 00:12:29 Adding extra 5 rows.
   0s [============>-------------------------------------------------------]  20%
Error 1062: Duplicate entry '65535' for key 'PRIMARY'
Error 1062: Duplicate entry '65535' for key 'PRIMARY'
Error 1062: Duplicate entry '65535' for key 'PRIMARY'
...

Only one row is inserted:

SELECT * FROM actor;
+----------+-----------------------------------------------+-----------------------------------------------+---------------------+
| actor_id | first_name                                    | last_name                                     | last_update         |
+----------+-----------------------------------------------+-----------------------------------------------+---------------------+
|    65535 | fugiat ratione tempora quia aliquam nulla dol | tempore aut harum debitis corporis sed repell | 2017-08-29 05:09:01 |
+----------+-----------------------------------------------+-----------------------------------------------+---------------------+
1 row in set (0.00 sec)

It may make sense to try to choose another PK value on error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant