Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-5590

Primary key cannot be defined upon persistent virtual column

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • Virtual Columns
    • None

    Description

      ERROR 1903 (HY000): Primary key cannot be defined upon a computed column .

      Virtual column was a nice way to remove stuff like
      PRIMARY KEY (`COD_INV`, `COD_FAM`, `COD_MAG`, `COD_FIL`, `COD_ID_INV`)

      • It's a bad practice to use triggers
      • It's a bad practice to use hidden primary key ,
      • It's a bad practice to use virtual column .

      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.

      Attachments

        Issue Links

          Activity

            stephane@skysql.com VAROQUI Stephane created issue -
            serg Sergei Golubchik made changes -
            Field Original Value New Value
            Summary Primary key cannot be defined upon persitent virtual column Primary key cannot be defined upon persistent virtual column
            elenst Elena Stepanova made changes -
            Affects Version/s 5.5.34 [ 13700 ]
            Affects Version/s 10.0.7 [ 14100 ]
            Issue Type Bug [ 1 ] Task [ 3 ]
            serg Sergei Golubchik made changes -
            Priority Major [ 3 ] Minor [ 4 ]
            serg Sergei Golubchik made changes -
            Workflow defaullt [ 33760 ] MariaDB v2 [ 42376 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            Workflow MariaDB v2 [ 42376 ] MariaDB v3 [ 61303 ]
            serg Sergei Golubchik made changes -
            greenman Ian Gilfillan made changes -
            Epic Link MDEV-10137 [ 56868 ]
            monty Michael Widenius made changes -
            monty Michael Widenius made changes -
            Parent MDEV-10137 [ 56868 ]
            Issue Type Task [ 3 ] Technical task [ 7 ]
            monty Michael Widenius made changes -
            Epic Link MDEV-10137 [ 56868 ]
            monty Michael Widenius made changes -
            monty Michael Widenius made changes -
            monty Michael Widenius made changes -
            monty Michael Widenius made changes -
            monty Michael Widenius made changes -
            Parent MDEV-10137 [ 56868 ]
            Issue Type Technical task [ 7 ] Task [ 3 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Priority Minor [ 4 ] Major [ 3 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            NRE Projects RM_105_CANDIDATE

            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?

            MariaDB [test]> alter table bad_with_key add primary key (id,id_len);
            ERROR 1903 (HY000): Primary key cannot be defined upon a generated column
            MariaDB [test]> alter table bad_with_key add unique key (id,id_len);
            Query OK, 0 rows affected (0.035 sec)
            Records: 0  Duplicates: 0  Warnings: 0
            

            manjot Manjot Singh (Inactive) added a comment - 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? MariaDB [test]> alter table bad_with_key add primary key (id,id_len); ERROR 1903 (HY000): Primary key cannot be defined upon a generated column MariaDB [test]> alter table bad_with_key add unique key (id,id_len); Query OK, 0 rows affected (0.035 sec) Records: 0 Duplicates: 0 Warnings: 0
            julien.fritsch Julien Fritsch made changes -
            Assignee Ralf Gebhardt [ ralf.gebhardt@mariadb.com ]
            stephane@skysql.com VAROQUI Stephane added a comment - The implementation should take care of : https://blog.jcole.us/2013/05/02/how-does-innodb-behave-without-a-primary-key/
            ralf.gebhardt Ralf Gebhardt made changes -
            Assignee Ralf Gebhardt [ ralf.gebhardt@mariadb.com ]

            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

            stephane@skysql.com VAROQUI Stephane added a comment - 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
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 61303 ] MariaDB v4 [ 130191 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Component/s Virtual Columns [ 10803 ]
            rjasdfiii Rick James added a comment -

            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.)

            rjasdfiii Rick James added a comment - 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.)
            stephane@skysql.com VAROQUI Stephane added a comment - - edited

            Less of on issue as of MDEV-19506

            stephane@skysql.com VAROQUI Stephane added a comment - - edited Less of on issue as of MDEV-19506

            Hi rjasdfiii,

            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)?

            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.

            GeoffMontee Geoff Montee (Inactive) added a comment - Hi rjasdfiii , 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)? 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.

            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.

            marko Marko Mäkelä added a comment - 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.
            mariadb-jira-automation Jira Automation (IT) made changes -
            Zendesk Related Tickets 139074
            AirFocus AirFocus made changes -
            Summary Primary key cannot be defined upon persistent virtual column Primary key cannot be defined upon persistent virtual column

            People

              Unassigned Unassigned
              stephane@skysql.com VAROQUI Stephane
              Votes:
              1 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.