diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 86cab59fd2a..fccd94ec3cd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1289,8 +1289,19 @@ JOIN::optimize() store_key *key_copy= tab->ref.key_copy[key_copy_index]; if (key_copy->type() == store_key::FIELD_STORE_KEY) { - store_key_field *field_copy= ((store_key_field *)key_copy); - field_copy->change_source_field((Item_field *) item); + if (item->basic_const_item()) + { + /* It is constant propagated here */ + tab->ref.key_copy[key_copy_index]= + new store_key_const_item(*tab->ref.key_copy[key_copy_index], + item); + } + else + { + store_key_field *field_copy= ((store_key_field *)key_copy); + DBUG_ASSERT(item->type() == Item::FIELD_ITEM); + field_copy->change_source_field((Item_field *) item); + } } } key_copy_index++; diff --git a/sql/sql_select.h b/sql/sql_select.h index 2724c4a5a63..22bdd93a38c 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1468,6 +1468,11 @@ public: to_field=field_arg->new_key_field(thd->mem_root, field_arg->table, ptr, null, 1); } + store_key(store_key &arg) + :null_key(arg.null_key), to_field(arg.to_field), + null_ptr(arg.null_ptr), err(arg.err) + + {} virtual ~store_key() {} /** Not actually needed */ virtual enum Type type() const=0; virtual const char *name() const=0; @@ -1572,6 +1577,10 @@ public: null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ? &err : (uchar*) 0, length), item(item_arg), use_value(val) {} + store_key_item(store_key &arg, Item *new_item, bool val) + :store_key(arg), item(new_item), use_value(val) + {} + enum Type type() const { return ITEM_STORE_KEY; } const char *name() const { return "func"; } @@ -1617,11 +1626,14 @@ public: store_key_const_item(THD *thd, Field *to_field_arg, uchar *ptr, uchar *null_ptr_arg, uint length, Item *item_arg) - :store_key_item(thd, to_field_arg,ptr, + :store_key_item(thd, to_field_arg, ptr, null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ? &err : (uchar*) 0, length, item_arg, FALSE), inited(0) { } + store_key_const_item(store_key &arg, Item *new_item) + :store_key_item(arg, new_item, FALSE), inited(0) + {} enum Type type() const { return CONST_ITEM_STORE_KEY; } const char *name() const { return "const"; }