Bug #114250 | Wrong auto_increment set when using INSERT SELECT with ORDER RAND() | ||
---|---|---|---|
Submitted: | 6 Mar 2024 18:15 | Modified: | 7 Mar 2024 12:24 |
Reporter: | Renan Benedicto Pereira | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S3 (Non-critical) |
Version: | 8.0.31-google | OS: | Linux (Cloud SQL) |
Assigned to: | CPU Architecture: | Other | |
Tags: | auto_increment, insert select, order by rand |
[6 Mar 2024 18:15]
Renan Benedicto Pereira
[7 Mar 2024 11:25]
MySQL Verification Team
Hi Mr. Pereira, Thank you for your bug report. However, what you describe is expected behaviour. Simply, that is how InnoDB is designed to work with INSERT .... SELECT ..... Some of us have been part of that design. This has also to do with the fact that InnoDB is a transactional engine. As such, it has to have auto-increment key values reserved PRIOR to the start of the INSERT statement. Hence, InnoDB tries to calculate how many rows will SELECT return. Meanwhile, other transactions may run other DML statements, which might interfere with with a running INSERT and change the number of rows that is reserved. That is how InnoDB deals with INSERT from SELECT since 2003. The same is valid for INSERT with multi-row INSERT. Hence, this is the expected behaviour and it is here to stay. Some of this is explained in the Reference Manual, which would be read : https://dev.mysql.com/doc/refman/8.0/en/innodb-auto-increment-handling.html Not a bug.
[7 Mar 2024 12:24]
Renan Benedicto Pereira
Thank you for fast answer! So it compromises the ACID, may I have to hope for future changes about it? The workaround I used here is to create a "row_id" in the SELECT statement to hard load this column instead let auto_increment take the decision. Whatever it still have the behavior that you mentioned, reserving some others ID "slots". But what paid me attention for, was the exactly size of SMALLINT was used. Great thanks everyone that works hard on MySQL development and improvements !
[7 Mar 2024 13:05]
MySQL Verification Team
Hi, Currently there are no plans about changing this behaviour. It is very, very rare that ACID is compromised. Also, do remember that neither SQL nor ACID allow for the auto-increment type, at all. Thank you for your kind words. We wish you the best.