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

Allow instant change of WITH SYSTEM VERSIONING column attribute

Details

    Description

      An ALTER TABLE operation that specifies WITH SYSTEM VERSIONING or WITHOUT SYSTEM VERSIONING on a column will set the flag ALTER_COLUMN_UNVERSIONED, which currently causes the table to be rebuilt.

      As far as I can tell, the change should not require rebuilding anything. The data in the table remains the same.

      Enabling WITH SYSTEM VERSIONING for a column should be an instantaneous change, assuming that system versioning is already enabled on the table. This would only set some metadata so that future UPDATE on that column will cause the versioning information to be stored.

      Specifying WITHOUT SYSTEM VERSIONING might involve removing old history data for that column. That could be done by a table scan and update, which is cheaper than a full rebuild. We could also redefine the semantics of the operation, documenting that any old historical data for the column would survive.

      Attachments

        Issue Links

          Activity

            Specifying WITHOUT SYSTEM VERSIONING might involve removing old history data for that column.

            History is stored for rows, not columns. Thus it's not possible to remove history for some columns. And changing WITH/WITHOUT SYSTEM VERSIONING doens't need to read table data at all.

            kevg Eugene Kosov (Inactive) added a comment - Specifying WITHOUT SYSTEM VERSIONING might involve removing old history data for that column. History is stored for rows, not columns. Thus it's not possible to remove history for some columns. And changing WITH/WITHOUT SYSTEM VERSIONING doens't need to read table data at all.

            Apart from table rebuildint there is a related bug:

            set @@system_versioning_alter_history=keep;
            create table t (
              a int,
              b int,
              row_start bigint unsigned as row start invisible,
              row_end bigint unsigned as row end invisible,
              period for system_time(row_start, row_end)
            ) with system versioning engine=innodb;
             
            insert into t values (1,1);
             
            alter table t
              change a a int without system versioning;
             
            update t set a=11;
            select *,row_start,row_end from t for system_time all;
            
            

            Here historical row is created on UPDATE.

            kevg Eugene Kosov (Inactive) added a comment - Apart from table rebuildint there is a related bug: set @@system_versioning_alter_history=keep; create table t ( a int, b int, row_start bigint unsigned as row start invisible, row_end bigint unsigned as row end invisible, period for system_time(row_start, row_end) ) with system versioning engine=innodb;   insert into t values (1,1);   alter table t change a a int without system versioning;   update t set a=11; select *,row_start,row_end from t for system_time all; Here historical row is created on UPDATE .

            Yes, history is stored for rows, not columns. I meant that it would be technically possible to remove historical data for a particular column by updating the value of the column in the history rows to the current value.

            Come to think of it, if versioning is disabled for some columns, some historical values of non-versioned columns can be persisted in historical rows as ‘collateral damage’ if these historical rows are created due to updating versioned columns.

            So, I would guess that adding the WITHOUT SYSTEM VERSIONING attribute to a column could be an instantaneous operation, only affecting subsequent versioned operations. (SELECT should only report the current value of non-versioned columns, and treat any values in historical rows as garbage.)

            marko Marko Mäkelä added a comment - Yes, history is stored for rows, not columns. I meant that it would be technically possible to remove historical data for a particular column by updating the value of the column in the history rows to the current value. Come to think of it, if versioning is disabled for some columns, some historical values of non-versioned columns can be persisted in historical rows as ‘collateral damage’ if these historical rows are created due to updating versioned columns. So, I would guess that adding the WITHOUT SYSTEM VERSIONING attribute to a column could be an instantaneous operation, only affecting subsequent versioned operations. ( SELECT should only report the current value of non-versioned columns, and treat any values in historical rows as garbage.)

            I posted my review comments, asking for some revision.

            marko Marko Mäkelä added a comment - I posted my review comments, asking for some revision.

            I improved PR and asking for another review round.

            kevg Eugene Kosov (Inactive) added a comment - I improved PR and asking for another review round.

            Some minor improvements are still needed.

            marko Marko Mäkelä added a comment - Some minor improvements are still needed.

            PR updated.

            kevg Eugene Kosov (Inactive) added a comment - PR updated.

            People

              kevg Eugene Kosov (Inactive)
              marko Marko Mäkelä
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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