summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2018-06-06 14:09:06 +0400
committerAlexander Barkov <bar@mariadb.com>2018-06-06 14:09:06 +0400
commitc20cd68e60465f43266fe2bc2b2190e7c1cc4983 (patch)
tree16beb4138d72ba2fac7c33fab3cf94b3591fc3cf /sql
parent395212446acec1191d570d15eb03219c2cb11791 (diff)
downloadmariadb-git-c20cd68e60465f43266fe2bc2b2190e7c1cc4983.tar.gz
MDEV-14630 Replace {STRING|INT|REAL|DECIMAL|DATE}_ITEM to CONST_ITEM
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc2
-rw-r--r--sql/item.cc33
-rw-r--r--sql/item.h80
-rw-r--r--sql/item_func.cc2
-rw-r--r--sql/item_func.h2
-rw-r--r--sql/sp_head.cc26
-rw-r--r--sql/sp_head.h3
7 files changed, 49 insertions, 99 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 735c46be582..dc854826ed6 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -10630,7 +10630,7 @@ Field *Column_definition_attributes::make_field(TABLE_SHARE *share,
bool Field_vers_trx_id::test_if_equality_guarantees_uniqueness(const Item* item) const
{
- return item->type() == Item::DATE_ITEM;
+ return item->is_of_type(Item::CONST_ITEM, TIME_RESULT);
}
diff --git a/sql/item.cc b/sql/item.cc
index a4a72a8d2f8..5cffb244030 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1806,10 +1806,10 @@ Item_splocal::Item_splocal(THD *thd,
Rewritable_query_parameter(pos_in_q, len_in_q),
Type_handler_hybrid_field_type(handler),
m_rcontext_handler(rh),
- m_var_idx(sp_var_idx)
+ m_var_idx(sp_var_idx),
+ m_type(handler == &type_handler_row ? ROW_ITEM : CONST_ITEM)
{
maybe_null= TRUE;
- m_type= sp_map_item_type(handler);
}
@@ -3635,11 +3635,8 @@ longlong Item_field::val_int_endpoint(bool left_endp, bool *incl_endp)
bool Item_basic_value::eq(const Item *item, bool binary_cmp) const
{
const Item_basic_value *other= item->get_item_basic_value();
- Type other_type;
- // Exclude CACHE_OTEM and VARBIN_ITEM
- if (!other ||
- (other_type= other->type()) == CACHE_ITEM ||
- other_type == VARBIN_ITEM)
+ // Exclude CACHE_ITEM and VARBIN_ITEM
+ if (!other || type() != other->type())
return false;
const Type_handler *h= type_handler()->type_handler_for_comparison();
bool res= (h == other->type_handler()->type_handler_for_comparison()) &&
@@ -4040,8 +4037,6 @@ Item_param::Item_param(THD *thd, const LEX_CSTRING *name_arg,
*/
Type_handler_hybrid_field_type(&type_handler_null),
state(NO_VALUE),
- /* Don't pretend to be a literal unless value for this item is set. */
- item_type(PARAM_ITEM),
m_empty_string_is_null(false),
indicator(STMT_INDICATOR_NONE),
m_out_param_info(NULL),
@@ -4080,7 +4075,6 @@ void Item_param::set_null()
max_length= 0;
decimals= 0;
state= NULL_VALUE;
- fix_type(Item::NULL_ITEM);
DBUG_VOID_RETURN;
}
@@ -4095,7 +4089,6 @@ void Item_param::set_int(longlong i, uint32 max_length_arg)
decimals= 0;
maybe_null= 0;
null_value= 0;
- fix_type(Item::INT_ITEM);
DBUG_VOID_RETURN;
}
@@ -4110,7 +4103,6 @@ void Item_param::set_double(double d)
decimals= NOT_FIXED_DEC;
maybe_null= 0;
null_value= 0;
- fix_type(Item::REAL_ITEM);
DBUG_VOID_RETURN;
}
@@ -4143,7 +4135,6 @@ void Item_param::set_decimal(const char *str, ulong length)
decimals, unsigned_flag);
maybe_null= 0;
null_value= 0;
- fix_type(Item::DECIMAL_ITEM);
DBUG_VOID_RETURN;
}
@@ -4161,7 +4152,6 @@ void Item_param::set_decimal(const my_decimal *dv, bool unsigned_arg)
decimals, unsigned_flag);
maybe_null= 0;
null_value= 0;
- fix_type(Item::DECIMAL_ITEM);
}
@@ -4173,7 +4163,6 @@ void Item_param::fix_temporal(uint32 max_length_arg, uint decimals_arg)
decimals= decimals_arg;
maybe_null= 0;
null_value= 0;
- fix_type(Item::DATE_ITEM);
}
@@ -4258,7 +4247,6 @@ bool Item_param::set_str(const char *str, ulong length,
null_value= 0;
/* max_length and decimals are set after charset conversion */
/* sic: str may be not null-terminated, don't add DBUG_PRINT here */
- fix_type(Item::STRING_ITEM);
DBUG_RETURN(FALSE);
}
@@ -4292,7 +4280,6 @@ bool Item_param::set_longdata(const char *str, ulong length)
state= LONG_DATA_VALUE;
maybe_null= 0;
null_value= 0;
- fix_type(Item::STRING_ITEM);
DBUG_RETURN(FALSE);
}
@@ -4394,15 +4381,6 @@ void Item_param::reset()
state= NO_VALUE;
maybe_null= 1;
null_value= 0;
- /*
- Don't reset item_type to PARAM_ITEM: it's only needed to guard
- us from item optimizations at prepare stage, when item doesn't yet
- contain a literal of some kind.
- In all other cases when this object is accessed its value is
- set (this assumption is guarded by 'state' and
- DBUG_ASSERTS(state != NO_VALUE) in all Item_param::get_*
- methods).
- */
DBUG_VOID_RETURN;
}
@@ -4441,7 +4419,6 @@ int Item_param::save_in_field(Field *field, bool no_conversions)
bool Item_param::can_return_value() const
{
- DBUG_ASSERT(has_valid_state());
// There's no "default". See comments in Item_param::save_in_field().
switch (state) {
case SHORT_DATA_VALUE:
@@ -4725,7 +4702,6 @@ bool Item_param::convert_str_value(THD *thd)
bool Item_param::basic_const_item() const
{
- DBUG_ASSERT(has_valid_state());
switch (state) {
case LONG_DATA_VALUE:
case NULL_VALUE:
@@ -4853,7 +4829,6 @@ Item_param::set_param_type_and_swap_value(Item_param *src)
{
Type_std_attributes::set(src);
set_handler(src->type_handler());
- item_type= src->item_type;
maybe_null= src->maybe_null;
null_value= src->null_value;
diff --git a/sql/item.h b/sql/item.h
index 811a0fac0ba..d8f2adab113 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -720,16 +720,28 @@ public:
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM,
- WINDOW_FUNC_ITEM, STRING_ITEM,
- INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
- COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
- PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
- FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
+ WINDOW_FUNC_ITEM,
+ /*
+ NOT NULL literal-alike constants, which do not change their
+ value during an SQL statement execution, but can optionally
+ change their value between statements:
+ - Item_literal - real NOT NULL constants
+ - Item_param - can change between statements
+ - Item_splocal - can change between statements
+ - Item_user_var_as_out_param - hack
+ Note, Item_user_var_as_out_param actually abuses the type code.
+ It should be moved out of the Item tree eventually.
+ */
+ CONST_ITEM,
+ NULL_ITEM, // Item_null or Item_param bound to NULL
+ VARBIN_ITEM,
+ COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
+ PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
+ FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
- PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
+ PARAM_ITEM, TRIGGER_FIELD_ITEM,
XPATH_NODESET, XPATH_NODESET_CMP,
- EXPR_CACHE_ITEM,
- DATE_ITEM};
+ EXPR_CACHE_ITEM};
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
@@ -1077,6 +1089,10 @@ public:
return type_handler()->Item_get_cache(thd, this);
}
virtual enum Type type() const =0;
+ bool is_of_type(Type t, Item_result cmp) const
+ {
+ return type() == t && cmp_type() == cmp;
+ }
/*
real_type() is the type of base item. This is same as type() for
most items, except Item_ref() and Item_cache_wrapper() where it
@@ -2940,6 +2956,7 @@ class Item_literal: public Item_basic_constant
public:
Item_literal(THD *thd): Item_basic_constant(thd)
{ }
+ enum Type type() const { return CONST_ITEM; }
bool check_partition_func_processor(void *int_arg) { return false;}
bool const_item() const { return true; }
bool basic_const_item() const { return true; }
@@ -3518,8 +3535,8 @@ class Item_param :public Item_basic_value,
All Item_param::set_xxx() make sure to do so.
In the state with an assigned value:
- Item_param::basic_const_item() returns true
- - Item::type() returns NULL_ITEM, INT_ITEM, REAL_ITEM, DECIMAL_ITEM,
- DATE_ITEM, STRING_ITEM, depending on the value assigned.
+ - Item::type() returns NULL_ITEM or CONST_ITEM,
+ depending on the value assigned.
So in this state Item_param behaves in many cases like a literal.
When Item_param::cleanup() is called:
@@ -3542,20 +3559,6 @@ class Item_param :public Item_basic_value,
DEFAULT_VALUE, IGNORE_VALUE
} state;
- enum Type item_type;
-
- bool has_valid_state() const
- {
- return item_type == PARAM_ITEM || state > NO_VALUE;
- }
-
- void fix_type(Type type)
- {
- item_type= type;
- DBUG_ASSERT(is_fixed());
- DBUG_ASSERT(has_valid_state());
- }
-
void fix_temporal(uint32 max_length_arg, uint decimals_arg);
struct CONVERSION_INFO
@@ -3677,13 +3680,21 @@ public:
enum Type type() const
{
- DBUG_ASSERT(has_valid_state());
- return item_type;
+ // Don't pretend to be a constant unless value for this item is set.
+ switch (state) {
+ case NO_VALUE: return PARAM_ITEM;
+ case NULL_VALUE: return NULL_ITEM;
+ case SHORT_DATA_VALUE: return CONST_ITEM;
+ case LONG_DATA_VALUE: return CONST_ITEM;
+ case DEFAULT_VALUE: return PARAM_ITEM;
+ case IGNORE_VALUE: return PARAM_ITEM;
+ }
+ DBUG_ASSERT(0);
+ return PARAM_ITEM;
}
bool is_order_clause_position() const
{
- DBUG_ASSERT(has_valid_state());
return state == SHORT_DATA_VALUE &&
type_handler()->is_order_clause_position_type();
}
@@ -3783,12 +3794,10 @@ public:
*/
bool const_item() const
{
- DBUG_ASSERT(has_valid_state());
return state != NO_VALUE;
}
virtual table_map used_tables() const
{
- DBUG_ASSERT(has_valid_state());
return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT;
}
virtual void print(String *str, enum_query_type query_type);
@@ -3878,7 +3887,6 @@ public:
unsigned_flag= flag;
}
Item_int(THD *thd, const char *str_arg, size_t length=64);
- enum Type type() const { return INT_ITEM; }
const Type_handler *type_handler() const
{ return type_handler_long_or_longlong(); }
Field *create_field_for_create_select(TABLE *table)
@@ -3977,7 +3985,6 @@ public:
Item_decimal(THD *thd, double val, int precision, int scale);
Item_decimal(THD *thd, const uchar *bin, int precision, int scale);
- enum Type type() const { return DECIMAL_ITEM; }
const Type_handler *type_handler() const { return &type_handler_newdecimal; }
longlong val_int();
double val_real();
@@ -4015,7 +4022,6 @@ public:
decimals= (uint8) decimal_par;
}
int save_in_field(Field *field, bool no_conversions);
- enum Type type() const { return REAL_ITEM; }
const Type_handler *type_handler() const { return &type_handler_double; }
double val_real() { return value; }
longlong val_int()
@@ -4139,7 +4145,6 @@ public:
{
str_value.print(to);
}
- enum Type type() const { return STRING_ITEM; }
double val_real();
longlong val_int();
String *val_str(String*)
@@ -4554,7 +4559,6 @@ public:
decimals= dec_arg;
cached_time= *ltime;
}
- enum Type type() const { return DATE_ITEM; }
bool eq(const Item *item, bool binary_cmp) const;
bool is_null()
@@ -6217,7 +6221,7 @@ public:
for any value.
*/
-class Item_cache: public Item_basic_constant,
+class Item_cache: public Item_basic_value,
public Type_handler_hybrid_field_type
{
protected:
@@ -6240,7 +6244,7 @@ protected:
table_map used_table_map;
public:
Item_cache(THD *thd):
- Item_basic_constant(thd),
+ Item_basic_value(thd),
Type_handler_hybrid_field_type(&type_handler_string),
example(0), cached_field(0),
value_cached(0),
@@ -6251,7 +6255,7 @@ public:
}
protected:
Item_cache(THD *thd, const Type_handler *handler):
- Item_basic_constant(thd),
+ Item_basic_value(thd),
Type_handler_hybrid_field_type(handler),
example(0), cached_field(0),
value_cached(0),
@@ -6308,7 +6312,7 @@ public:
void cleanup()
{
clear();
- Item_basic_constant::cleanup();
+ Item_basic_value::cleanup();
}
/**
Check if saved item has a non-NULL value.
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 5f1860deb14..d9d8735d9fe 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1919,7 +1919,7 @@ void Item_func_neg::fix_length_and_dec_int()
longlong val= args[0]->val_int();
if ((ulonglong) val >= (ulonglong) LONGLONG_MIN &&
((ulonglong) val != (ulonglong) LONGLONG_MIN ||
- args[0]->type() != INT_ITEM))
+ !args[0]->is_of_type(CONST_ITEM, INT_RESULT)))
{
/*
Ensure that result is converted to DECIMAL, as longlong can't hold
diff --git a/sql/item_func.h b/sql/item_func.h
index 2de7fc69b59..3e429d331d5 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -2547,7 +2547,7 @@ public:
return NULL;
}
/* We should return something different from FIELD_ITEM here */
- enum Type type() const { return STRING_ITEM;}
+ enum Type type() const { return CONST_ITEM;}
double val_real();
longlong val_int();
String *val_str(String *str);
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index ceb2055dc16..12fb63925ce 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -70,32 +70,6 @@ static void reset_start_time_for_sp(THD *thd)
}
-Item::Type
-sp_map_item_type(const Type_handler *handler)
-{
- if (handler == &type_handler_row)
- return Item::ROW_ITEM;
-
- switch (handler->real_field_type()) {
- case MYSQL_TYPE_BIT:
- case MYSQL_TYPE_TINY:
- case MYSQL_TYPE_SHORT:
- case MYSQL_TYPE_LONG:
- case MYSQL_TYPE_LONGLONG:
- case MYSQL_TYPE_INT24:
- return Item::INT_ITEM;
- case MYSQL_TYPE_DECIMAL:
- case MYSQL_TYPE_NEWDECIMAL:
- return Item::DECIMAL_ITEM;
- case MYSQL_TYPE_FLOAT:
- case MYSQL_TYPE_DOUBLE:
- return Item::REAL_ITEM;
- default:
- return Item::STRING_ITEM;
- }
-}
-
-
bool Item_splocal::append_for_log(THD *thd, String *str)
{
if (fix_fields_if_needed(thd, NULL))
diff --git a/sql/sp_head.h b/sql/sp_head.h
index c0c0c83b77e..5c9183f79ab 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -39,9 +39,6 @@
@{
*/
-Item::Type
-sp_map_item_type(const Type_handler *handler);
-
uint
sp_get_flags_for_command(LEX *lex);