Skip to content

Commit dafb507

Browse files
committed
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.
1 parent e46c422 commit dafb507

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

sql/filesort.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,7 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
747747
DBUG_SET("+d,ha_rnd_init_fail"););
748748
if (file->ha_rnd_init_with_error(1))
749749
DBUG_RETURN(HA_POS_ERROR);
750-
file->extra_opt(HA_EXTRA_CACHE,
751-
current_thd->variables.read_buff_size);
750+
file->extra_opt(HA_EXTRA_CACHE, thd->variables.read_buff_size);
752751
}
753752

754753
/* Remember original bitmaps */
@@ -757,6 +756,7 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
757756
save_vcol_set= sort_form->vcol_set;
758757

759758
/* Set up temporary column read map for columns used by sort */
759+
DBUG_ASSERT(save_read_set != &sort_form->tmp_set);
760760
bitmap_clear_all(&sort_form->tmp_set);
761761
sort_form->column_bitmaps_set(&sort_form->tmp_set, &sort_form->tmp_set,
762762
&sort_form->tmp_set);

sql/sql_update.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,9 @@ int mysql_update(THD *thd,
534534
/*
535535
We can't update table directly; We must first search after all
536536
matching rows before updating the table!
537-
*/
538-
MY_BITMAP *save_read_set= table->read_set;
539-
MY_BITMAP *save_write_set= table->write_set;
540-
541-
if (query_plan.index < MAX_KEY && old_covering_keys.is_set(query_plan.index))
542-
table->prepare_for_keyread(query_plan.index);
543-
else
544-
table->use_all_columns();
545537
546-
/* note: We avoid sorting if we sort on the used index */
538+
note: We avoid sorting if we sort on the used index
539+
*/
547540
if (query_plan.using_filesort)
548541
{
549542
/*
@@ -569,6 +562,14 @@ int mysql_update(THD *thd,
569562
}
570563
else
571564
{
565+
MY_BITMAP *save_read_set= table->read_set;
566+
MY_BITMAP *save_write_set= table->write_set;
567+
568+
if (query_plan.index < MAX_KEY && old_covering_keys.is_set(query_plan.index))
569+
table->prepare_for_keyread(query_plan.index);
570+
else
571+
table->use_all_columns();
572+
572573
/*
573574
We are doing a search on a key that is updated. In this case
574575
we go trough the matching rows, save a pointer to them and
@@ -681,9 +682,10 @@ int mysql_update(THD *thd,
681682
select->file=tempfile; // Read row ptrs from this file
682683
if (error >= 0)
683684
goto err;
685+
686+
table->file->ha_end_keyread();
687+
table->column_bitmaps_set(save_read_set, save_write_set);
684688
}
685-
table->file->ha_end_keyread();
686-
table->column_bitmaps_set(save_read_set, save_write_set);
687689
}
688690

689691
if (ignore)

0 commit comments

Comments
 (0)