• Aleksey Midenkov's avatar
    MDEV-21540 Initialization of already inited long unique index on reorganize partition · 231feabd
    Aleksey Midenkov authored
    Handler for existing partition was already index-inited at the
    beginning of copy_partitions().
    
    In the case of REORGANIZE PARTITION we fill new partition by calling
    its ha_write_row() (handler is storage engine of new partition). From
    that we go through the below conditions:
    
        if (this->inited == RND)
          table->clone_handler_for_update();
        handler *h= table->update_handler ? table->update_handler : table->file;
    
    First, the above misses the meaning of this->inited check. Now it is
    new partition and this handler is not inited. So, we assign
    table->file which is ha_partition and is really not known to be inited
    or not. It is supposed (this == table->file), otherwise we are
    out of the logic for using update_handler. This patch adds DBUG_ASSERT
    for that.
    
    Second, we call check_duplicate_long_entries() for table->file and
    that calls ha_partition::index_init() which calls index_init() for
    each partition's handler. But the existing parititions' handlers was
    already inited in copy_partitions() and we fail on assertion.
    
    The fix implies that we don't need check_duplicate_long_entries()
    per-partition as we've already done check_duplicate_long_entries() for
    ha_partition. For REORGANIZE PARTITION that means existing row was
    already checked at previous INSERT/UPDATE commands, so no need to
    check it again (see NOTE in handler::ha_write_row()).
    
    The fix also optimizes ha_update_row() so
    check_duplicate_long_entries_update() is not called per-partition
    considering it was already called for ha_partition. Besides,
    per-partition duplicate check is not really usable.
    231feabd
long_unique_bugs.test 12.2 KB