Bug #104335 MySQL 8.0 operation failing silently
Submitted: 16 Jul 2021 11:24 Modified: 16 Jul 2021 12:56
Reporter: Atul Arora Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[16 Jul 2021 11:24] Atul Arora
Description:
See the table DDL at the end.

I have a table that has as 'id' column as the primary key and set to autoincrement. It is a tinyint type. As I kept inserting data into it, the 'id' value reached tinyint threshold. When I try to insert another row, it fails. Its fine but it fails 'silently'. It does not give me an error message indicating it.

Later, I changed the type from tinyint to int. I was. then able to insert new rows.

Reiterating, the concern is that the operation failure should give an easy error message so that it can be understood and handled.

I was fortunate, this error came in Development environment for me. If it was in production, my application would have been badly affected.

CREATE TABLE `question_banks` (
  `id` tinyint NOT NULL AUTO_INCREMENT,
  `qb_name` varchar(200) NOT NULL DEFAULT 'Generic',
  `count_of_questions_in_exam` tinyint NOT NULL DEFAULT '0',
  `location` varchar(500) DEFAULT 'ANY',
  `skill_levels_applicable` varchar(600) DEFAULT 'L0',
  `status` varchar(45) NOT NULL DEFAULT 'NEW',
  `exam_type` varchar(15) NOT NULL DEFAULT 'SKILL_TEST',
  PRIMARY KEY (`id`),
  UNIQUE KEY `qb_name_UNIQUE` (`qb_name`)
) ENGINE=InnoDB AUTO_INCREMENT=216 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

How to repeat:
1. Create a table using the DDL.

CREATE TABLE `question_banks` (
  `id` tinyint NOT NULL AUTO_INCREMENT,
  `qb_name` varchar(200) NOT NULL DEFAULT 'Generic',
  `count_of_questions_in_exam` tinyint NOT NULL DEFAULT '0',
  `location` varchar(500) DEFAULT 'ANY',
  `skill_levels_applicable` varchar(600) DEFAULT 'L0',
  `status` varchar(45) NOT NULL DEFAULT 'NEW',
  `exam_type` varchar(15) NOT NULL DEFAULT 'SKILL_TEST',
  PRIMARY KEY (`id`),
  UNIQUE KEY `qb_name_UNIQUE` (`qb_name`)
) ENGINE=InnoDB AUTO_INCREMENT=216 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

2. Keep inserting rows in this table using insert command in a loop that repeats for 10000 times.

INSERT INTO `assessments`.`question_banks`
(`id`,
`qb_name`,
`count_of_questions_in_exam`,
`location`,
`skill_levels_applicable`,
`status`,
`exam_type`)
VALUES
(<{id: }>,
<{qb_name: Generic}>,
<{count_of_questions_in_exam: 0}>,
<{location: ANY}>,
<{skill_levels_applicable: L0}>,
<{status: NEW}>,
<{exam_type: SKILL_TEST}>);

3. Check the result. It should have 10000 recs in table, but it will have lesser.

Suggested fix:
Add an error message that explains the issue and 'fails' the insert.
[16 Jul 2021 12:56] MySQL Verification Team
Hi Mr. Arora,

Thank you for your bug report.

However, this is not a bug.

When I run 257 INSERTs into the auto_increment column of the type TINYINT UNSIGNED, I get the following very, very loud error messages:

ERROR 1062 (23000) 1062 (23000) at line 1 at line 1: Duplicate entry '255' for key 't1.PRIMARY'
: Duplicate entry '255' for key 't1.PRIMARY'
ERROR 1062 (23000) at line 1: Duplicate entry '255' for key 't1.PRIMARY'
ERROR 1062 (23000) at line 1: Duplicate entry '255' for key 't1.PRIMARY'

Not a bug.