summaryrefslogtreecommitdiff
path: root/sql/item_func.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r--sql/item_func.cc197
1 files changed, 157 insertions, 40 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 2a74f2801c0..c648b34efae 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -32,6 +32,16 @@
#include "sp_rcontext.h"
#include "sp.h"
+bool check_reserved_words(LEX_STRING *name)
+{
+ if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
+ !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
+ !my_strcasecmp(system_charset_info, name->str, "SESSION"))
+ return TRUE;
+ return FALSE;
+}
+
+
static void my_coll_agg_error(DTCollation &c1, DTCollation &c2,
const char *fname)
{
@@ -192,6 +202,7 @@ Item_func::Item_func(THD *thd, Item_func *item)
bool
Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
+ DBUG_ASSERT(fixed == 0);
Item **arg,**arg_end;
#ifndef EMBEDDED_LIBRARY // Avoid compiler warning
char buff[STACK_BUFF_ALLOC]; // Max argument in function
@@ -207,8 +218,11 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++)
{
Item *item;
- /* We can't yet set item to *arg as fix_fields may change *arg */
- if ((*arg)->fix_fields(thd, tables, arg) ||
+ /*
+ We can't yet set item to *arg as fix_fields may change *arg
+ We shouldn't call fix_fields() twice, so check 'fixed' field first
+ */
+ if ((!(*arg)->fixed && (*arg)->fix_fields(thd, tables, arg)) ||
(*arg)->check_cols(allowed_arg_cols))
return 1; /* purecov: inspected */
item= *arg;
@@ -373,6 +387,7 @@ Field *Item_func::tmp_table_field(TABLE *t_arg)
String *Item_real_func::val_str(String *str)
{
+ DBUG_ASSERT(fixed == 1);
double nr=val();
if (null_value)
return 0; /* purecov: inspected */
@@ -383,6 +398,7 @@ String *Item_real_func::val_str(String *str)
String *Item_num_func::val_str(String *str)
{
+ DBUG_ASSERT(fixed == 1);
if (hybrid_type == INT_RESULT)
{
longlong nr=val_int();
@@ -421,6 +437,7 @@ Item *Item_func::get_tmp_table_item(THD *thd)
String *Item_int_func::val_str(String *str)
{
+ DBUG_ASSERT(fixed == 1);
longlong nr=val_int();
if (null_value)
return 0;
@@ -448,6 +465,7 @@ void Item_num_op::find_num_type(void)
String *Item_num_op::val_str(String *str)
{
+ DBUG_ASSERT(fixed == 1);
if (hybrid_type == INT_RESULT)
{
longlong nr=val_int();
@@ -489,6 +507,7 @@ void Item_func_unsigned::print(String *str)
double Item_func_plus::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val()+args[1]->val();
if ((null_value=args[0]->null_value || args[1]->null_value))
return 0.0;
@@ -497,6 +516,7 @@ double Item_func_plus::val()
longlong Item_func_plus::val_int()
{
+ DBUG_ASSERT(fixed == 1);
if (hybrid_type == INT_RESULT)
{
longlong value=args[0]->val_int()+args[1]->val_int();
@@ -524,6 +544,7 @@ void Item_func_minus::fix_length_and_dec()
double Item_func_minus::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val() - args[1]->val();
if ((null_value=args[0]->null_value || args[1]->null_value))
return 0.0;
@@ -532,6 +553,7 @@ double Item_func_minus::val()
longlong Item_func_minus::val_int()
{
+ DBUG_ASSERT(fixed == 1);
if (hybrid_type == INT_RESULT)
{
longlong value=args[0]->val_int() - args[1]->val_int();
@@ -545,6 +567,7 @@ longlong Item_func_minus::val_int()
double Item_func_mul::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val()*args[1]->val();
if ((null_value=args[0]->null_value || args[1]->null_value))
return 0.0; /* purecov: inspected */
@@ -553,6 +576,7 @@ double Item_func_mul::val()
longlong Item_func_mul::val_int()
{
+ DBUG_ASSERT(fixed == 1);
if (hybrid_type == INT_RESULT)
{
longlong value=args[0]->val_int()*args[1]->val_int();
@@ -566,6 +590,7 @@ longlong Item_func_mul::val_int()
double Item_func_div::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
double val2=args[1]->val();
if ((null_value= val2 == 0.0 || args[0]->null_value || args[1]->null_value))
@@ -575,6 +600,7 @@ double Item_func_div::val()
longlong Item_func_div::val_int()
{
+ DBUG_ASSERT(fixed == 1);
if (hybrid_type == INT_RESULT)
{
longlong value=args[0]->val_int();
@@ -599,6 +625,7 @@ void Item_func_div::fix_length_and_dec()
/* Integer division */
longlong Item_func_int_div::val_int()
{
+ DBUG_ASSERT(fixed == 1);
longlong value=args[0]->val_int();
longlong val2=args[1]->val_int();
if ((null_value= val2 == 0 || args[0]->null_value || args[1]->null_value))
@@ -619,6 +646,7 @@ void Item_func_int_div::fix_length_and_dec()
double Item_func_mod::val()
{
+ DBUG_ASSERT(fixed == 1);
double value= floor(args[0]->val()+0.5);
double val2=floor(args[1]->val()+0.5);
if ((null_value=val2 == 0.0 || args[0]->null_value || args[1]->null_value))
@@ -628,6 +656,7 @@ double Item_func_mod::val()
longlong Item_func_mod::val_int()
{
+ DBUG_ASSERT(fixed == 1);
longlong value= args[0]->val_int();
longlong val2= args[1]->val_int();
if ((null_value=val2 == 0 || args[0]->null_value || args[1]->null_value))
@@ -646,6 +675,7 @@ void Item_func_mod::fix_length_and_dec()
double Item_func_neg::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
null_value=args[0]->null_value;
return -value;
@@ -654,6 +684,7 @@ double Item_func_neg::val()
longlong Item_func_neg::val_int()
{
+ DBUG_ASSERT(fixed == 1);
longlong value=args[0]->val_int();
null_value=args[0]->null_value;
return -value;
@@ -687,6 +718,7 @@ void Item_func_neg::fix_length_and_dec()
double Item_func_abs::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
null_value=args[0]->null_value;
return fabs(value);
@@ -695,6 +727,7 @@ double Item_func_abs::val()
longlong Item_func_abs::val_int()
{
+ DBUG_ASSERT(fixed == 1);
longlong value=args[0]->val_int();
null_value=args[0]->null_value;
return value >= 0 ? value : -value;
@@ -717,6 +750,7 @@ void Item_func_abs::fix_length_and_dec()
/* Gateway to natural LOG function */
double Item_func_ln::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=(args[0]->null_value || value <= 0.0)))
return 0.0;
@@ -730,6 +764,7 @@ double Item_func_ln::val()
*/
double Item_func_log::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=(args[0]->null_value || value <= 0.0)))
return 0.0;
@@ -745,6 +780,7 @@ double Item_func_log::val()
double Item_func_log2::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=(args[0]->null_value || value <= 0.0)))
return 0.0;
@@ -753,6 +789,7 @@ double Item_func_log2::val()
double Item_func_log10::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=(args[0]->null_value || value <= 0.0)))
return 0.0; /* purecov: inspected */
@@ -761,6 +798,7 @@ double Item_func_log10::val()
double Item_func_exp::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=args[0]->null_value))
return 0.0; /* purecov: inspected */
@@ -769,6 +807,7 @@ double Item_func_exp::val()
double Item_func_sqrt::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=(args[0]->null_value || value < 0)))
return 0.0; /* purecov: inspected */
@@ -777,6 +816,7 @@ double Item_func_sqrt::val()
double Item_func_pow::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
double val2=args[1]->val();
if ((null_value=(args[0]->null_value || args[1]->null_value)))
@@ -788,7 +828,9 @@ double Item_func_pow::val()
double Item_func_acos::val()
{
- double value=args[0]->val();
+ DBUG_ASSERT(fixed == 1);
+ // the volatile's for BUG #2338 to calm optimizer down (because of gcc's bug)
+ volatile double value=args[0]->val();
if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0))))
return 0.0;
return fix_result(acos(value));
@@ -796,7 +838,9 @@ double Item_func_acos::val()
double Item_func_asin::val()
{
- double value=args[0]->val();
+ DBUG_ASSERT(fixed == 1);
+ // the volatile's for BUG #2338 to calm optimizer down (because of gcc's bug)
+ volatile double value=args[0]->val();
if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0))))
return 0.0;
return fix_result(asin(value));
@@ -804,6 +848,7 @@ double Item_func_asin::val()
double Item_func_atan::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=args[0]->null_value))
return 0.0;
@@ -819,6 +864,7 @@ double Item_func_atan::val()
double Item_func_cos::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=args[0]->null_value))
return 0.0;
@@ -827,6 +873,7 @@ double Item_func_cos::val()
double Item_func_sin::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=args[0]->null_value))
return 0.0;
@@ -835,6 +882,7 @@ double Item_func_sin::val()
double Item_func_tan::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=args[0]->null_value))
return 0.0;
@@ -847,6 +895,7 @@ double Item_func_tan::val()
longlong Item_func_shift_left::val_int()
{
+ DBUG_ASSERT(fixed == 1);
uint shift;
ulonglong res= ((ulonglong) args[0]->val_int() <<
(shift=(uint) args[1]->val_int()));
@@ -861,6 +910,7 @@ longlong Item_func_shift_left::val_int()
longlong Item_func_shift_right::val_int()
{
+ DBUG_ASSERT(fixed == 1);
uint shift;
ulonglong res= (ulonglong) args[0]->val_int() >>
(shift=(uint) args[1]->val_int());
@@ -876,6 +926,7 @@ longlong Item_func_shift_right::val_int()
longlong Item_func_bit_neg::val_int()
{
+ DBUG_ASSERT(fixed == 1);
ulonglong res= (ulonglong) args[0]->val_int();
if ((null_value=args[0]->null_value))
return 0;
@@ -895,6 +946,7 @@ void Item_func_integer::fix_length_and_dec()
longlong Item_func_ceiling::val_int()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
null_value=args[0]->null_value;
return (longlong) ceil(value);
@@ -902,7 +954,9 @@ longlong Item_func_ceiling::val_int()
longlong Item_func_floor::val_int()
{
- double value=args[0]->val();
+ DBUG_ASSERT(fixed == 1);
+ // the volatile's for BUG #3051 to calm optimizer down (because of gcc's bug)
+ volatile double value=args[0]->val();
null_value=args[0]->null_value;
return (longlong) floor(value);
}
@@ -923,6 +977,7 @@ void Item_func_round::fix_length_and_dec()
double Item_func_round::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
int dec=(int) args[1]->val_int();
uint abs_dec=abs(dec);
@@ -955,6 +1010,7 @@ void Item_func_rand::fix_length_and_dec()
{
decimals=NOT_FIXED_DEC;
max_length=float_length(decimals);
+ used_tables_cache|= RAND_TABLE_BIT;
if (arg_count)
{ // Only use argument once in query
uint32 tmp= (uint32) (args[0]->val_int());
@@ -980,14 +1036,22 @@ void Item_func_rand::fix_length_and_dec()
}
}
+void Item_func_rand::update_used_tables()
+{
+ Item_real_func::update_used_tables();
+ used_tables_cache|= RAND_TABLE_BIT;
+}
+
double Item_func_rand::val()
{
+ DBUG_ASSERT(fixed == 1);
return my_rnd(rand);
}
longlong Item_func_sign::val_int()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
null_value=args[0]->null_value;
return value < 0.0 ? -1 : (value > 0 ? 1 : 0);
@@ -996,6 +1060,7 @@ longlong Item_func_sign::val_int()
double Item_func_units::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=args[0]->val();
if ((null_value=args[0]->null_value))
return 0;
@@ -1027,6 +1092,7 @@ void Item_func_min_max::fix_length_and_dec()
String *Item_func_min_max::val_str(String *str)
{
+ DBUG_ASSERT(fixed == 1);
switch (cmp_type) {
case INT_RESULT:
{
@@ -1080,7 +1146,6 @@ String *Item_func_min_max::val_str(String *str)
// This case should never be choosen
DBUG_ASSERT(0);
return 0;
-
}
return 0; // Keep compiler happy
}
@@ -1088,6 +1153,7 @@ String *Item_func_min_max::val_str(String *str)
double Item_func_min_max::val()
{
+ DBUG_ASSERT(fixed == 1);
double value=0.0;
null_value=1;
for (uint i=0; i < arg_count ; i++)
@@ -1110,6 +1176,7 @@ double Item_func_min_max::val()
longlong Item_func_min_max::val_int()
{
+ DBUG_ASSERT(fixed == 1);
longlong value=0;
null_value=1;
for (uint i=0; i < arg_count ; i++)
@@ -1131,6 +1198,7 @@ longlong Item_func_min_max::val_int()
longlong Item_func_length::val_int()
{
+ DBUG_ASSERT(fixed == 1);
String *res=args[0]->val_str(&value);
if (!res)
{
@@ -1144,6 +1212,7 @@ longlong Item_func_length::val_int()
longlong Item_func_char_length::val_int()
{
+ DBUG_ASSERT(fixed == 1);
String *res=args[0]->val_str(&value);
if (!res)
{
@@ -1157,6 +1226,7 @@ longlong Item_func_char_length::val_int()
longlong Item_func_coercibility::val_int()
{
+ DBUG_ASSERT(fixed == 1);
if (args[0]->null_value)
{
null_value= 1;
@@ -1176,6 +1246,7 @@ void Item_func_locate::fix_length_and_dec()
longlong Item_func_locate::val_int()
{
+ DBUG_ASSERT(fixed == 1);
String *a=args[0]->val_str(&value1);
String *b=args[1]->val_str(&value2);
if (!a || !b)
@@ -1226,6 +1297,7 @@ void Item_func_locate::print(String *str)
longlong Item_func_field::val_int()
{
+ DBUG_ASSERT(fixed == 1);
if (cmp_type == STRING_RESULT)
{
String *field;
@@ -1273,6 +1345,7 @@ void Item_func_field::fix_length_and_dec()
longlong Item_func_ascii::val_int()
{
+ DBUG_ASSERT(fixed == 1);
String *res=args[0]->val_str(&value);
if (!res)
{
@@ -1285,6 +1358,7 @@ longlong Item_func_ascii::val_int()
longlong Item_func_ord::val_int()
{
+ DBUG_ASSERT(fixed == 1);
String *res=args[0]->val_str(&value);
if (!res)
{
@@ -1339,6 +1413,7 @@ static const char separator=',';
longlong Item_func_find_in_set::val_int()
{
+ DBUG_ASSERT(fixed == 1);
if (enum_value)
{
ulonglong tmp=(ulonglong) args[1]->val_int();
@@ -1392,6 +1467,7 @@ longlong Item_func_find_in_set::val_int()
longlong Item_func_bit_count::val_int()
{
+ DBUG_ASSERT(fixed == 1);
ulonglong value= (ulonglong) args[0]->val_int();
if (args[0]->null_value)
{
@@ -1470,9 +1546,12 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
arg != arg_end ;
arg++,i++)
{
+ if ((*arg)->fix_fields(thd, tables, arg))
+ DBUG_RETURN(1);
+ // we can't assign 'item' before, because fix_fields() can change arg
Item *item= *arg;
- if (item->fix_fields(thd, tables, arg) || item->check_cols(1))
- return 1;
+ if (item->check_cols(1))
+ DBUG_RETURN(1);
/*
TODO: We should think about this. It is not always
right way just to set an UDF result to return my_charset_bin
@@ -1668,6 +1747,7 @@ String *udf_handler::val_str(String *str,String *save_str)
double Item_func_udf_float::val()
{
+ DBUG_ASSERT(fixed == 1);
DBUG_ENTER("Item_func_udf_float::val");
DBUG_PRINT("info",("result_type: %d arg_count: %d",
args[0]->result_type(), arg_count));
@@ -1677,6 +1757,7 @@ double Item_func_udf_float::val()
String *Item_func_udf_float::val_str(String *str)
{
+ DBUG_ASSERT(fixed == 1);
double nr=val();
if (null_value)
return 0; /* purecov: inspected */
@@ -1687,6 +1768,7 @@ String *Item_func_udf_float::val_str(String *str)
longlong Item_func_udf_int::val_int()
{
+ DBUG_ASSERT(fixed == 1);
DBUG_ENTER("Item_func_udf_int::val_int");
DBUG_PRINT("info",("result_type: %d arg_count: %d",
args[0]->result_type(), arg_count));
@@ -1697,6 +1779,7 @@ longlong Item_func_udf_int::val_int()
String *Item_func_udf_int::val_str(String *str)
{
+ DBUG_ASSERT(fixed == 1);
longlong nr=val_int();
if (null_value)
return 0;
@@ -1720,6 +1803,7 @@ void Item_func_udf_str::fix_length_and_dec()
String *Item_func_udf_str::val_str(String *str)
{
+ DBUG_ASSERT(fixed == 1);
String *res=udf.val_str(str,&str_value);
null_value = !res;
return res;
@@ -1736,7 +1820,7 @@ bool udf_handler::get_arguments() { return 0; }
pthread_mutex_t LOCK_user_locks;
static HASH hash_user_locks;
-class ULL
+class User_level_lock
{
char *key;
uint key_length;
@@ -1748,7 +1832,7 @@ public:
pthread_t thread;
ulong thread_id;
- ULL(const char *key_arg,uint length, ulong id)
+ User_level_lock(const char *key_arg,uint length, ulong id)
:key_length(length),count(1),locked(1), thread_id(id)
{
key=(char*) my_memdup((byte*) key_arg,length,MYF(0));
@@ -1762,7 +1846,7 @@ public:
}
}
}
- ~ULL()
+ ~User_level_lock()
{
if (key)
{
@@ -1772,11 +1856,12 @@ public:
pthread_cond_destroy(&cond);
}
inline bool initialized() { return key != 0; }
- friend void item_user_lock_release(ULL *ull);
- friend char *ull_get_key(const ULL *ull,uint *length,my_bool not_used);
+ friend void item_user_lock_release(User_level_lock *ull);
+ friend char *ull_get_key(const User_level_lock *ull, uint *length,
+ my_bool not_used);
};
-char *ull_get_key(const ULL *ull,uint *length,
+char *ull_get_key(const User_level_lock *ull, uint *length,
my_bool not_used __attribute__((unused)))
{
*length=(uint) ull->key_length;
@@ -1804,7 +1889,7 @@ void item_user_lock_free(void)
}
}
-void item_user_lock_release(ULL *ull)
+void item_user_lock_release(User_level_lock *ull)
{
ull->locked=0;
if (mysql_bin_log.is_open())
@@ -1832,6 +1917,7 @@ void item_user_lock_release(ULL *ull)
longlong Item_master_pos_wait::val_int()
{
+ DBUG_ASSERT(fixed == 1);
THD* thd = current_thd;
String *log_name = args[0]->val_str(&value);
int event_count= 0;
@@ -1845,13 +1931,11 @@ longlong Item_master_pos_wait::val_int()
longlong pos = (ulong)args[1]->val_int();
longlong timeout = (arg_count==3) ? args[2]->val_int() : 0 ;
#ifdef HAVE_REPLICATION
- LOCK_ACTIVE_MI;
- if ((event_count = active_mi->rli.wait_for_pos(thd, log_name, pos, timeout)) == -2)
- {
+ if ((event_count = active_mi->rli.wait_for_pos(thd, log_name, pos, timeout)) == -2)
+ {
null_value = 1;
event_count=0;
}
- UNLOCK_ACTIVE_MI;
#endif
return event_count;
}
@@ -1860,7 +1944,7 @@ longlong Item_master_pos_wait::val_int()
void debug_sync_point(const char* lock_name, uint lock_timeout)
{
THD* thd=current_thd;
- ULL* ull;
+ User_level_lock* ull;
struct timespec abstime;
int lock_name_len,error=0;
lock_name_len=strlen(lock_name);
@@ -1878,7 +1962,7 @@ void debug_sync_point(const char* lock_name, uint lock_timeout)
this case, we will not be waiting, but rather, just waste CPU and
memory on the whole deal
*/
- if (!(ull= ((ULL*) hash_search(&hash_user_locks,lock_name,
+ if (!(ull= ((User_level_lock*) hash_search(&hash_user_locks, lock_name,
lock_name_len))))
{
pthread_mutex_unlock(&LOCK_user_locks);
@@ -1935,11 +2019,12 @@ void debug_sync_point(const char* lock_name, uint lock_timeout)
longlong Item_func_get_lock::val_int()
{
+ DBUG_ASSERT(fixed == 1);
String *res=args[0]->val_str(&value);
longlong timeout=args[1]->val_int();
struct timespec abstime;
THD *thd=current_thd;
- ULL *ull;
+ User_level_lock *ull;
int error=0;
pthread_mutex_lock(&LOCK_user_locks);
@@ -1958,10 +2043,11 @@ longlong Item_func_get_lock::val_int()
thd->ull=0;
}
- if (!(ull= ((ULL*) hash_search(&hash_user_locks,(byte*) res->ptr(),
- res->length()))))
+ if (!(ull= ((User_level_lock *) hash_search(&hash_user_locks,
+ (byte*) res->ptr(),
+ res->length()))))
{
- ull=new ULL(res->ptr(),res->length(), thd->thread_id);
+ ull=new User_level_lock(res->ptr(),res->length(), thd->thread_id);
if (!ull || !ull->initialized())
{
delete ull;
@@ -2029,8 +2115,9 @@ longlong Item_func_get_lock::val_int()
longlong Item_func_release_lock::val_int()
{
+ DBUG_ASSERT(fixed == 1);
String *res=args[0]->val_str(&value);
- ULL *ull;
+ User_level_lock *ull;
longlong result;
if (!res || !res->length())
{
@@ -2041,8 +2128,9 @@ longlong Item_func_release_lock::val_int()
result=0;
pthread_mutex_lock(&LOCK_user_locks);
- if (!(ull= ((ULL*) hash_search(&hash_user_locks,(const byte*) res->ptr(),
- res->length()))))
+ if (!(ull= ((User_level_lock*) hash_search(&hash_user_locks,
+ (const byte*) res->ptr(),
+ res->length()))))
{
null_value=1;
}
@@ -2060,18 +2148,29 @@ longlong Item_func_release_lock::val_int()
}
-longlong Item_func_set_last_insert_id::val_int()
+longlong Item_func_last_insert_id::val_int()
{
- longlong value=args[0]->val_int();
- current_thd->insert_id(value);
- null_value=args[0]->null_value;
- return value;
+ DBUG_ASSERT(fixed == 1);
+ if (arg_count)
+ {
+ longlong value=args[0]->val_int();
+ current_thd->insert_id(value);
+ null_value=args[0]->null_value;
+ return value;
+ }
+ else
+ {
+ Item *it= get_system_var(current_thd, OPT_SESSION, "last_insert_id", 14,
+ "last_insert_id()");
+ return it->val_int();
+ }
}
/* This function is just used to test speed of different functions */
longlong Item_func_benchmark::val_int()
{
+ DBUG_ASSERT(fixed == 1);
char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff), &my_charset_bin);
THD *thd=current_thd;
@@ -2164,6 +2263,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
bool Item_func_set_user_var::fix_fields(THD *thd, TABLE_LIST *tables,
Item **ref)
{
+ DBUG_ASSERT(fixed == 0);
/* fix_fields will call Item_func_set_user_var::fix_length_and_dec */
if (Item_func::fix_fields(thd, tables, ref) ||
!(entry= get_variable(&thd->user_vars, name, 1)))
@@ -2264,7 +2364,7 @@ double user_var_entry::val(my_bool *null_value)
case INT_RESULT:
return (double) *(longlong*) value;
case STRING_RESULT:
- return atof(value); // This is null terminated
+ return my_atof(value); // This is null terminated
case ROW_RESULT:
DBUG_ASSERT(1); // Impossible
break;
@@ -2351,7 +2451,6 @@ Item_func_set_user_var::check()
save_result.vint= args[0]->val_int();
break;
}
- break;
case STRING_RESULT:
{
save_result.vstr= args[0]->val_str(&value);
@@ -2403,7 +2502,6 @@ Item_func_set_user_var::update()
INT_RESULT, &my_charset_bin, DERIVATION_NONE);
break;
}
- break;
case STRING_RESULT:
{
if (!save_result.vstr) // Null value
@@ -2428,6 +2526,7 @@ Item_func_set_user_var::update()
double Item_func_set_user_var::val()
{
+ DBUG_ASSERT(fixed == 1);
check();
update(); // Store expression
return entry->val(&null_value);
@@ -2435,6 +2534,7 @@ double Item_func_set_user_var::val()
longlong Item_func_set_user_var::val_int()
{
+ DBUG_ASSERT(fixed == 1);
check();
update(); // Store expression
return entry->val_int(&null_value);
@@ -2442,6 +2542,7 @@ longlong Item_func_set_user_var::val_int()
String *Item_func_set_user_var::val_str(String *str)
{
+ DBUG_ASSERT(fixed == 1);
check();
update(); // Store expression
return entry->val_str(&null_value, str, decimals);
@@ -2461,6 +2562,7 @@ void Item_func_set_user_var::print(String *str)
String *
Item_func_get_user_var::val_str(String *str)
{
+ DBUG_ASSERT(fixed == 1);
DBUG_ENTER("Item_func_get_user_var::val_str");
if (!var_entry)
DBUG_RETURN((String*) 0); // No such variable
@@ -2470,6 +2572,7 @@ Item_func_get_user_var::val_str(String *str)
double Item_func_get_user_var::val()
{
+ DBUG_ASSERT(fixed == 1);
if (!var_entry)
return 0.0; // No such variable
return (var_entry->val(&null_value));
@@ -2478,6 +2581,7 @@ double Item_func_get_user_var::val()
longlong Item_func_get_user_var::val_int()
{
+ DBUG_ASSERT(fixed == 1);
if (!var_entry)
return LL(0); // No such variable
return (var_entry->val_int(&null_value));
@@ -2624,6 +2728,7 @@ bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const
longlong Item_func_inet_aton::val_int()
{
+ DBUG_ASSERT(fixed == 1);
uint byte_result = 0;
ulonglong result = 0; // We are ready for 64 bit addresses
const char *p,* end;
@@ -2691,6 +2796,13 @@ void Item_func_match::init_search(bool no_order)
fields.push_back(args[i]);
concat=new Item_func_concat_ws(new Item_string(" ",1,
cmp_collation.collation), fields);
+ /*
+ Above function used only to get value and do not need fix_fields for it:
+ Item_string - basic constant
+ fields - fix_fields() was already called for this arguments
+ Item_func_concat_ws - do not need fix_fields() to produce value
+ */
+ concat->quick_fix_field();
}
if (master)
@@ -2733,6 +2845,7 @@ void Item_func_match::init_search(bool no_order)
bool Item_func_match::fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
{
+ DBUG_ASSERT(fixed == 0);
Item *item;
LINT_INIT(item); // Safe as arg_count is > 1
@@ -2877,6 +2990,7 @@ bool Item_func_match::eq(const Item *item, bool binary_cmp) const
double Item_func_match::val()
{
+ DBUG_ASSERT(fixed == 1);
DBUG_ENTER("Item_func_match::val");
if (ft_handler == NULL)
DBUG_RETURN(-1.0);
@@ -2919,6 +3033,7 @@ void Item_func_match::print(String *str)
longlong Item_func_bit_xor::val_int()
{
+ DBUG_ASSERT(fixed == 1);
ulonglong arg1= (ulonglong) args[0]->val_int();
ulonglong arg2= (ulonglong) args[1]->val_int();
if ((null_value= (args[0]->null_value || args[1]->null_value)))
@@ -3047,9 +3162,10 @@ Item *get_system_var(THD *thd, enum_var_type var_type, const char *var_name,
longlong Item_func_is_free_lock::val_int()
{
+ DBUG_ASSERT(fixed == 1);
String *res=args[0]->val_str(&value);
THD *thd=current_thd;
- ULL *ull;
+ User_level_lock *ull;
null_value=0;
if (!res || !res->length())
@@ -3059,7 +3175,7 @@ longlong Item_func_is_free_lock::val_int()
}
pthread_mutex_lock(&LOCK_user_locks);
- ull= (ULL*) hash_search(&hash_user_locks,(byte*) res->ptr(),
+ ull= (User_level_lock *) hash_search(&hash_user_locks, (byte*) res->ptr(),
res->length());
pthread_mutex_unlock(&LOCK_user_locks);
if (!ull || !ull->locked)
@@ -3069,16 +3185,17 @@ longlong Item_func_is_free_lock::val_int()
longlong Item_func_is_used_lock::val_int()
{
+ DBUG_ASSERT(fixed == 1);
String *res=args[0]->val_str(&value);
THD *thd=current_thd;
- ULL *ull;
+ User_level_lock *ull;
null_value=1;
if (!res || !res->length())
return 0;
pthread_mutex_lock(&LOCK_user_locks);
- ull= (ULL*) hash_search(&hash_user_locks,(byte*) res->ptr(),
+ ull= (User_level_lock *) hash_search(&hash_user_locks, (byte*) res->ptr(),
res->length());
pthread_mutex_unlock(&LOCK_user_locks);
if (!ull || !ull->locked)