Commit dafb507e authored by Sergei Golubchik's avatar Sergei Golubchik

find_all_keys: add an assert, remove current_thd

Filesort temporarily changes read_set to be tmp_set and marks only
fields needed for filesort. Add an assert to ensure that it doesn't
overwrite the old value of tmp_set, that is that read_set was *not*
already tmp_set when filesort was invoked.

Fix sql_update.cc that was was doing exactly that - changing read_set to
tmp_set, configuring tmp_set for keyread, and then invoking filesort.
parent e46c4221
...@@ -747,8 +747,7 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select, ...@@ -747,8 +747,7 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
DBUG_SET("+d,ha_rnd_init_fail");); DBUG_SET("+d,ha_rnd_init_fail"););
if (file->ha_rnd_init_with_error(1)) if (file->ha_rnd_init_with_error(1))
DBUG_RETURN(HA_POS_ERROR); DBUG_RETURN(HA_POS_ERROR);
file->extra_opt(HA_EXTRA_CACHE, file->extra_opt(HA_EXTRA_CACHE, thd->variables.read_buff_size);
current_thd->variables.read_buff_size);
} }
/* Remember original bitmaps */ /* Remember original bitmaps */
...@@ -757,6 +756,7 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select, ...@@ -757,6 +756,7 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
save_vcol_set= sort_form->vcol_set; save_vcol_set= sort_form->vcol_set;
/* Set up temporary column read map for columns used by sort */ /* Set up temporary column read map for columns used by sort */
DBUG_ASSERT(save_read_set != &sort_form->tmp_set);
bitmap_clear_all(&sort_form->tmp_set); bitmap_clear_all(&sort_form->tmp_set);
sort_form->column_bitmaps_set(&sort_form->tmp_set, &sort_form->tmp_set, sort_form->column_bitmaps_set(&sort_form->tmp_set, &sort_form->tmp_set,
&sort_form->tmp_set); &sort_form->tmp_set);
......
...@@ -534,16 +534,9 @@ int mysql_update(THD *thd, ...@@ -534,16 +534,9 @@ int mysql_update(THD *thd,
/* /*
We can't update table directly; We must first search after all We can't update table directly; We must first search after all
matching rows before updating the table! matching rows before updating the table!
*/
MY_BITMAP *save_read_set= table->read_set;
MY_BITMAP *save_write_set= table->write_set;
if (query_plan.index < MAX_KEY && old_covering_keys.is_set(query_plan.index))
table->prepare_for_keyread(query_plan.index);
else
table->use_all_columns();
/* note: We avoid sorting if we sort on the used index */ note: We avoid sorting if we sort on the used index
*/
if (query_plan.using_filesort) if (query_plan.using_filesort)
{ {
/* /*
...@@ -569,6 +562,14 @@ int mysql_update(THD *thd, ...@@ -569,6 +562,14 @@ int mysql_update(THD *thd,
} }
else else
{ {
MY_BITMAP *save_read_set= table->read_set;
MY_BITMAP *save_write_set= table->write_set;
if (query_plan.index < MAX_KEY && old_covering_keys.is_set(query_plan.index))
table->prepare_for_keyread(query_plan.index);
else
table->use_all_columns();
/* /*
We are doing a search on a key that is updated. In this case We are doing a search on a key that is updated. In this case
we go trough the matching rows, save a pointer to them and we go trough the matching rows, save a pointer to them and
...@@ -681,10 +682,11 @@ int mysql_update(THD *thd, ...@@ -681,10 +682,11 @@ int mysql_update(THD *thd,
select->file=tempfile; // Read row ptrs from this file select->file=tempfile; // Read row ptrs from this file
if (error >= 0) if (error >= 0)
goto err; goto err;
}
table->file->ha_end_keyread(); table->file->ha_end_keyread();
table->column_bitmaps_set(save_read_set, save_write_set); table->column_bitmaps_set(save_read_set, save_write_set);
} }
}
if (ignore) if (ignore)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment