summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2015-09-06 13:25:47 +0400
committerAlexander Barkov <bar@mariadb.org>2015-09-06 13:25:47 +0400
commite0df116056237beb89faa3527938b7ec7b1e15ec (patch)
tree089b17d3b2f331f65608922783166d4a58682bb3
parentc108019a48451147b456aed0d988773eee32a55b (diff)
downloadmariadb-git-e0df116056237beb89faa3527938b7ec7b1e15ec.tar.gz
A clean-up after the patch for MDEV-8747 and MDEV-8749:
removing IMPOSSIBLE_RESULT from Item_result, as it's not needed any more. The fact that an Item is not in a comparison context is now always designated by IDENTITY_SUBST in Subst_constraint. Previously IMPOSSIBLE_RESULT and IDENTITY_SUBST co-existed but actually meant the same thing.
-rw-r--r--include/mysql.h.pp2
-rw-r--r--include/mysql_com.h2
-rw-r--r--sql/field.cc1
-rw-r--r--sql/item.cc62
-rw-r--r--sql/item.h33
-rw-r--r--sql/item_cmpfunc.cc12
-rw-r--r--sql/item_cmpfunc.h4
-rw-r--r--sql/item_func.cc22
-rw-r--r--sql/item_sum.cc5
-rw-r--r--sql/sql_class.cc1
-rw-r--r--storage/connect/jsonudf.cpp3
11 files changed, 47 insertions, 100 deletions
diff --git a/include/mysql.h.pp b/include/mysql.h.pp
index ea4a3ee9c02..5c3a9210ce8 100644
--- a/include/mysql.h.pp
+++ b/include/mysql.h.pp
@@ -100,7 +100,7 @@ struct my_rnd_struct;
enum Item_result
{
STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT,
- TIME_RESULT,IMPOSSIBLE_RESULT
+ TIME_RESULT
};
typedef struct st_udf_args
{
diff --git a/include/mysql_com.h b/include/mysql_com.h
index 88dc57a9a39..a226c59bc9b 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -547,7 +547,7 @@ struct my_rnd_struct;
enum Item_result
{
STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT,
- TIME_RESULT,IMPOSSIBLE_RESULT
+ TIME_RESULT
};
typedef struct st_udf_args
diff --git a/sql/field.cc b/sql/field.cc
index b5f4020af71..a472ce473bf 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -8616,7 +8616,6 @@ bool Field_enum::can_optimize_keypart_ref(const Item_bool_func *cond,
return true;
case STRING_RESULT:
return charset() == cond->compare_collation();
- case IMPOSSIBLE_RESULT:
case ROW_RESULT:
DBUG_ASSERT(0);
break;
diff --git a/sql/item.cc b/sql/item.cc
index 7d7bced4872..cfbbcd136ac 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -97,7 +97,6 @@ bool Item::val_bool()
return val_real() != 0.0;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
return 0; // Wrong (but safe)
}
@@ -543,7 +542,6 @@ void Item::print_value(String *str)
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
}
@@ -634,7 +632,7 @@ Item_result Item::cmp_type() const
return TIME_RESULT;
};
DBUG_ASSERT(0);
- return IMPOSSIBLE_RESULT;
+ return STRING_RESULT;
}
/**
@@ -2596,7 +2594,6 @@ bool Item_field::val_bool_result()
return result_field->val_real() != 0.0;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
return 0; // Shut up compiler
}
@@ -3396,7 +3393,6 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
}
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
set_null();
}
@@ -4015,7 +4011,6 @@ Item_copy *Item_copy::create(THD *thd, Item *item)
return new (mem_root) Item_copy_decimal(thd, item);
case TIME_RESULT:
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT (0);
}
/* should not happen */
@@ -5369,13 +5364,27 @@ Item_equal *Item_field::find_item_equal(COND_EQUAL *cond_equal)
bool Item_field::can_be_substituted_to_equal_item(const Context &ctx,
const Item_equal *item_equal)
{
- if (ctx.compare_type() == STRING_RESULT &&
- ctx.compare_collation() != item_equal->compare_collation())
- return false;
- return ctx.subst_constraint() == ANY_SUBST ||
- field->cmp_type() != STRING_RESULT ||
- ((field->charset()->state & MY_CS_BINSORT) &&
- (field->charset()->state & MY_CS_NOPAD));
+ switch (ctx.subst_constraint()) {
+ case ANY_SUBST:
+ /*
+ Disable const propagation for items used in different comparison contexts.
+ This must be done because, for example, Item_hex_string->val_int() is not
+ the same as (Item_hex_string->val_str() in BINARY column)->val_int().
+ We cannot simply disable the replacement in a particular context (
+ e.g. <bin_col> = <int_col> AND <bin_col> = <hex_string>) since
+ Items don't know the context they are in and there are functions like
+ IF (<hex_string>, 'yes', 'no').
+ */
+ return
+ ctx.compare_type() == item_equal->compare_type() &&
+ (ctx.compare_type() != STRING_RESULT ||
+ ctx.compare_collation() == item_equal->compare_collation());
+ case IDENTITY_SUBST:
+ return field->cmp_type() != STRING_RESULT ||
+ ((field->charset()->state & MY_CS_BINSORT) &&
+ (field->charset()->state & MY_CS_NOPAD));
+ }
+ return false;
}
@@ -5442,17 +5451,7 @@ Item *Item_field::propagate_equal_fields(THD *thd,
Item *item= 0;
if (item_equal)
{
- /*
- Disable const propagation for items used in different comparison contexts.
- This must be done because, for example, Item_hex_string->val_int() is not
- the same as (Item_hex_string->val_str() in BINARY column)->val_int().
- We cannot simply disable the replacement in a particular context (
- e.g. <bin_col> = <int_col> AND <bin_col> = <hex_string>) since
- Items don't know the context they are in and there are functions like
- IF (<hex_string>, 'yes', 'no').
- */
- if (!can_be_substituted_to_equal_item(ctx, item_equal) ||
- !ctx.has_compatible_context(item_equal->compare_type()))
+ if (!can_be_substituted_to_equal_item(ctx, item_equal))
{
item_equal= NULL;
return this;
@@ -5463,11 +5462,13 @@ Item *Item_field::propagate_equal_fields(THD *thd,
item= this;
else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type()))
{
- DBUG_ASSERT(ctx.compare_type() != STRING_RESULT);
- if (item && (ctx.subst_constraint() == IDENTITY_SUBST))
+ if (ctx.subst_constraint() == IDENTITY_SUBST)
convert_zerofill_number_to_string(thd, &item, (Field_num *)field);
else
+ {
+ DBUG_ASSERT(ctx.compare_type() != STRING_RESULT);
item= this;
+ }
}
return item;
}
@@ -5599,7 +5600,6 @@ enum_field_types Item::field_type() const
case REAL_RESULT: return MYSQL_TYPE_DOUBLE;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
return MYSQL_TYPE_VARCHAR;
}
@@ -7384,7 +7384,6 @@ bool Item_ref::val_bool_result()
return result_field->val_real() != 0.0;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
}
@@ -8748,9 +8747,6 @@ void resolve_const_item(THD *thd, Item **ref, Item *comp_item)
(Item*) new (mem_root) Item_decimal(thd, name, result, length, decimals));
break;
}
- case IMPOSSIBLE_RESULT:
- DBUG_ASSERT(0);
- break;
}
if (new_item)
thd->change_item_tree(ref, new_item);
@@ -8902,9 +8898,6 @@ Item_cache* Item_cache::get_cache(THD *thd, const Item *item,
return new (mem_root) Item_cache_row(thd);
case TIME_RESULT:
return new (mem_root) Item_cache_temporal(thd, item->field_type());
- case IMPOSSIBLE_RESULT:
- DBUG_ASSERT(0);
- break;
}
return 0; // Impossible
}
@@ -9538,7 +9531,6 @@ enum_field_types Item_type_holder::get_real_type(Item *item)
return MYSQL_TYPE_NEWDECIMAL;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
return MYSQL_TYPE_VAR_STRING;
}
diff --git a/sql/item.h b/sql/item.h
index f858cc811c1..1fd26f144d4 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1438,14 +1438,18 @@ public:
{
/*
Which type of propagation is allowed:
- - SUBST_ANY (loose equality, according to the collation), or
- - SUBST_IDENTITY (strict binary equality).
+ - ANY_SUBST (loose equality, according to the collation), or
+ - IDENTITY_SUBST (strict binary equality).
*/
Subst_constraint m_subst_constraint;
+ /*
+ Comparison type.
+ Impostant only when ANY_SUBSTS.
+ */
Item_result m_compare_type;
/*
Collation of the comparison operation.
- Important only when SUBST_ANY.
+ Important only when ANY_SUBST.
*/
CHARSET_INFO *m_compare_collation;
public:
@@ -1454,27 +1458,22 @@ public:
m_compare_type(type),
m_compare_collation(cs) { }
Subst_constraint subst_constraint() const { return m_subst_constraint; }
- Item_result compare_type() const { return m_compare_type; }
- CHARSET_INFO *compare_collation() const { return m_compare_collation; }
- /**
- Check whether this and the given comparison type are compatible.
- Used by the equality propagation. See Item_field::propagate_equal_fields()
-
- @return
- TRUE if the context is the same
- FALSE otherwise.
- */
- inline bool has_compatible_context(Item_result other) const
+ Item_result compare_type() const
+ {
+ DBUG_ASSERT(m_subst_constraint == ANY_SUBST);
+ return m_compare_type;
+ }
+ CHARSET_INFO *compare_collation() const
{
- return m_compare_type == IMPOSSIBLE_RESULT ||
- m_compare_type == other;
+ DBUG_ASSERT(m_subst_constraint == ANY_SUBST);
+ return m_compare_collation;
}
};
class Context_identity: public Context
{ // Use this to request only exact value, no invariants.
public:
Context_identity()
- :Context(IDENTITY_SUBST, IMPOSSIBLE_RESULT, &my_charset_bin) { }
+ :Context(IDENTITY_SUBST, STRING_RESULT, &my_charset_bin) { }
};
class Context_boolean: public Context
{ // Use this when an item is [a part of] a boolean expression
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index d6a113e0ecb..3bfee49560c 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -612,9 +612,6 @@ int Arg_comparator::set_compare_func(Item_func_or_sum *item, Item_result type)
}
break;
}
- case IMPOSSIBLE_RESULT:
- DBUG_ASSERT(0);
- break;
}
return 0;
}
@@ -2358,7 +2355,6 @@ longlong Item_func_between::val_int()
break;
}
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
null_value= 1;
return 0;
@@ -2417,7 +2413,6 @@ Item_func_case_abbreviation2::fix_length_and_dec2(Item **args)
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
fix_char_length(char_length);
@@ -3375,7 +3370,6 @@ void Item_func_coalesce::fix_length_and_dec()
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
}
@@ -3739,9 +3733,6 @@ cmp_item* cmp_item::get_comparator(Item_result type, Item *warn_item,
case TIME_RESULT:
DBUG_ASSERT(warn_item);
return new cmp_item_datetime(warn_item);
- case IMPOSSIBLE_RESULT:
- DBUG_ASSERT(0);
- break;
}
return 0; // to satisfy compiler :)
}
@@ -4164,9 +4155,6 @@ void Item_func_in::fix_length_and_dec()
date_arg= find_date_time_item(args, arg_count, 0);
array= new (thd->mem_root) in_datetime(date_arg, arg_count - 1);
break;
- case IMPOSSIBLE_RESULT:
- DBUG_ASSERT(0);
- break;
}
if (array && !(thd->is_fatal_error)) // If not EOM
{
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index df0fc248f25..fe4084d0402 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -69,11 +69,11 @@ public:
/* Allow owner function to use string buffers. */
String value1, value2;
- Arg_comparator(): m_compare_type(IMPOSSIBLE_RESULT),
+ Arg_comparator(): m_compare_type(STRING_RESULT),
set_null(TRUE), comparators(0), thd(0),
a_cache(0), b_cache(0) {};
Arg_comparator(Item **a1, Item **a2): a(a1), b(a2),
- m_compare_type(IMPOSSIBLE_RESULT), set_null(TRUE),
+ m_compare_type(STRING_RESULT), set_null(TRUE),
comparators(0), thd(0), a_cache(0), b_cache(0) {};
private:
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 5bb5f541694..23fb45fb037 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -545,7 +545,6 @@ Field *Item_func::tmp_table_field(TABLE *table)
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
// This case should never be chosen
DBUG_ASSERT(0);
field= 0;
@@ -859,7 +858,6 @@ void Item_func_num1::fix_length_and_dec()
max_length= args[0]->max_length;
break;
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
DBUG_PRINT("info", ("Type: %s",
@@ -920,7 +918,6 @@ String *Item_func_hybrid_result_type::val_str(String *str)
return str_op(&str_value);
case TIME_RESULT:
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
return str;
@@ -969,7 +966,6 @@ double Item_func_hybrid_result_type::val_real()
}
case TIME_RESULT:
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
return 0.0;
@@ -1018,7 +1014,6 @@ longlong Item_func_hybrid_result_type::val_int()
}
case TIME_RESULT:
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
return 0;
@@ -1070,7 +1065,6 @@ my_decimal *Item_func_hybrid_result_type::val_decimal(my_decimal *decimal_value)
}
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
return val;
@@ -1124,7 +1118,6 @@ bool Item_func_hybrid_result_type::get_date(MYSQL_TIME *ltime,
}
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
@@ -1876,7 +1869,6 @@ void Item_func_div::fix_length_and_dec()
case STRING_RESULT:
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
maybe_null= 1; // devision by zero
@@ -2452,7 +2444,6 @@ void Item_func_int_val::fix_length_and_dec()
}
break;
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
DBUG_PRINT("info", ("Type: %s",
@@ -2634,7 +2625,6 @@ void Item_func_round::fix_length_and_dec()
}
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); /* This result type isn't handled */
}
}
@@ -3016,7 +3006,6 @@ String *Item_func_min_max::val_str(String *str)
}
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // This case should never be chosen
return 0;
}
@@ -3614,7 +3603,6 @@ udf_handler::fix_fields(THD *thd, Item_func_or_sum *func,
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // This case should never be chosen
break;
}
@@ -3693,7 +3681,6 @@ bool udf_handler::get_arguments()
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // This case should never be chosen
break;
}
@@ -4530,7 +4517,6 @@ longlong Item_func_benchmark::val_int()
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // This case should never be chosen
return 0;
}
@@ -4969,7 +4955,6 @@ double user_var_entry::val_real(bool *null_value)
return my_atof(value); // This is null terminated
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // Impossible
break;
}
@@ -5002,7 +4987,6 @@ longlong user_var_entry::val_int(bool *null_value) const
}
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // Impossible
break;
}
@@ -5037,7 +5021,6 @@ String *user_var_entry::val_str(bool *null_value, String *str,
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // Impossible
break;
}
@@ -5066,7 +5049,6 @@ my_decimal *user_var_entry::val_decimal(bool *null_value, my_decimal *val)
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // Impossible
break;
}
@@ -5125,7 +5107,6 @@ Item_func_set_user_var::check(bool use_result_field)
}
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // This case should never be chosen
break;
}
@@ -5160,7 +5141,6 @@ void Item_func_set_user_var::save_item_result(Item *item)
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // This case should never be chosen
break;
}
@@ -5228,7 +5208,6 @@ Item_func_set_user_var::update()
}
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // This case should never be chosen
break;
}
@@ -5684,7 +5663,6 @@ void Item_func_get_user_var::fix_length_and_dec()
break;
case ROW_RESULT: // Keep compiler happy
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0); // This case should never be chosen
break;
}
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index ae21a94fc83..79471bb6d50 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -526,7 +526,6 @@ Field *Item_sum::create_tmp_field(bool group, TABLE *table,
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
// This case should never be choosen
DBUG_ASSERT(0);
return 0;
@@ -1202,7 +1201,6 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref)
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
};
setup_hybrid(thd, args[0], NULL);
@@ -1380,7 +1378,6 @@ void Item_sum_sum::fix_length_and_dec()
break;
}
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
DBUG_PRINT("info", ("Type: %s (%d, %d)",
@@ -1871,7 +1868,6 @@ void Item_sum_variance::fix_length_and_dec()
}
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
DBUG_PRINT("info", ("Type: REAL_RESULT (%d, %d)", max_length, (int)decimals));
@@ -2314,7 +2310,6 @@ void Item_sum_hybrid::reset_field()
}
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
DBUG_ASSERT(0);
}
}
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 9b225de1ab8..98664fb3e65 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -3395,7 +3395,6 @@ int select_max_min_finder_subselect::send_data(List<Item> &items)
break;
case ROW_RESULT:
case TIME_RESULT:
- case IMPOSSIBLE_RESULT:
// This case should never be choosen
DBUG_ASSERT(0);
op= 0;
diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp
index b2d983712aa..2b7d3601c68 100644
--- a/storage/connect/jsonudf.cpp
+++ b/storage/connect/jsonudf.cpp
@@ -129,7 +129,6 @@ static my_bool CalcLen(UDF_ARGS *args, my_bool obj,
break;
case TIME_RESULT:
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
default:
// What should we do here ?
break;
@@ -167,7 +166,6 @@ static my_bool CalcLen(UDF_ARGS *args, my_bool obj,
break;
case TIME_RESULT:
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
default:
// What should we do here ?
break;
@@ -271,7 +269,6 @@ static PJVAL MakeValue(PGLOBAL g, UDF_ARGS *args, int i)
break;
case TIME_RESULT:
case ROW_RESULT:
- case IMPOSSIBLE_RESULT:
default:
break;
} // endswitch arg_type