summaryrefslogtreecommitdiff
path: root/sql/item_cmpfunc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r--sql/item_cmpfunc.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index a79a94868c8..5fe324f1b6a 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -413,10 +413,15 @@ static bool convert_constant_item(THD *thd, Item_field *field_item,
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
/*
- Store the value of the field if it references an outer field because
- the call to save_in_field below overrides that value.
+ Store the value of the field/constant if it references an outer field
+ because the call to save_in_field below overrides that value.
+ Don't save field value if no data has been read yet.
+ Outer constant values are always saved.
*/
- if (field_item->depended_from)
+ bool save_field_value= (field_item->depended_from &&
+ (field_item->const_item() ||
+ !(field->table->status & STATUS_NO_RECORD)));
+ if (save_field_value)
orig_field_val= field->val_int();
if (!(*item)->is_null() && !(*item)->save_in_field(field, 1))
{
@@ -427,7 +432,7 @@ static bool convert_constant_item(THD *thd, Item_field *field_item,
result= 1; // Item was replaced
}
/* Restore the original field value. */
- if (field_item->depended_from)
+ if (save_field_value)
{
result= field->store(orig_field_val, TRUE);
/* orig_field_val must be a valid value that can be restored back. */