[MDEV-5590] Primary key cannot be defined upon persistent virtual column Created: 2014-01-29 Updated: 2023-08-23 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Virtual Columns |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | VAROQUI Stephane | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
ERROR 1903 (HY000): Primary key cannot be defined upon a computed column . Virtual column was a nice way to remove stuff like
What could we advice that can be transparent to the application layer to fixe such bad design for InnoDB. Rewrite the application is not always a political correct answer. |
| Comments |
| Comment by Manjot Singh (Inactive) [ 2019-04-08 ] | |||||
|
So as a workaround, we are able to remove the primary key and create a unique key with the required columns. InnoDB seems to treat this the same as the primary key (needs more testing). Therefore, this feature should be easy to implement?
| |||||
| Comment by VAROQUI Stephane [ 2020-01-29 ] | |||||
|
The implementation should take care of : | |||||
| Comment by VAROQUI Stephane [ 2020-11-16 ] | |||||
|
The idea was to create an UNSIGNED LONG HASH for primary or unique key but this is blocked by 10.3+ -> https://jira.mariadb.org/browse/MDEV-18319 | |||||
| Comment by Rick James [ 2023-02-03 ] | |||||
|
I'm confused. https://mariadb.com/kb/en/generated-columns/ implies that "persistent" and "virtual" are mutually exclusive. So, is this bug report about a GENERATED column that is VIRTUAL? Or is PERSISTENT (aka STORED)? (Also, Singh's example does not have enough info to reproduce it.) | |||||
| Comment by VAROQUI Stephane [ 2023-02-03 ] | |||||
|
Less of on issue as of | |||||
| Comment by Geoff Montee (Inactive) [ 2023-02-03 ] | |||||
|
Hi rjasdfiii,
MariaDB implemented "virtual generated columns" before it implemented "persistent generated columns". At first, many folks just called the new feature "virtual columns". When MariaDB implemented "persistent generated columns", many folks were used to calling the old feature "virtual columns", so they started calling the new feature "persistent virtual columns", even though "virtual virtual columns" sounds kind of redundant and weird. Hopefully that confusing misnomer stops being used eventually. | |||||
| Comment by Marko Mäkelä [ 2023-08-23 ] | |||||
|
When it comes to InnoDB, and presumably any other storage engine that uses index-organized tables, support for defining a primary key on a virtual column would have to be implemented at a very low level. It would also imply that any update of the base columns of that virtual column would be expensive, just like updating the primary key. In an index-organized table, updating the primary key is like a DELETE and INSERT of the entire row, in all indexes. In a heap-organized table (which InnoDB does not support), every key can be updated independently of each other, so this would just be a DELETE and INSERT of the primary key index, not touching the data heap or other indexes. |