Commit a2cd622f authored by Chaithra Gopalareddy's avatar Chaithra Gopalareddy

Bug #20730129: BACKPORT BUG#19612819 TO 5.1

Backport from mysql-5.5 to mysql-5.1

Bug #19612819 :  FILESORT: ASSERTION FAILED: POS->FIELD != 0 || POS->ITEM != 0

Problem:
While getting the temp table field for a REF_ITEM
make_sortorder is using the real_item. As a result
server fails later with an assert.

Solution:
Do not use real_item to get the temp table field.
Instead use the REF_ITEM itself as temp table fields
are created for REF_ITEM not the real_item.
parent c7581bb5
/* 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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment