← Back to team overview

maria-developers team mailing list archive

Re: f93af1f93e2: MDEV-12836 Avoid table rebuild when adding or removing of auto_increment settings

 

Hi, Eugene!

On Feb 04, Eugene Kosov wrote:
> revision-id: f93af1f93e2 (mariadb-10.3.12-19-gf93af1f93e2)
> parent(s): d4144c8e010
> author: Eugene Kosov <claprix@xxxxxxxxx>
> committer: Eugene Kosov <claprix@xxxxxxxxx>
> timestamp: 2019-01-23 19:32:02 +0300
> message:
> 
> MDEV-12836 Avoid table rebuild when adding or removing of auto_increment settings
> 
> ALTER_AUTO_INC: this flag indicates that ALTER operation
> adds or removes AUTO_INCREMENT from some field
> 
> Field::is_equal(): now sometime returns IS_EQUAL_BUT_AUTO_INC
> which means that only AUTO_INCREMENT was changed for that field

You enable instant alter for adding auto_inc. This is not what
Valerii asked for in MDEV-12836, and for a reason. Consider this test
case:

  create table t1 (a int unique);
  insert t1 values (NULL),(NULL),(NULL);
  alter table t1 modify a int auto_increment;

here `alter table` modifies the data, actually generating auto-inc
values for all NULL columns. I don't think you can do that instantly.
You can only remove auto-inc instantly. And for that you don't need any
big changes, just modify Field::is_equal() to allow it:

diff --git a/sql/field.cc b/sql/field.cc
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -3507,7 +3507,7 @@ uint Field_new_decimal::is_equal(Create_field *new_field)
   return ((new_field->type_handler() == type_handler()) &&
           ((new_field->flags & UNSIGNED_FLAG) ==
            (uint) (flags & UNSIGNED_FLAG)) &&
-          ((new_field->flags & AUTO_INCREMENT_FLAG) ==
+          ((new_field->flags & AUTO_INCREMENT_FLAG) <=
            (uint) (flags & AUTO_INCREMENT_FLAG)) &&
           (new_field->length == max_display_length()) &&
           (new_field->decimals == dec));
@@ -9508,7 +9508,7 @@ uint Field_num::is_equal(Create_field *new_field)
   return ((new_field->type_handler() == type_handler()) &&
           ((new_field->flags & UNSIGNED_FLAG) ==
            (uint) (flags & UNSIGNED_FLAG)) &&
-         ((new_field->flags & AUTO_INCREMENT_FLAG) ==
+         ((new_field->flags & AUTO_INCREMENT_FLAG) <=
           (uint) (flags & AUTO_INCREMENT_FLAG)) &&
           (new_field->pack_length == pack_length()));
 }

And this should be enough.

Regards,
Sergei
Chief Architect MariaDB
and security@xxxxxxxxxxx


Follow ups