[MDEV-33261] aut_increment field cannot be use unles it's first field in primary key Created: 2024-01-16 Updated: 2024-01-17 |
|
| Status: | Needs Feedback |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - InnoDB |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | Philip orleans | Assignee: | Marko Mäkelä |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
I thought, this was allowed
the above create table statement fails, and the only one that works is
Is there a workaround? |
| Comments |
| Comment by Marko Mäkelä [ 2024-01-17 ] | ||||||||||||||
|
I don’t think that anything has changed recently about this. After
The implementation could be rewritten so that in case there is no usable index for quickly reading MAX(auto_increment_column), we will scan the entire table. Then we could remove the requirement to have a suitable index on the AUTO_INCREMENT column. Can you please be more specific with the "until now, this was allowed"? With which version of MariaDB Server would your first example work? | ||||||||||||||
| Comment by Philip orleans [ 2024-01-17 ] | ||||||||||||||
|
I cannot find out what version was allowing this. | ||||||||||||||
| Comment by Sergei Golubchik [ 2024-01-17 ] | ||||||||||||||
|
It used to work, and it still does, in MyISAM and Aria. InnoDB doesn't seem to have the HA_AUTO_PART_KEY flag and that causes your ER_WRONG_AUTO_KEY error. As far as I can see, InnoDB never had it. But what behavior do you actually need? Do you need it to have different values for all rows? Or you want it to have different values for all rows with the same day and fileid but start from 1 for every new day, for example? | ||||||||||||||
| Comment by Philip orleans [ 2024-01-17 ] | ||||||||||||||
|
I checked with Oracle's version of Innodb and it does not work either. | ||||||||||||||
| Comment by Sergei Golubchik [ 2024-01-17 ] | ||||||||||||||
|
if you don't need specifically the prefix-autoincrement behavior, then perhaps you can create a primary key specifically for auto-increment, and a separate UNIQUE key for (day, fileid, lineid) | ||||||||||||||
| Comment by Philip orleans [ 2024-01-17 ] | ||||||||||||||
|
I am doing exactly that, but I need to add a new index, unnecessarily, to the table. If Innodb would support the auto_increment field in any position within the primary key, it would more rational. I would save a unique index. |