summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_select.cc35
1 files changed, 25 insertions, 10 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 7507f430eb7..03054020d57 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -14428,18 +14428,33 @@ SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length,
for (;order;order=order->next,pos++)
{
- Item *item= order->item[0]->real_item();
+ Item *const item= order->item[0], *const real_item= item->real_item();
pos->field= 0; pos->item= 0;
- if (item->type() == Item::FIELD_ITEM)
- pos->field= ((Item_field*) item)->field;
- else if (item->type() == Item::SUM_FUNC_ITEM && !item->const_item())
- pos->field= ((Item_sum*) item)->get_tmp_table_field();
- else if (item->type() == Item::COPY_STR_ITEM)
- { // Blob patch
- pos->item= ((Item_copy*) item)->get_item();
+ if (real_item->type() == Item::FIELD_ITEM)
+ {
+ // Could be a field, or Item_direct_view_ref wrapping a field
+ DBUG_ASSERT(item->type() == Item::FIELD_ITEM ||
+ (item->type() == Item::REF_ITEM &&
+ static_cast<Item_ref*>(item)->ref_type() ==
+ Item_ref::VIEW_REF));
+ pos->field= static_cast<Item_field*>(real_item)->field;
+ }
+ else if (real_item->type() == Item::SUM_FUNC_ITEM &&
+ !real_item->const_item())
+ {
+ // Aggregate, or Item_aggregate_ref
+ DBUG_ASSERT(item->type() == Item::SUM_FUNC_ITEM ||
+ (item->type() == Item::REF_ITEM &&
+ static_cast<Item_ref*>(item)->ref_type() ==
+ Item_ref::AGGREGATE_REF));
+ pos->field= item->get_tmp_table_field();
+ }
+ else if (real_item->type() == Item::COPY_STR_ITEM)
+ {// Blob patch
+ pos->item= static_cast<Item_copy*>(real_item)->get_item();
}
else
- pos->item= *order->item;
+ pos->item= item;
pos->reverse=! order->asc;
}
*length=count;