mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-30046 wrong row targeted with "insert ... on duplicate" and "replace"
When HA_DUPLICATE_POS is not supported, the row to replace was navigated by ha_index_read_idx_map, which uses only hash to navigate. Suchwise, given a hash collision it may choose an incorrect row. handler::position would be correct and very convenient to use here. dup_ref is already set by handler independently of the engine capabilities, when an extra lookup is made (for long unique or something else, for example WITHOUT OVERLAPS) such error will be indicated by file->lookup_errkey != -1.
This commit is contained in:
@ -1884,11 +1884,28 @@ int write_record(THD *thd, TABLE *table, COPY_INFO *info, select_result *sink)
|
||||
if (info->handle_duplicates == DUP_REPLACE && table->next_number_field &&
|
||||
key_nr == table->s->next_number_index && insert_id_for_cur_row > 0)
|
||||
goto err;
|
||||
if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
|
||||
if (table->file->has_dup_ref())
|
||||
{
|
||||
/*
|
||||
If engine doesn't support HA_DUPLICATE_POS, the handler may init to
|
||||
INDEX, but dup_ref could also be set by lookup_handled (and then,
|
||||
lookup_errkey is set, f.ex. long unique duplicate).
|
||||
|
||||
In such case, handler would stay uninitialized, so do it here.
|
||||
*/
|
||||
bool init_lookup_handler= table->file->lookup_errkey != (uint)-1 &&
|
||||
table->file->inited == handler::NONE;
|
||||
if (init_lookup_handler && table->file->ha_rnd_init_with_error(false))
|
||||
goto err;
|
||||
|
||||
DBUG_ASSERT(table->file->inited == handler::RND);
|
||||
if (table->file->ha_rnd_pos(table->record[1],table->file->dup_ref))
|
||||
goto err;
|
||||
int rnd_pos_err= table->file->ha_rnd_pos(table->record[1],
|
||||
table->file->dup_ref);
|
||||
|
||||
if (init_lookup_handler)
|
||||
table->file->ha_rnd_end();
|
||||
if (rnd_pos_err)
|
||||
goto err;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user