[MDEV-21624] Unique index length is able to exceed max key length Created: 2020-01-31 Updated: 2021-04-19 Resolved: 2020-08-27 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Alter Table, Storage Engine - InnoDB |
| Affects Version/s: | 10.4.12 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Critical |
| Reporter: | Geoff Montee (Inactive) | Assignee: | Sachin Setiya (Inactive) |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
It appears that unique indexes are able to exceed the max key length in some cases. For example, if we tried to add the following primary key, then it would fail:
And for example, if we tried to add the following non-unique secondary index, then it would also fail:
We see the following error in both cases:
However, for some reason, if we tried to add the following unique index, then it would succeed:
Is it intentional for the unique index to have a different max key length? |
| Comments |
| Comment by Geoff Montee (Inactive) [ 2020-01-31 ] | |
|
This issue does not affect MariaDB 10.2.31 or MariaDB 10.3.22. It only seems to affect MariaDB 10.4.12. | |
| Comment by Marko Mäkelä [ 2020-02-01 ] | |
|
There should not be anything special about unique indexes in InnoDB. Even for non-leaf pages, PRIMARY KEY columns are included, as reported in | |
| Comment by Sergei Golubchik [ 2020-02-03 ] | |
|
| |
| Comment by Marko Mäkelä [ 2020-08-25 ] | |
|
Yes, this is caused by
For the unique index, an index on a hidden virtual column DB_ROW_HASH_1 would be created instead. I do not think that there is anything that can be fixed in the storage engine, and I do not know if this can be treated as a bug at all. Maybe this should simply be treated as a documentation issue? | |
| Comment by Marko Mäkelä [ 2020-08-25 ] | |
|
Actually, to work around bugs related to | |
| Comment by Sergei Golubchik [ 2020-08-27 ] | |
|
It's not a bug, MariaDB since 10.4 allows creating unique constraints of arbitrary length. A constraint is a logical object in the database and since 10.4 you can specify that "values in these columns should be unique" without thinking about implementation details and limitations of a particular storage engine. The second statement failing is a bug, though. Creating non-unique indexes should not fail with "key too long" — the server automatically shortens the index to fit. And for some reason this doesn't happen in your example. |