Commit 8b0ae035 authored by Tor Didriksen's avatar Tor Didriksen

Bug#14463247 ORDER BY SUBQUERY REFERENCING OUTER ALIAS FAILS

Documentation for class Item_outer_ref was wrong:
(*ref) may point to Item_field as well
(see e.g. Item_outer_ref::fix_fields)

So this casting in get_store_key() was wrong:
(*(Item_ref**)((Item_ref*)keyuse->val)->ref)->ref_type()
parent ab3862b8
...@@ -2676,6 +2676,7 @@ class Item_direct_view_ref :public Item_direct_ref ...@@ -2676,6 +2676,7 @@ class Item_direct_view_ref :public Item_direct_ref
resolved is a grouping one. After it has been fixed the ref field will point resolved is a grouping one. After it has been fixed the ref field will point
to either an Item_ref or an Item_direct_ref object which will be used to to either an Item_ref or an Item_direct_ref object which will be used to
access the field. access the field.
The ref field may also point to an Item_field instance.
See also comments for the fix_inner_refs() and the See also comments for the fix_inner_refs() and the
Item_field::fix_outer_field() functions. Item_field::fix_outer_field() functions.
*/ */
......
...@@ -6019,19 +6019,33 @@ get_store_key(THD *thd, KEYUSE *keyuse, table_map used_tables, ...@@ -6019,19 +6019,33 @@ get_store_key(THD *thd, KEYUSE *keyuse, table_map used_tables,
key_part->length, key_part->length,
keyuse->val); keyuse->val);
} }
else if (keyuse->val->type() == Item::FIELD_ITEM ||
(keyuse->val->type() == Item::REF_ITEM && Item_field *field_item= NULL;
((Item_ref*)keyuse->val)->ref_type() == Item_ref::OUTER_REF && if (keyuse->val->type() == Item::FIELD_ITEM)
(*(Item_ref**)((Item_ref*)keyuse->val)->ref)->ref_type() == field_item= static_cast<Item_field*>(keyuse->val->real_item());
Item_ref::DIRECT_REF && else if (keyuse->val->type() == Item::REF_ITEM)
keyuse->val->real_item()->type() == Item::FIELD_ITEM)) {
Item_ref *item_ref= static_cast<Item_ref*>(keyuse->val);
if (item_ref->ref_type() == Item_ref::OUTER_REF)
{
if ((*item_ref->ref)->type() == Item::FIELD_ITEM)
field_item= static_cast<Item_field*>(item_ref->real_item());
else if ((*(Item_ref**)(item_ref)->ref)->ref_type()
== Item_ref::DIRECT_REF
&&
item_ref->real_item()->type() == Item::FIELD_ITEM)
field_item= static_cast<Item_field*>(item_ref->real_item());
}
}
if (field_item)
return new store_key_field(thd, return new store_key_field(thd,
key_part->field, key_part->field,
key_buff + maybe_null, key_buff + maybe_null,
maybe_null ? key_buff : 0, maybe_null ? key_buff : 0,
key_part->length, key_part->length,
((Item_field*) keyuse->val->real_item())->field, field_item->field,
keyuse->val->full_name()); keyuse->val->full_name());
return new store_key_item(thd, return new store_key_item(thd,
key_part->field, key_part->field,
key_buff + maybe_null, key_buff + maybe_null,
......
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