@@ -8026,6 +8026,12 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
80268026 bool table_cant_handle_bit_fields,
80278027 uint convert_blob_length)
80288028{
8029+ Item *org_item= item;
8030+ if (item->real_item ()->type () == Item::FIELD_ITEM)
8031+ {
8032+ item= item->real_item ();
8033+ type= item->type ();
8034+ }
80298035 switch (type) {
80308036 case Item::SUM_FUNC_ITEM:
80318037 {
@@ -8038,30 +8044,22 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
80388044 case Item::FIELD_ITEM:
80398045 case Item::DEFAULT_VALUE_ITEM:
80408046 {
8041- Item_field *field= (Item_field*) item;
8042- if (table_cant_handle_bit_fields && field->field ->type () == FIELD_TYPE_BIT)
8043- return create_tmp_field_from_item (thd, item, table, copy_func,
8044- modify_item, convert_blob_length);
8045- return create_tmp_field_from_field (thd, (*from_field= field->field ),
8046- item->name , table,
8047- modify_item ? (Item_field*) item : NULL ,
8048- convert_blob_length);
8049- }
8050- case Item::REF_ITEM:
8051- {
8052- Item *tmp_item;
8053- if ((tmp_item= item->real_item ())->type () == Item::FIELD_ITEM)
8047+ if (org_item->type () != Item::REF_ITEM ||
8048+ !((Item_ref *)org_item)->depended_from )
80548049 {
8055- Item_field *field= (Item_field*) tmp_item;
8056- Field *new_field= create_tmp_field_from_field (thd,
8057- (*from_field= field->field ),
8058- item->name , table,
8059- NULL ,
8060- convert_blob_length);
8061- if (modify_item)
8062- item->set_result_field (new_field);
8063- return new_field;
8050+ Item_field *field= (Item_field*) item;
8051+ if (table_cant_handle_bit_fields &&
8052+ field->field ->type () == FIELD_TYPE_BIT)
8053+ return create_tmp_field_from_item (thd, item, table, copy_func,
8054+ modify_item, convert_blob_length);
8055+ return create_tmp_field_from_field (thd, (*from_field= field->field ),
8056+ item->name , table,
8057+ modify_item ? (Item_field*) item :
8058+ NULL ,
8059+ convert_blob_length);
80648060 }
8061+ else
8062+ item= org_item;
80658063 }
80668064 case Item::FUNC_ITEM:
80678065 case Item::COND_ITEM:
@@ -8074,6 +8072,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
80748072 case Item::REAL_ITEM:
80758073 case Item::DECIMAL_ITEM:
80768074 case Item::STRING_ITEM:
8075+ case Item::REF_ITEM:
80778076 case Item::NULL_ITEM:
80788077 case Item::VARBIN_ITEM:
80798078 return create_tmp_field_from_item (thd, item, table, copy_func, modify_item,
@@ -10904,12 +10903,12 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
1090410903 usable_keys.set_all ();
1090510904 for (ORDER *tmp_order=order; tmp_order ; tmp_order=tmp_order->next )
1090610905 {
10907- if ((*tmp_order->item )->type () != Item::FIELD_ITEM)
10906+ if ((*tmp_order->item )->real_item ()-> type () != Item::FIELD_ITEM)
1090810907 {
1090910908 usable_keys.clear_all ();
1091010909 DBUG_RETURN (0 );
1091110910 }
10912- usable_keys.intersect (((Item_field*) (*tmp_order->item ))->
10911+ usable_keys.intersect (((Item_field*) (*tmp_order->item )-> real_item () )->
1091310912 field->part_of_sortkey );
1091410913 if (usable_keys.is_clear_all ())
1091510914 DBUG_RETURN (0 ); // No usable keys
0 commit comments