diff options
author | unknown <timour@mysql.com> | 2005-01-06 10:49:26 +0200 |
---|---|---|
committer | unknown <timour@mysql.com> | 2005-01-06 10:49:26 +0200 |
commit | f0cf742fd3e87dbe6cfb065bb371b1cbc93c00e5 (patch) | |
tree | f4d39c8ba71ef4ea329006b635a4f77910cd67e4 /sql | |
parent | c99b4964ca7da035bf2895812ef02bcfbdefa67a (diff) | |
download | mariadb-git-f0cf742fd3e87dbe6cfb065bb371b1cbc93c00e5.tar.gz |
Fix for BUG#7331.
The problem was that when a QUICK_SELECT access method is chosen,
test_if_skip_sort_order() discovered that the index being used
by the quick select will not deliver tuples in sorted order.
In this case test_if_skip_sort_order() tried to change the index
used by the quick select, but it didn't properly set the other
members of the quick select, and especially the range flags of
the ranges in QUICK_SELECT::ranges.
The fix re-invokes the function SQL_SELECT::test_quick_select
to correctly create a valid QUICK_SELECT object.
mysql-test/r/order_by.result:
Added test results.
mysql-test/t/order_by.test:
Added test for BUG#7331.
sql/sql_select.cc:
Fix for BUG#7331.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_select.cc | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 610a98d1983..acff1180e8c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7153,11 +7153,24 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, } else { - select->quick->file->ha_index_end(); - select->quick->index= new_ref_key; - select->quick->init(); + /* + The range optimizer constructed QUICK_RANGE for ref_key, and + we want to use instead new_ref_key as the index. We can't + just change the index of the quick select, because this may + result in an incosistent QUICK_SELECT object. Below we + create a new QUICK_SELECT from scratch so that all its + parameres are set correctly by the range optimizer. + */ + key_map new_ref_key_map; + new_ref_key_map.clear_all(); /* Force the creation of quick select */ + new_ref_key_map.set_bit(new_ref_key); /* only for new_ref_key. */ + + if (select->test_quick_select(tab->join->thd, new_ref_key_map, 0, + (tab->join->select_options & OPTION_FOUND_ROWS) ? + HA_POS_ERROR : tab->join->unit->select_limit_cnt) <= 0) + DBUG_RETURN(0); } - ref_key= new_ref_key; + ref_key= new_ref_key; } } /* Check if we get the rows in requested sorted order by using the key */ |