summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2021-06-10 23:54:14 +0300
committerSergei Petrunia <psergey@askmonty.org>2021-07-15 18:56:08 +0300
commit6a89f346dea852b267994e6f32e1c163e7688b34 (patch)
tree13b804165a766861342e532608aba616e882b58c /sql
parentda495b1b697d7cde0af8c7900dc9762cc3f7455b (diff)
downloadmariadb-git-6a89f346dea852b267994e6f32e1c163e7688b34.tar.gz
MDEV-25858: Query results are incorrect when indexes are added
If test_if_skip_sort_order() decides to use an index to produce required ordering, it should disable "Range Checked for each record" optimization. This is because Range-Checked-for-each-record may decide to use an index (or an index_merge) which will not produce the required ordering.
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_select.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index e89d06115fc..2bb01ee0d0a 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -21938,6 +21938,12 @@ check_reverse_order:
if (select->quick == save_quick)
save_quick= 0; // make_reverse() consumed it
select->set_quick(tmp);
+ /* Cancel "Range checked for each record" */
+ if (tab->use_quick == 2)
+ {
+ tab->use_quick= 1;
+ tab->read_first_record= join_init_read_record;
+ }
}
else if (tab->type != JT_NEXT && tab->type != JT_REF_OR_NULL &&
tab->ref.key >= 0 && tab->ref.key_parts <= used_key_parts)
@@ -21950,6 +21956,12 @@ check_reverse_order:
*/
tab->read_first_record= join_read_last_key;
tab->read_record.read_record= join_read_prev_same;
+ /* Cancel "Range checked for each record" */
+ if (tab->use_quick == 2)
+ {
+ tab->use_quick= 1;
+ tab->read_first_record= join_init_read_record;
+ }
/*
Cancel Pushed Index Condition, as it doesn't work for reverse scans.
*/