summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2019-11-22 19:11:58 -0800
committerIgor Babaev <igor@askmonty.org>2019-11-22 19:34:08 -0800
commitf95288211ce1023e0d268229fbe5febbf0b2edd3 (patch)
treead3caae8630595477655026fc908baac815dee4e /sql
parentcb6d7c3ee3e3e90ed46d3d1d58be6bac12e5f784 (diff)
downloadmariadb-git-f95288211ce1023e0d268229fbe5febbf0b2edd3.tar.gz
MDEV-19919 Assertion `!prebuilt->index->is_primary()' failed
in row_search_idx_cond_check For a single table query with ORDER BY and several sargable range conditions the optimizer may choose an execution plan that employs a rowid filter. In this case it is important to build the filter before calling the function JOIN_TAB::sort_table() that creates sort index for the result set, because when this is index created the filter has to be already filled. After the sort index has been created the filter must be deactivated. If not to do this the innodb function row_search_idx_cond_check() is getting confused when it has to read rows from the created sort index by using ha_rnd_pos(). The order of actions mentioned above is needed also when processing a join query if sorting is performed for the first non constant table in the chosen execution plan.
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_select.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index a05c2f81b10..1ee2a175579 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -21101,11 +21101,12 @@ int join_init_read_record(JOIN_TAB *tab)
*/
if (tab->distinct && tab->remove_duplicates()) // Remove duplicates.
return 1;
- if (tab->filesort && tab->sort_table()) // Sort table.
- return 1;
tab->build_range_rowid_filter_if_needed();
+ if (tab->filesort && tab->sort_table()) // Sort table.
+ return 1;
+
DBUG_EXECUTE_IF("kill_join_init_read_record",
tab->join->thd->set_killed(KILL_QUERY););
if (tab->select && tab->select->quick && tab->select->quick->reset())
@@ -21165,6 +21166,9 @@ JOIN_TAB::sort_table()
JOIN::ordered_index_order_by :
JOIN::ordered_index_group_by));
rc= create_sort_index(join->thd, join, this, NULL);
+ /* Disactivate rowid filter if it was used when creating sort index */
+ if (rowid_filter)
+ table->file->rowid_filter_is_active= false;
return (rc != 0);
}