Skip to content
  • Nischal Tonthanahal's avatar
    a34a7928
    Bug#29941988 PREFIX INDEX LENGTH IGNORED WHILE UPGRADING PARTITIONED TABLES. · a34a7928
    Nischal Tonthanahal authored
    DESCRIPTION:
    ------------
    During upgrade of partitioned tables from 5.7 to 8.0, when a
    prefix key is used by the partitioning function, the prefix
    length is ignored, and the full column length is considered
    instead. Hence, the table might incorrectly be rejected from
    being upgraded because its partition field length is found
    to be too large, e.g. for a table like the following:
    
    CREATE TABLE t1(a VARCHAR(10000),
                    b VARCHAR(10),
                    PRIMARY KEY(a(100), b)
    ) PARTITION BY KEY() PARTITIONS 2;
    
    ANALYSIS:
    ---------
    When creating/opening/upgrading a table, the
    unpack_partition_info() function reads the length of the
    partitioned fields. There is a difference in behaviour when
    a table is created (or opened from the DD for the first
    time) in 8.0, and when a table is upgraded from 5.7, which
    is detailed below.
    
    During CREATE/OPEN TABLE:
        open_table_from_share() is called, which
        - Creates a copy of the key_info from TABLE_SHARE object
        to TABLE object.
        - Allocates a new Field object, with the field_length
        (eg: originally 10000) set to the key_part length (which
        is the length of the prefix key, eg: 100)
        - Points key_part->field to the new Field.
    
        Hence, unpack_partition_info()
        - Gets the TABLE object with the Field pointer having
        the correct length of partitioned fields.
    
    However, during UPGRADE from 5.7 to 8.0:
        open_table_from_share() is never called, instead,
        migrate_table_to_dd() is called, which simply
        - Points the key_info of TABLE to that of TABLE_SHARE.
    
        Hence, unpack_partition_info()
        - Gets the TABLE object with the Field pointer having
        the unmodified field_length (eg: 10000)
        - Causes the upgrade to be wrongfully rejected (because
        partition field length is found to be too large).
    
    FIX:
    ----
    Since open_table_from_share() performs the same tasks as
    this fix requires, we move the relevant code into a new
    function called create_key_part_field_with_prefix_length().
    
    This new function is then called in migrate_table_to_dd()
    during UPGRADE. This ensures that unpack_partition_info()
    reads the correct prefix length of partitioned fields, and
    upgrade does not fail in this scenario.
    
    Change-Id: I8ead62149b19ddc1d4546a34676c8e14369a5493
    a34a7928
    Bug#29941988 PREFIX INDEX LENGTH IGNORED WHILE UPGRADING PARTITIONED TABLES.
    Nischal Tonthanahal authored
    DESCRIPTION:
    ------------
    During upgrade of partitioned tables from 5.7 to 8.0, when a
    prefix key is used by the partitioning function, the prefix
    length is ignored, and the full column length is considered
    instead. Hence, the table might incorrectly be rejected from
    being upgraded because its partition field length is found
    to be too large, e.g. for a table like the following:
    
    CREATE TABLE t1(a VARCHAR(10000),
                    b VARCHAR(10),
                    PRIMARY KEY(a(100), b)
    ) PARTITION BY KEY() PARTITIONS 2;
    
    ANALYSIS:
    ---------
    When creating/opening/upgrading a table, the
    unpack_partition_info() function reads the length of the
    partitioned fields. There is a difference in behaviour when
    a table is created (or opened from the DD for the first
    time) in 8.0, and when a table is upgraded from 5.7, which
    is detailed below.
    
    During CREATE/OPEN TABLE:
        open_table_from_share() is called, which
        - Creates a copy of the key_info from TABLE_SHARE object
        to TABLE object.
        - Allocates a new Field object, with the field_length
        (eg: originally 10000) set to the key_part length (which
        is the length of the prefix key, eg: 100)
        - Points key_part->field to the new Field.
    
        Hence, unpack_partition_info()
        - Gets the TABLE object with the Field pointer having
        the correct length of partitioned fields.
    
    However, during UPGRADE from 5.7 to 8.0:
        open_table_from_share() is never called, instead,
        migrate_table_to_dd() is called, which simply
        - Points the key_info of TABLE to that of TABLE_SHARE.
    
        Hence, unpack_partition_info()
        - Gets the TABLE object with the Field pointer having
        the unmodified field_length (eg: 10000)
        - Causes the upgrade to be wrongfully rejected (because
        partition field length is found to be too large).
    
    FIX:
    ----
    Since open_table_from_share() performs the same tasks as
    this fix requires, we move the relevant code into a new
    function called create_key_part_field_with_prefix_length().
    
    This new function is then called in migrate_table_to_dd()
    during UPGRADE. This ensures that unpack_partition_info()
    reads the correct prefix length of partitioned fields, and
    upgrade does not fail in this scenario.
    
    Change-Id: I8ead62149b19ddc1d4546a34676c8e14369a5493
Loading