summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorunknown <monty@tik.mysql.fi>2002-03-02 09:51:24 +0200
committerunknown <monty@tik.mysql.fi>2002-03-02 09:51:24 +0200
commitad4fcb8a01f297f914e9e75d44b04e10fd91eb97 (patch)
tree7c46a4aab7560f176209fe10d40e1ec2df488a46 /sql/sql_select.cc
parentae670b76660fd66d046fd96af88be303c1d91006 (diff)
downloadmariadb-git-ad4fcb8a01f297f914e9e75d44b04e10fd91eb97.tar.gz
Fix sorting of NULL values (Should always be first)
Fix problem with HAVING and MAX() IS NOT NULL Docs/manual.texi: Changelog & NULL usage with ORDER BY client/mysqldump.c: Cleanup disable keys mysql-test/r/distinct.result: Fix results after ORDER BY with NULL fix mysql-test/r/group_by.result: Fix results after ORDER BY with NULL fix mysql-test/r/having.result: Testcase for bug with HAVING mysql-test/t/distinct.test: Test for DISTINCT + ORDER BY DESC bug mysql-test/t/having.test: Test of HAVING and MAX IS NOT NULL sql/filesort.cc: Fix sorting of NULL values (Should always be first) sql/item.h: Fix problem with HAVING and MAX() IS NOT NULL sql/item_sum.h: Fix problem with HAVING and MAX() IS NOT NULL sql/opt_range.cc: Fix problem with HAVING and MAX() IS NOT NULL sql/opt_range.h: Fix sorting of NULL values sql/sql_select.cc: Fix sorting of ORDER BY ... DESC on NULL values.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc37
1 files changed, 26 insertions, 11 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 69cac90e2be..fe21cf77589 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -594,8 +594,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;
@@ -5431,7 +5430,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,
@@ -5477,15 +5485,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)
@@ -7028,7 +7043,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
net_store_null(packet);
net_store_null(packet);
}
- sprintf(buff,"%.0f",join->best_positions[i].records_read);
+ sprintf(buff,"%.0f",(double) join->best_positions[i].records_read);
net_store_data(packet,buff);
my_bool key_read=table->key_read;
if (tab->type == JT_NEXT &&