summaryrefslogtreecommitdiff
path: root/sql/filesort.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/filesort.cc')
-rw-r--r--sql/filesort.cc30
1 files changed, 27 insertions, 3 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 8f03ee26691..65e4116479c 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -612,10 +612,34 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
}
DBUG_RETURN(HA_POS_ERROR); /* purecov: inspected */
}
+
+ bool write_record= false;
if (error == 0)
+ {
param->examined_rows++;
-
- if (error == 0 && (!select || select->skip_record(thd) > 0))
+ if (select && select->cond)
+ {
+ /*
+ If the condition 'select->cond' contains a subquery, restore the
+ original read/write sets of the table 'sort_form' because when
+ SQL_SELECT::skip_record evaluates this condition. it may include a
+ correlated subquery predicate, such that some field in the subquery
+ refers to 'sort_form'.
+ */
+ if (select->cond->with_subselect)
+ sort_form->column_bitmaps_set(save_read_set, save_write_set,
+ save_vcol_set);
+ write_record= (select->skip_record(thd) > 0);
+ if (select->cond->with_subselect)
+ sort_form->column_bitmaps_set(&sort_form->tmp_set,
+ &sort_form->tmp_set,
+ &sort_form->tmp_set);
+ }
+ else
+ write_record= true;
+ }
+
+ if (write_record)
{
if (idx == param->keys)
{
@@ -628,7 +652,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
}
else
file->unlock_row();
-
+
/* It does not make sense to read more keys in case of a fatal error */
if (thd->is_error())
break;