summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc44
1 files changed, 29 insertions, 15 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 95a7ba514b7..57b09fa40b4 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -4604,14 +4604,14 @@ const_expression_in_where(COND *cond, Item *comp_item, Item **const_item)
create_tmp_field_from_field()
thd Thread handler
org_field field from which new field will be created
+ name New field name
item Item to create a field for
table Temporary table
- modify_item 1 if item->result_field should point to new item.
- This is relevent for how fill_record() is going to
- work:
- If modify_item is 1 then fill_record() will update
+ item !=NULL if item->result_field should point to new field.
+ This is relevant for how fill_record() is going to work:
+ If item != NULL then fill_record() will update
the record in the original table.
- If modify_item is 0 then fill_record() will update
+ If item == NULL then fill_record() will update
the temporary table
convert_blob_length If >0 create a varstring(convert_blob_length) field
instead of blob.
@@ -4622,8 +4622,8 @@ const_expression_in_where(COND *cond, Item *comp_item, Item **const_item)
*/
static Field* create_tmp_field_from_field(THD *thd, Field* org_field,
- Item *item, TABLE *table,
- bool modify_item,
+ const char *name, TABLE *table,
+ Item_field *item,
uint convert_blob_length)
{
Field *new_field;
@@ -4636,10 +4636,10 @@ static Field* create_tmp_field_from_field(THD *thd, Field* org_field,
new_field= org_field->new_field(thd->mem_root, table);
if (new_field)
{
- if (modify_item)
- ((Item_field *)item)->result_field= new_field;
+ if (item)
+ item->result_field= new_field;
else
- new_field->field_name= item->name;
+ new_field->field_name= name;
if (org_field->maybe_null())
new_field->flags&= ~NOT_NULL_FLAG; // Because of outer join
if (org_field->type() == FIELD_TYPE_VAR_STRING)
@@ -4779,8 +4779,8 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
if (item_sum->args[0]->type() == Item::FIELD_ITEM)
{
*from_field= ((Item_field*) item_sum->args[0])->field;
- return create_tmp_field_from_field(thd, *from_field, item, table,
- modify_item, convert_blob_length);
+ return create_tmp_field_from_field(thd, *from_field, item->name, table,
+ NULL, convert_blob_length);
}
/* fall through */
default:
@@ -4818,8 +4818,10 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
case Item::DEFAULT_VALUE_ITEM:
{
Item_field *field= (Item_field*) item;
- return create_tmp_field_from_field(thd, (*from_field= field->field), item,
- table, modify_item, convert_blob_length);
+ return create_tmp_field_from_field(thd, (*from_field= field->field),
+ item->name, table,
+ modify_item ? (Item_field*) item : NULL,
+ convert_blob_length);
}
case Item::FUNC_ITEM:
case Item::COND_ITEM:
@@ -7174,7 +7176,19 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
/* Found key that can be used to retrieve data in sorted order */
if (tab->ref.key >= 0)
{
- tab->ref.key= new_ref_key;
+ /*
+ We'll use ref access method on key new_ref_key. In general case
+ the index search tuple for new_ref_key will be different (e.g.
+ when one of the indexes only covers prefix of the field, see
+ BUG#9213 in group_by.test).
+ So we build tab->ref from scratch here.
+ */
+ KEYUSE *keyuse= tab->keyuse;
+ while (keyuse->key != new_ref_key && keyuse->table == tab->table)
+ keyuse++;
+ if (create_ref_for_key(tab->join, tab, keyuse,
+ tab->join->const_table_map))
+ DBUG_RETURN(0);
}
else
{