1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-21 21:22:27 +03:00

MDEV-14630 Replace {STRING|INT|REAL|DECIMAL|DATE}_ITEM to CONST_ITEM

This commit is contained in:
Alexander Barkov
2018-06-06 14:09:06 +04:00
parent 395212446a
commit c20cd68e60
11 changed files with 148 additions and 170 deletions

View File

@ -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 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);
} }

View File

@ -1806,10 +1806,10 @@ Item_splocal::Item_splocal(THD *thd,
Rewritable_query_parameter(pos_in_q, len_in_q), Rewritable_query_parameter(pos_in_q, len_in_q),
Type_handler_hybrid_field_type(handler), Type_handler_hybrid_field_type(handler),
m_rcontext_handler(rh), 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; 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 bool Item_basic_value::eq(const Item *item, bool binary_cmp) const
{ {
const Item_basic_value *other= item->get_item_basic_value(); const Item_basic_value *other= item->get_item_basic_value();
Type other_type; // Exclude CACHE_ITEM and VARBIN_ITEM
// Exclude CACHE_OTEM and VARBIN_ITEM if (!other || type() != other->type())
if (!other ||
(other_type= other->type()) == CACHE_ITEM ||
other_type == VARBIN_ITEM)
return false; return false;
const Type_handler *h= type_handler()->type_handler_for_comparison(); const Type_handler *h= type_handler()->type_handler_for_comparison();
bool res= (h == other->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), Type_handler_hybrid_field_type(&type_handler_null),
state(NO_VALUE), 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), m_empty_string_is_null(false),
indicator(STMT_INDICATOR_NONE), indicator(STMT_INDICATOR_NONE),
m_out_param_info(NULL), m_out_param_info(NULL),
@ -4080,7 +4075,6 @@ void Item_param::set_null()
max_length= 0; max_length= 0;
decimals= 0; decimals= 0;
state= NULL_VALUE; state= NULL_VALUE;
fix_type(Item::NULL_ITEM);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
@ -4095,7 +4089,6 @@ void Item_param::set_int(longlong i, uint32 max_length_arg)
decimals= 0; decimals= 0;
maybe_null= 0; maybe_null= 0;
null_value= 0; null_value= 0;
fix_type(Item::INT_ITEM);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
@ -4110,7 +4103,6 @@ void Item_param::set_double(double d)
decimals= NOT_FIXED_DEC; decimals= NOT_FIXED_DEC;
maybe_null= 0; maybe_null= 0;
null_value= 0; null_value= 0;
fix_type(Item::REAL_ITEM);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
@ -4143,7 +4135,6 @@ void Item_param::set_decimal(const char *str, ulong length)
decimals, unsigned_flag); decimals, unsigned_flag);
maybe_null= 0; maybe_null= 0;
null_value= 0; null_value= 0;
fix_type(Item::DECIMAL_ITEM);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
@ -4161,7 +4152,6 @@ void Item_param::set_decimal(const my_decimal *dv, bool unsigned_arg)
decimals, unsigned_flag); decimals, unsigned_flag);
maybe_null= 0; maybe_null= 0;
null_value= 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; decimals= decimals_arg;
maybe_null= 0; maybe_null= 0;
null_value= 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; null_value= 0;
/* max_length and decimals are set after charset conversion */ /* max_length and decimals are set after charset conversion */
/* sic: str may be not null-terminated, don't add DBUG_PRINT here */ /* sic: str may be not null-terminated, don't add DBUG_PRINT here */
fix_type(Item::STRING_ITEM);
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }
@ -4292,7 +4280,6 @@ bool Item_param::set_longdata(const char *str, ulong length)
state= LONG_DATA_VALUE; state= LONG_DATA_VALUE;
maybe_null= 0; maybe_null= 0;
null_value= 0; null_value= 0;
fix_type(Item::STRING_ITEM);
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }
@ -4394,15 +4381,6 @@ void Item_param::reset()
state= NO_VALUE; state= NO_VALUE;
maybe_null= 1; maybe_null= 1;
null_value= 0; 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; 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 bool Item_param::can_return_value() const
{ {
DBUG_ASSERT(has_valid_state());
// There's no "default". See comments in Item_param::save_in_field(). // There's no "default". See comments in Item_param::save_in_field().
switch (state) { switch (state) {
case SHORT_DATA_VALUE: case SHORT_DATA_VALUE:
@ -4725,7 +4702,6 @@ bool Item_param::convert_str_value(THD *thd)
bool Item_param::basic_const_item() const bool Item_param::basic_const_item() const
{ {
DBUG_ASSERT(has_valid_state());
switch (state) { switch (state) {
case LONG_DATA_VALUE: case LONG_DATA_VALUE:
case NULL_VALUE: case NULL_VALUE:
@ -4853,7 +4829,6 @@ Item_param::set_param_type_and_swap_value(Item_param *src)
{ {
Type_std_attributes::set(src); Type_std_attributes::set(src);
set_handler(src->type_handler()); set_handler(src->type_handler());
item_type= src->item_type;
maybe_null= src->maybe_null; maybe_null= src->maybe_null;
null_value= src->null_value; null_value= src->null_value;

View File

@ -720,16 +720,28 @@ public:
static void operator delete(void *ptr, MEM_ROOT *mem_root) {} static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM,
WINDOW_FUNC_ITEM, STRING_ITEM, WINDOW_FUNC_ITEM,
INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM, /*
COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM, NOT NULL literal-alike constants, which do not change their
PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM, value during an SQL statement execution, but can optionally
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM, 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, 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, XPATH_NODESET, XPATH_NODESET_CMP,
EXPR_CACHE_ITEM, EXPR_CACHE_ITEM};
DATE_ITEM};
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE }; enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
@ -1077,6 +1089,10 @@ public:
return type_handler()->Item_get_cache(thd, this); return type_handler()->Item_get_cache(thd, this);
} }
virtual enum Type type() const =0; 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 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 most items, except Item_ref() and Item_cache_wrapper() where it
@ -2940,6 +2956,7 @@ class Item_literal: public Item_basic_constant
public: public:
Item_literal(THD *thd): Item_basic_constant(thd) 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 check_partition_func_processor(void *int_arg) { return false;}
bool const_item() const { return true; } bool const_item() const { return true; }
bool basic_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. All Item_param::set_xxx() make sure to do so.
In the state with an assigned value: In the state with an assigned value:
- Item_param::basic_const_item() returns true - Item_param::basic_const_item() returns true
- Item::type() returns NULL_ITEM, INT_ITEM, REAL_ITEM, DECIMAL_ITEM, - Item::type() returns NULL_ITEM or CONST_ITEM,
DATE_ITEM, STRING_ITEM, depending on the value assigned. depending on the value assigned.
So in this state Item_param behaves in many cases like a literal. So in this state Item_param behaves in many cases like a literal.
When Item_param::cleanup() is called: When Item_param::cleanup() is called:
@ -3542,20 +3559,6 @@ class Item_param :public Item_basic_value,
DEFAULT_VALUE, IGNORE_VALUE DEFAULT_VALUE, IGNORE_VALUE
} state; } 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); void fix_temporal(uint32 max_length_arg, uint decimals_arg);
struct CONVERSION_INFO struct CONVERSION_INFO
@ -3677,13 +3680,21 @@ public:
enum Type type() const enum Type type() const
{ {
DBUG_ASSERT(has_valid_state()); // Don't pretend to be a constant unless value for this item is set.
return item_type; 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 bool is_order_clause_position() const
{ {
DBUG_ASSERT(has_valid_state());
return state == SHORT_DATA_VALUE && return state == SHORT_DATA_VALUE &&
type_handler()->is_order_clause_position_type(); type_handler()->is_order_clause_position_type();
} }
@ -3783,12 +3794,10 @@ public:
*/ */
bool const_item() const bool const_item() const
{ {
DBUG_ASSERT(has_valid_state());
return state != NO_VALUE; return state != NO_VALUE;
} }
virtual table_map used_tables() const virtual table_map used_tables() const
{ {
DBUG_ASSERT(has_valid_state());
return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT;
} }
virtual void print(String *str, enum_query_type query_type); virtual void print(String *str, enum_query_type query_type);
@ -3878,7 +3887,6 @@ public:
unsigned_flag= flag; unsigned_flag= flag;
} }
Item_int(THD *thd, const char *str_arg, size_t length=64); 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 const Type_handler *type_handler() const
{ return type_handler_long_or_longlong(); } { return type_handler_long_or_longlong(); }
Field *create_field_for_create_select(TABLE *table) 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, double val, int precision, int scale);
Item_decimal(THD *thd, const uchar *bin, 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; } const Type_handler *type_handler() const { return &type_handler_newdecimal; }
longlong val_int(); longlong val_int();
double val_real(); double val_real();
@ -4015,7 +4022,6 @@ public:
decimals= (uint8) decimal_par; decimals= (uint8) decimal_par;
} }
int save_in_field(Field *field, bool no_conversions); 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; } const Type_handler *type_handler() const { return &type_handler_double; }
double val_real() { return value; } double val_real() { return value; }
longlong val_int() longlong val_int()
@ -4139,7 +4145,6 @@ public:
{ {
str_value.print(to); str_value.print(to);
} }
enum Type type() const { return STRING_ITEM; }
double val_real(); double val_real();
longlong val_int(); longlong val_int();
String *val_str(String*) String *val_str(String*)
@ -4554,7 +4559,6 @@ public:
decimals= dec_arg; decimals= dec_arg;
cached_time= *ltime; cached_time= *ltime;
} }
enum Type type() const { return DATE_ITEM; }
bool eq(const Item *item, bool binary_cmp) const; bool eq(const Item *item, bool binary_cmp) const;
bool is_null() bool is_null()
@ -6217,7 +6221,7 @@ public:
for any value. for any value.
*/ */
class Item_cache: public Item_basic_constant, class Item_cache: public Item_basic_value,
public Type_handler_hybrid_field_type public Type_handler_hybrid_field_type
{ {
protected: protected:
@ -6240,7 +6244,7 @@ protected:
table_map used_table_map; table_map used_table_map;
public: public:
Item_cache(THD *thd): Item_cache(THD *thd):
Item_basic_constant(thd), Item_basic_value(thd),
Type_handler_hybrid_field_type(&type_handler_string), Type_handler_hybrid_field_type(&type_handler_string),
example(0), cached_field(0), example(0), cached_field(0),
value_cached(0), value_cached(0),
@ -6251,7 +6255,7 @@ public:
} }
protected: protected:
Item_cache(THD *thd, const Type_handler *handler): Item_cache(THD *thd, const Type_handler *handler):
Item_basic_constant(thd), Item_basic_value(thd),
Type_handler_hybrid_field_type(handler), Type_handler_hybrid_field_type(handler),
example(0), cached_field(0), example(0), cached_field(0),
value_cached(0), value_cached(0),
@ -6308,7 +6312,7 @@ public:
void cleanup() void cleanup()
{ {
clear(); clear();
Item_basic_constant::cleanup(); Item_basic_value::cleanup();
} }
/** /**
Check if saved item has a non-NULL value. Check if saved item has a non-NULL value.

View File

@ -1919,7 +1919,7 @@ void Item_func_neg::fix_length_and_dec_int()
longlong val= args[0]->val_int(); longlong val= args[0]->val_int();
if ((ulonglong) val >= (ulonglong) LONGLONG_MIN && if ((ulonglong) val >= (ulonglong) LONGLONG_MIN &&
((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 Ensure that result is converted to DECIMAL, as longlong can't hold

View File

@ -2547,7 +2547,7 @@ public:
return NULL; return NULL;
} }
/* We should return something different from FIELD_ITEM here */ /* 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(); double val_real();
longlong val_int(); longlong val_int();
String *val_str(String *str); String *val_str(String *str);

View File

@ -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) bool Item_splocal::append_for_log(THD *thd, String *str)
{ {
if (fix_fields_if_needed(thd, NULL)) if (fix_fields_if_needed(thd, NULL))

View File

@ -39,9 +39,6 @@
@{ @{
*/ */
Item::Type
sp_map_item_type(const Type_handler *handler);
uint uint
sp_get_flags_for_command(LEX *lex); sp_get_flags_for_command(LEX *lex);

View File

@ -2726,37 +2726,44 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond)
if (!i && (ismul)) if (!i && (ismul))
return NULL; return NULL;
switch (args[i]->real_type()) { switch (args[i]->real_type()) {
case COND::STRING_ITEM: case COND::CONST_ITEM:
res= pval->val_str(&tmp); switch (args[i]->cmp_type()) {
pp->Value= PlugSubAllocStr(g, NULL, res->ptr(), res->length()); case STRING_RESULT:
pp->Type= (pp->Value) ? TYPE_STRING : TYPE_ERROR; res= pval->val_str(&tmp);
break; pp->Value= PlugSubAllocStr(g, NULL, res->ptr(), res->length());
case COND::INT_ITEM: pp->Type= (pp->Value) ? TYPE_STRING : TYPE_ERROR;
pp->Type= TYPE_INT; break;
pp->Value= PlugSubAlloc(g, NULL, sizeof(int)); case INT_RESULT:
*((int*)pp->Value)= (int)pval->val_int(); pp->Type= TYPE_INT;
break; pp->Value= PlugSubAlloc(g, NULL, sizeof(int));
case COND::DATE_ITEM: *((int*)pp->Value)= (int)pval->val_int();
pp->Type= TYPE_DATE; break;
pp->Value= PlugSubAlloc(g, NULL, sizeof(int)); case TIME_RESULT:
*((int*)pp->Value)= (int)pval->val_int_from_date(); pp->Type= TYPE_DATE;
break; pp->Value= PlugSubAlloc(g, NULL, sizeof(int));
case COND::REAL_ITEM: *((int*)pp->Value)= (int)pval->val_int_from_date();
pp->Type= TYPE_DOUBLE; break;
pp->Value= PlugSubAlloc(g, NULL, sizeof(double)); case REAL_RESULT:
*((double*)pp->Value)= pval->val_real(); pp->Type= TYPE_DOUBLE;
break; pp->Value= PlugSubAlloc(g, NULL, sizeof(double));
case COND::DECIMAL_ITEM: *((double*)pp->Value)= pval->val_real();
pp->Type= TYPE_DOUBLE; break;
pp->Value= PlugSubAlloc(g, NULL, sizeof(double)); case DECIMAL_RESULT:
*((double*)pp->Value)= pval->val_real_from_decimal(); pp->Type= TYPE_DOUBLE;
break; pp->Value= PlugSubAlloc(g, NULL, sizeof(double));
*((double*)pp->Value)= pval->val_real_from_decimal();
break;
case ROW_RESULT:
DBUG_ASSERT(0);
return NULL;
}
break;
case COND::CACHE_ITEM: // Possible ??? case COND::CACHE_ITEM: // Possible ???
case COND::NULL_ITEM: // TODO: handle this case COND::NULL_ITEM: // TODO: handle this
default: default:
return NULL; return NULL;
} // endswitch type } // endswitch type
if (trace(1)) if (trace(1))
htrc("Value type=%hd\n", pp->Type); htrc("Value type=%hd\n", pp->Type);
@ -3008,12 +3015,8 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
Item::Type type= args[i]->real_type(); Item::Type type= args[i]->real_type();
switch (type) { switch (type) {
case COND::STRING_ITEM: case COND::CONST_ITEM:
case COND::INT_ITEM:
case COND::REAL_ITEM:
case COND::NULL_ITEM: case COND::NULL_ITEM:
case COND::DECIMAL_ITEM:
case COND::DATE_ITEM:
case COND::CACHE_ITEM: case COND::CACHE_ITEM:
break; break;
default: default:

View File

@ -179,17 +179,17 @@ namespace mrn {
NormalizedType normalized_type = normalize_field_type(field_type); NormalizedType normalized_type = normalize_field_type(field_type);
switch (normalized_type) { switch (normalized_type) {
case STRING_TYPE: case STRING_TYPE:
if (value_item->type() == Item::STRING_ITEM && if (value_item->is_of_type(Item::CONST_ITEM, STRING_RESULT) &&
func_type == Item_func::EQ_FUNC) { func_type == Item_func::EQ_FUNC) {
convertable = have_index(field_item, GRN_OP_EQUAL); convertable = have_index(field_item, GRN_OP_EQUAL);
} }
break; break;
case INT_TYPE: case INT_TYPE:
if (field_type == MYSQL_TYPE_ENUM) { if (field_type == MYSQL_TYPE_ENUM) {
convertable = (value_item->type() == Item::STRING_ITEM || convertable = value_item->is_of_type(Item::CONST_ITEM, STRING_RESULT) ||
value_item->type() == Item::INT_ITEM); value_item->is_of_type(Item::CONST_ITEM, INT_RESULT);
} else { } else {
convertable = value_item->type() == Item::INT_ITEM; convertable = value_item->is_of_type(Item::CONST_ITEM, INT_RESULT);
} }
break; break;
case TIME_TYPE: case TIME_TYPE:
@ -215,14 +215,14 @@ namespace mrn {
NormalizedType normalized_type = normalize_field_type(field_type); NormalizedType normalized_type = normalize_field_type(field_type);
switch (normalized_type) { switch (normalized_type) {
case STRING_TYPE: case STRING_TYPE:
if (min_item->type() == Item::STRING_ITEM && if (min_item->is_of_type(Item::CONST_ITEM, STRING_RESULT) &&
max_item->type() == Item::STRING_ITEM) { max_item->is_of_type(Item::CONST_ITEM, STRING_RESULT)) {
convertable = have_index(field_item, GRN_OP_LESS); convertable = have_index(field_item, GRN_OP_LESS);
} }
break; break;
case INT_TYPE: case INT_TYPE:
if (min_item->type() == Item::INT_ITEM && if (min_item->is_of_type(Item::CONST_ITEM, INT_RESULT) &&
max_item->type() == Item::INT_ITEM) { max_item->is_of_type(Item::CONST_ITEM, INT_RESULT)) {
convertable = have_index(field_item, GRN_OP_LESS); convertable = have_index(field_item, GRN_OP_LESS);
} }
break; break;
@ -587,7 +587,7 @@ namespace mrn {
case INT_TYPE: case INT_TYPE:
grn_obj_reinit(ctx_, &value_, GRN_DB_INT64, 0); grn_obj_reinit(ctx_, &value_, GRN_DB_INT64, 0);
if (field_type == MYSQL_TYPE_ENUM) { if (field_type == MYSQL_TYPE_ENUM) {
if (const_item->type() == Item::STRING_ITEM) { if (const_item->is_of_type(Item::CONST_ITEM, STRING_RESULT)) {
String *string; String *string;
string = const_item->val_str(NULL); string = const_item->val_str(NULL);
Field_enum *enum_field = static_cast<Field_enum *>(field_item->field); Field_enum *enum_field = static_cast<Field_enum *>(field_item->field);

View File

@ -2746,7 +2746,9 @@ const Item * ha_sphinx::cond_push ( const Item *cond )
if ( !m_pShare->m_bSphinxQL ) if ( !m_pShare->m_bSphinxQL )
{ {
// on non-QL tables, intercept query=value condition for SELECT // on non-QL tables, intercept query=value condition for SELECT
if (!( args[0]->type()==Item::FIELD_ITEM && args[1]->type()==Item::STRING_ITEM )) if (!( args[0]->type()==Item::FIELD_ITEM &&
args[1]->is_of_type(Item::CONST_ITEM,
STRING_RESULT)))
break; break;
Item_field * pField = (Item_field *) args[0]; Item_field * pField = (Item_field *) args[0];
@ -2762,7 +2764,9 @@ const Item * ha_sphinx::cond_push ( const Item *cond )
} else } else
{ {
if (!( args[0]->type()==Item::FIELD_ITEM && args[1]->type()==Item::INT_ITEM )) if (!( args[0]->type()==Item::FIELD_ITEM &&
args[1]->is_of_type(Item::CONST_ITEM,
INT_RESULT)))
break; break;
// on QL tables, intercept id=value condition for DELETE // on QL tables, intercept id=value condition for DELETE

View File

@ -8449,6 +8449,35 @@ int spider_db_flush_logs(
DBUG_RETURN(0); DBUG_RETURN(0);
} }
int spider_db_print_item_type_default(
Item *item,
ha_spider *spider,
spider_string *str
) {
DBUG_ENTER("spider_db_print_item_type_default");
THD *thd = spider->trx->thd;
SPIDER_SHARE *share = spider->share;
if (spider_param_skip_default_condition(thd,
share->skip_default_condition))
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
if (str)
{
if (spider->share->access_charset->cset == system_charset_info->cset)
{
#if MYSQL_VERSION_ID < 50500
item->print(str->get_str(), QT_IS);
#else
item->print(str->get_str(), QT_TO_SYSTEM_CHARSET);
#endif
} else {
item->print(str->get_str(), QT_ORDINARY);
}
str->mem_calc();
}
DBUG_RETURN(0);
}
int spider_db_print_item_type( int spider_db_print_item_type(
Item *item, Item *item,
ha_spider *spider, ha_spider *spider,
@ -8483,14 +8512,25 @@ int spider_db_print_item_type(
case Item::ROW_ITEM: case Item::ROW_ITEM:
DBUG_RETURN(spider_db_open_item_row((Item_row *) item, spider, str, DBUG_RETURN(spider_db_open_item_row((Item_row *) item, spider, str,
alias, alias_length, dbton_id, use_fields, fields)); alias, alias_length, dbton_id, use_fields, fields));
case Item::STRING_ITEM: case Item::CONST_ITEM:
DBUG_RETURN(spider_db_open_item_string(item, spider, str, {
alias, alias_length, dbton_id, use_fields, fields)); switch (item->cmp_type()) {
case Item::INT_ITEM: case ROW_RESULT:
case Item::REAL_ITEM: DBUG_ASSERT(0);
case Item::DECIMAL_ITEM: // fall through
DBUG_RETURN(spider_db_open_item_int(item, spider, str, case TIME_RESULT:
alias, alias_length, dbton_id, use_fields, fields)); DBUG_RETURN(spider_db_print_item_type_default(item, spider, str));
case STRING_RESULT:
DBUG_RETURN(spider_db_open_item_string(item, spider, str,
alias, alias_length, dbton_id, use_fields, fields));
case INT_RESULT:
case REAL_RESULT:
case DECIMAL_RESULT:
DBUG_RETURN(spider_db_open_item_int(item, spider, str,
alias, alias_length, dbton_id, use_fields, fields));
}
DBUG_ASSERT(0);
}
case Item::CACHE_ITEM: case Item::CACHE_ITEM:
DBUG_RETURN(spider_db_open_item_cache((Item_cache *)item, spider, str, DBUG_RETURN(spider_db_open_item_cache((Item_cache *)item, spider, str,
alias, alias_length, dbton_id, use_fields, fields)); alias, alias_length, dbton_id, use_fields, fields));
@ -8504,26 +8544,7 @@ int spider_db_print_item_type(
#endif #endif
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
default: default:
THD *thd = spider->trx->thd; DBUG_RETURN(spider_db_print_item_type_default(item, spider, str));
SPIDER_SHARE *share = spider->share;
if (spider_param_skip_default_condition(thd,
share->skip_default_condition))
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
if (str)
{
if (spider->share->access_charset->cset == system_charset_info->cset)
{
#if MYSQL_VERSION_ID < 50500
item->print(str->get_str(), QT_IS);
#else
item->print(str->get_str(), QT_TO_SYSTEM_CHARSET);
#endif
} else {
item->print(str->get_str(), QT_ORDINARY);
}
str->mem_calc();
}
break;
} }
DBUG_RETURN(0); DBUG_RETURN(0);
} }