From dafb507e3ed09699230e3dd52fdc68c6094ee148 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 3 Feb 2017 19:09:19 +0100 Subject: 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. --- sql/filesort.cc | 4 ++-- sql/sql_update.cc | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/sql/filesort.cc b/sql/filesort.cc index 2283e6e3d0a..baeb75b3b0b 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -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");); if (file->ha_rnd_init_with_error(1)) DBUG_RETURN(HA_POS_ERROR); - file->extra_opt(HA_EXTRA_CACHE, - current_thd->variables.read_buff_size); + file->extra_opt(HA_EXTRA_CACHE, thd->variables.read_buff_size); } /* Remember original bitmaps */ @@ -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; /* 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); sort_form->column_bitmaps_set(&sort_form->tmp_set, &sort_form->tmp_set, &sort_form->tmp_set); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 9c0e9443b0d..35e1fe24b97 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -534,16 +534,9 @@ int mysql_update(THD *thd, /* We can't update table directly; We must first search after all 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) { /* @@ -569,6 +562,14 @@ int mysql_update(THD *thd, } 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 go trough the matching rows, save a pointer to them and @@ -681,9 +682,10 @@ int mysql_update(THD *thd, select->file=tempfile; // Read row ptrs from this file if (error >= 0) goto err; + + table->file->ha_end_keyread(); + table->column_bitmaps_set(save_read_set, save_write_set); } - table->file->ha_end_keyread(); - table->column_bitmaps_set(save_read_set, save_write_set); } if (ignore) -- cgit v1.2.1