diff options
author | monty@hundin.mysql.fi <> | 2002-03-06 23:41:18 +0200 |
---|---|---|
committer | monty@hundin.mysql.fi <> | 2002-03-06 23:41:18 +0200 |
commit | e9ba8d58feb15dba676e5603f9c4134f1d411c79 (patch) | |
tree | 8004cb532c51b6a2c9f603271702236358f167cb /sql/sql_select.cc | |
parent | c00ddbab5477d623ce00046e43fc0573052219e1 (diff) | |
parent | 35462001696d14b8f71bc4589fad3de63680eeed (diff) | |
download | mariadb-git-e9ba8d58feb15dba676e5603f9c4134f1d411c79.tar.gz |
merge
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 284f6304e07..a5ca249d590 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -612,8 +612,7 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds, HA_POS_ERROR : thd->select_limit,0)))) order=0; select_describe(&join,need_tmp, - (order != 0 && - (!need_tmp || order != group || simple_group)), + order != 0 && !skip_sort_order, select_distinct); error=0; goto err; @@ -5451,7 +5450,16 @@ static uint find_shortest_key(TABLE *table, key_map usable_keys) } -/* Return 1 if we don't have to do file sorting */ +/* + Test if we can skip the ORDER BY by using an index. + + If we can use an index, the JOIN_TAB / tab->select struct + is changed to use the index. + + Return: + 0 We have to use filesort to do the sorting + 1 We can use an index. +*/ static bool test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, @@ -5497,15 +5505,22 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, { if (select && select->quick) { - // ORDER BY range_key DESC - QUICK_SELECT_DESC *tmp=new QUICK_SELECT_DESC(select->quick, - used_key_parts); - if (!tmp || tmp->error) + /* + Don't reverse the sort order, if it's already done. + (In some cases test_if_order_by_key() can be called multiple times + */ + if (!select->quick->reverse_sorted()) { - delete tmp; - DBUG_RETURN(0); // Reverse sort not supported + // ORDER BY range_key DESC + QUICK_SELECT_DESC *tmp=new QUICK_SELECT_DESC(select->quick, + used_key_parts); + if (!tmp || tmp->error) + { + delete tmp; + DBUG_RETURN(0); // Reverse sort not supported + } + select->quick=tmp; } - select->quick=tmp; DBUG_RETURN(1); } if (tab->ref.key_parts < used_key_parts) |