summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorChad MILLER <chad@mysql.com>2008-07-10 14:50:07 -0400
committerChad MILLER <chad@mysql.com>2008-07-10 14:50:07 -0400
commitc425bf421da9ffa55d3d568f70508fa12dd07aa0 (patch)
tree667c2782c7fcee247010d3413aaf80a81fc6dd92 /sql
parent6a6e77eeffc7dbd72888ef685fdb93fc2ae7aed6 (diff)
parent0db1f520c629455b4766c3d8f57a9767d7f6a98f (diff)
downloadmariadb-git-c425bf421da9ffa55d3d568f70508fa12dd07aa0.tar.gz
Merge chunk from trunk.
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc80
-rw-r--r--sql/field.h2
-rw-r--r--sql/filesort.cc3
-rw-r--r--sql/ha_federated.cc34
-rw-r--r--sql/ha_myisam.cc64
-rw-r--r--sql/ha_myisammrg.cc6
-rw-r--r--sql/ha_ndbcluster_cond.cc9
-rw-r--r--sql/ha_ndbcluster_cond.h1
-rw-r--r--sql/handler.cc12
-rw-r--r--sql/item.cc139
-rw-r--r--sql/item.h91
-rw-r--r--sql/item_cmpfunc.cc5
-rw-r--r--sql/item_create.cc4
-rw-r--r--sql/item_func.cc16
-rw-r--r--sql/item_func.h5
-rw-r--r--sql/item_sum.cc3
-rw-r--r--sql/log.cc7
-rw-r--r--sql/log_event.cc3
-rw-r--r--sql/mysql_priv.h2
-rw-r--r--sql/mysqld.cc20
-rw-r--r--sql/repl_failsafe.cc15
-rw-r--r--sql/slave.cc103
-rw-r--r--sql/slave.h2
-rw-r--r--sql/sp.cc6
-rw-r--r--sql/sql_acl.cc4
-rw-r--r--sql/sql_base.cc8
-rw-r--r--sql/sql_class.h2
-rw-r--r--sql/sql_cursor.cc98
-rw-r--r--sql/sql_delete.cc19
-rw-r--r--sql/sql_insert.cc3
-rw-r--r--sql/sql_parse.cc60
-rw-r--r--sql/sql_prepare.cc57
-rw-r--r--sql/sql_repl.h6
-rw-r--r--sql/sql_select.cc43
-rw-r--r--sql/sql_update.cc4
-rw-r--r--sql/sql_view.cc242
-rw-r--r--sql/sql_view.h3
-rw-r--r--sql/sql_yacc.yy43
38 files changed, 864 insertions, 360 deletions
diff --git a/sql/field.cc b/sql/field.cc
index f1e2b6a4f27..53eafcaf2cc 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -5861,26 +5861,41 @@ check_string_copy_error(Field_str *field,
}
-
/*
- Send a truncation warning or a truncation error
- after storing a too long character string info a field.
+ Check if we lost any important data and send a truncation error/warning
SYNOPSIS
- report_data_too_long()
- field - Field
+ Field_longstr::report_if_important_data()
+ ptr - Truncated rest of string
+ end - End of truncated string
- RETURN
- N/A
+ RETURN VALUES
+ 0 - None was truncated (or we don't count cut fields)
+ 2 - Some bytes was truncated
+
+ NOTE
+ Check if we lost any important data (anything in a binary string,
+ or any non-space in others). If only trailing spaces was lost,
+ send a truncation note, otherwise send a truncation error.
*/
-inline void
-report_data_too_long(Field_str *field)
+int
+Field_longstr::report_if_important_data(const char *ptr, const char *end)
{
- if (field->table->in_use->abort_on_warning)
- field->set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
- else
- field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
+ if ((ptr < end) && table->in_use->count_cuted_fields)
+ {
+ if (test_if_important_data(field_charset, ptr, end))
+ {
+ if (table->in_use->abort_on_warning)
+ set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
+ else
+ set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
+ }
+ else /* If we lost only spaces then produce a NOTE, not a WARNING */
+ set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
+ return 2;
+ }
+ return 0;
}
@@ -5914,19 +5929,7 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
cannot_convert_error_pos, from + length))
return 2;
- /*
- Check if we lost any important data (anything in a binary string,
- or any non-space in others).
- */
- if ((from_end_pos < from + length) && table->in_use->count_cuted_fields)
- {
- if (test_if_important_data(field_charset, from_end_pos, from + length))
- {
- report_data_too_long(this);
- return 2;
- }
- }
- return 0;
+ return report_if_important_data(from_end_pos, from + length);
}
@@ -6385,16 +6388,7 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
cannot_convert_error_pos, from + length))
return 2;
- // Check if we lost something other than just trailing spaces
- if ((from_end_pos < from + length) && table->in_use->count_cuted_fields)
- {
- if (test_if_important_data(field_charset, from_end_pos, from + length))
- report_data_too_long(this);
- else /* If we lost only spaces then produce a NOTE, not a WARNING */
- set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
- return 2;
- }
- return 0;
+ return report_if_important_data(from_end_pos, from + length);
}
@@ -7030,13 +7024,7 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
cannot_convert_error_pos, from + length))
return 2;
- if (from_end_pos < from + length)
- {
- report_data_too_long(this);
- return 2;
- }
-
- return 0;
+ return report_if_important_data(from_end_pos, from + length);
oom_error:
/* Fatal OOM error */
@@ -7883,10 +7871,10 @@ int Field_set::store(const char *from,uint length,CHARSET_INFO *cs)
int Field_set::store(longlong nr, bool unsigned_val)
{
int error= 0;
- if ((ulonglong) nr > (ulonglong) (((longlong) 1 << typelib->count) -
- (longlong) 1))
+ ulonglong max_nr= set_bits(ulonglong, typelib->count);
+ if ((ulonglong) nr > max_nr)
{
- nr&= (longlong) (((longlong) 1 << typelib->count) - (longlong) 1);
+ nr&= max_nr;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
error=1;
}
diff --git a/sql/field.h b/sql/field.h
index d681229a9fd..c82d65147ac 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -454,6 +454,8 @@ public:
class Field_longstr :public Field_str
{
+protected:
+ int report_if_important_data(const char *ptr, const char *end);
public:
Field_longstr(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 132e91363f3..70fc6937b59 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -222,8 +222,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
sort_keys= table_sort.sort_keys;
if (memavl < min_sort_memory)
{
- my_error(ER_OUTOFMEMORY,MYF(ME_ERROR+ME_WAITTANG),
- thd->variables.sortbuff_size);
+ my_error(ER_OUT_OF_SORTMEMORY,MYF(ME_ERROR+ME_WAITTANG));
goto err;
}
if (open_cached_file(&buffpek_pointers,mysql_tmpdir,TEMP_PREFIX,
diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc
index ac1e0962ffb..d414dc34f02 100644
--- a/sql/ha_federated.cc
+++ b/sql/ha_federated.cc
@@ -643,13 +643,20 @@ static int parse_url(FEDERATED_SHARE *share, TABLE *table,
if ((strchr(share->table_name, '/')))
goto error;
+ /*
+ If hostname is omitted, we set it to NULL. According to
+ mysql_real_connect() manual:
+ The value of host may be either a hostname or an IP address.
+ If host is NULL or the string "localhost", a connection to the
+ local host is assumed.
+ */
if (share->hostname[0] == '\0')
share->hostname= NULL;
if (!share->port)
{
- if (strcmp(share->hostname, my_localhost) == 0)
- share->socket= my_strdup(MYSQL_UNIX_ADDR, MYF(0));
+ if (!share->hostname || strcmp(share->hostname, my_localhost) == 0)
+ share->socket= (char*) MYSQL_UNIX_ADDR;
else
share->port= MYSQL_PORT;
}
@@ -1094,10 +1101,20 @@ bool ha_federated::create_where_from_key(String *to,
{
if (*ptr++)
{
+ /*
+ We got "IS [NOT] NULL" condition against nullable column. We
+ distinguish between "IS NOT NULL" and "IS NULL" by flag. For
+ "IS NULL", flag is set to HA_READ_KEY_EXACT.
+ */
if (emit_key_part_name(&tmp, key_part) ||
- tmp.append(FEDERATED_ISNULL))
+ tmp.append(ranges[i]->flag == HA_READ_KEY_EXACT ?
+ FEDERATED_ISNULL : " IS NOT NULL "))
DBUG_RETURN(1);
- continue;
+ /*
+ We need to adjust pointer and length to be prepared for next
+ key part. As well as check if this was last key part.
+ */
+ goto prepare_for_next_key_part;
}
}
@@ -1199,12 +1216,18 @@ bool ha_federated::create_where_from_key(String *to,
if (tmp.append(FEDERATED_CLOSEPAREN))
DBUG_RETURN(1);
+prepare_for_next_key_part:
if (store_length >= length)
break;
DBUG_PRINT("info", ("remainder %d", remainder));
DBUG_ASSERT(remainder > 1);
length-= store_length;
- ptr+= store_length;
+ /*
+ For nullable columns, null-byte is already skipped before, that is
+ ptr was incremented by 1. Since store_length still counts null-byte,
+ we need to subtract 1 from store_length.
+ */
+ ptr+= store_length - test(key_part->null_bit);
if (tmp.append(FEDERATED_AND))
DBUG_RETURN(1);
@@ -1319,7 +1342,6 @@ static int free_share(FEDERATED_SHARE *share)
{
hash_delete(&federated_open_tables, (byte*) share);
my_free((gptr) share->scheme, MYF(MY_ALLOW_ZERO_PTR));
- my_free((gptr) share->socket, MYF(MY_ALLOW_ZERO_PTR));
thr_lock_delete(&share->lock);
VOID(pthread_mutex_destroy(&share->mutex));
my_free((gptr) share, MYF(0));
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 382fbc18667..5ed791d0f68 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -1954,6 +1954,7 @@ my_bool ha_myisam::register_query_cache_table(THD *thd, char *table_name,
*engine_callback,
ulonglong *engine_data)
{
+ DBUG_ENTER("ha_myisam::register_query_cache_table");
/*
No call back function is needed to determine if a cached statement
is valid or not.
@@ -1965,39 +1966,48 @@ my_bool ha_myisam::register_query_cache_table(THD *thd, char *table_name,
*/
*engine_data= 0;
- /*
- If a concurrent INSERT has happened just before the currently processed
- SELECT statement, the total size of the table is unknown.
+ if (file->s->concurrent_insert)
+ {
+ /*
+ If a concurrent INSERT has happened just before the currently
+ processed SELECT statement, the total size of the table is
+ unknown.
- To determine if the table size is known, the current thread's snap shot of
- the table size with the actual table size are compared.
+ To determine if the table size is known, the current thread's snap
+ shot of the table size with the actual table size are compared.
- If the table size is unknown the SELECT statement can't be cached.
- */
- ulonglong actual_data_file_length;
- ulonglong current_data_file_length;
+ If the table size is unknown the SELECT statement can't be cached.
- /*
- POSIX visibility rules specify that "2. Whatever memory values a
- thread can see when it unlocks a mutex <...> can also be seen by any
- thread that later locks the same mutex". In this particular case,
- concurrent insert thread had modified the data_file_length in
- MYISAM_SHARE before it has unlocked (or even locked)
- structure_guard_mutex. So, here we're guaranteed to see at least that
- value after we've locked the same mutex. We can see a later value
- (modified by some other thread) though, but it's ok, as we only want
- to know if the variable was changed, the actual new value doesn't matter
- */
- actual_data_file_length= file->s->state.state.data_file_length;
- current_data_file_length= file->save_state.data_file_length;
+ When concurrent inserts are disabled at table open, mi_open()
+ does not assign a get_status() function. In this case the local
+ ("current") status is never updated. We would wrongly think that
+ we cannot cache the statement.
+ */
+ ulonglong actual_data_file_length;
+ ulonglong current_data_file_length;
- if (current_data_file_length != actual_data_file_length)
- {
- /* Don't cache current statement. */
- return FALSE;
+ /*
+ POSIX visibility rules specify that "2. Whatever memory values a
+ thread can see when it unlocks a mutex <...> can also be seen by any
+ thread that later locks the same mutex". In this particular case,
+ concurrent insert thread had modified the data_file_length in
+ MYISAM_SHARE before it has unlocked (or even locked)
+ structure_guard_mutex. So, here we're guaranteed to see at least that
+ value after we've locked the same mutex. We can see a later value
+ (modified by some other thread) though, but it's ok, as we only want
+ to know if the variable was changed, the actual new value doesn't matter
+ */
+ actual_data_file_length= file->s->state.state.data_file_length;
+ current_data_file_length= file->save_state.data_file_length;
+
+ if (current_data_file_length != actual_data_file_length)
+ {
+ /* Don't cache current statement. */
+ DBUG_RETURN(FALSE);
+ }
}
/* It is ok to try to cache current statement. */
- return TRUE;
+ DBUG_RETURN(TRUE);
}
#endif
diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
index 02d0eaf2af3..f15a37efdc5 100644
--- a/sql/ha_myisammrg.cc
+++ b/sql/ha_myisammrg.cc
@@ -602,6 +602,12 @@ void ha_myisammrg::append_create_info(String *packet)
packet->append(STRING_WITH_LEN(" INSERT_METHOD="));
packet->append(get_type(&merge_insert_method,file->merge_insert_method-1));
}
+ /*
+ There is no sence adding UNION clause in case there is no underlying
+ tables specified.
+ */
+ if (file->open_tables == file->end_table)
+ return;
packet->append(STRING_WITH_LEN(" UNION=("));
MYRG_TABLE *open_table,*first;
diff --git a/sql/ha_ndbcluster_cond.cc b/sql/ha_ndbcluster_cond.cc
index c7b185a92f0..f5b41959b40 100644
--- a/sql/ha_ndbcluster_cond.cc
+++ b/sql/ha_ndbcluster_cond.cc
@@ -117,7 +117,8 @@ void ndb_serialize_cond(const Item *item, void *arg)
if (item->type() == Item::FUNC_ITEM)
{
Item_func *func_item= (Item_func *) item;
- if (func_item->functype() == Item_func::UNKNOWN_FUNC &&
+ if ((func_item->functype() == Item_func::UNKNOWN_FUNC ||
+ func_item->functype() == Item_func::NEG_FUNC) &&
func_item->const_item())
{
// Skip any arguments since we will evaluate function instead
@@ -369,8 +370,9 @@ void ndb_serialize_cond(const Item *item, void *arg)
{
Item_func *func_item= (Item_func *) item;
// Check that we expect a function or functional expression here
- if (context->expecting(Item::FUNC_ITEM) ||
- func_item->functype() == Item_func::UNKNOWN_FUNC)
+ if (context->expecting(Item::FUNC_ITEM) ||
+ func_item->functype() == Item_func::UNKNOWN_FUNC ||
+ func_item->functype() == Item_func::NEG_FUNC)
context->expect_nothing();
else
{
@@ -584,6 +586,7 @@ void ndb_serialize_cond(const Item *item, void *arg)
context->expect(Item::FUNC_ITEM);
break;
}
+ case Item_func::NEG_FUNC:
case Item_func::UNKNOWN_FUNC:
{
DBUG_PRINT("info", ("UNKNOWN_FUNC %s",
diff --git a/sql/ha_ndbcluster_cond.h b/sql/ha_ndbcluster_cond.h
index 6baf6945b58..6504df8d9d4 100644
--- a/sql/ha_ndbcluster_cond.h
+++ b/sql/ha_ndbcluster_cond.h
@@ -228,6 +228,7 @@ public:
case (Item_func::ISNOTNULL_FUNC): { return NDB_ISNOTNULL_FUNC; }
case (Item_func::LIKE_FUNC): { return NDB_LIKE_FUNC; }
case (Item_func::NOT_FUNC): { return NDB_NOT_FUNC; }
+ case (Item_func::NEG_FUNC): { return NDB_UNKNOWN_FUNC; }
case (Item_func::UNKNOWN_FUNC): { return NDB_UNKNOWN_FUNC; }
case (Item_func::COND_AND_FUNC): { return NDB_COND_AND_FUNC; }
case (Item_func::COND_OR_FUNC): { return NDB_COND_OR_FUNC; }
diff --git a/sql/handler.cc b/sql/handler.cc
index 27204ae725b..bfad10f986f 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1381,6 +1381,13 @@ int ha_delete_table(THD *thd, enum db_type table_type, const char *path,
handler *handler::clone(MEM_ROOT *mem_root)
{
handler *new_handler= get_new_handler(table, mem_root, table->s->db_type);
+ /*
+ Allocate handler->ref here because otherwise ha_open will allocate it
+ on this->table->mem_root and we will not be able to reclaim that memory
+ when the clone handler object is destroyed.
+ */
+ if (!(new_handler->ref= (byte*) alloc_root(mem_root, ALIGN_SIZE(ref_length)*2)))
+ return NULL;
if (new_handler && !new_handler->ha_open(table->s->path, table->db_stat,
HA_OPEN_IGNORE_IF_LOCKED))
return new_handler;
@@ -1420,8 +1427,9 @@ int handler::ha_open(const char *name, int mode, int test_if_locked)
(void) extra(HA_EXTRA_NO_READCHECK); // Not needed in SQL
DBUG_ASSERT(alloc_root_inited(&table->mem_root));
-
- if (!(ref= (byte*) alloc_root(&table->mem_root, ALIGN_SIZE(ref_length)*2)))
+ /* ref is already allocated for us if we're called from handler::clone() */
+ if (!ref && !(ref= (byte*) alloc_root(&table->mem_root,
+ ALIGN_SIZE(ref_length)*2)))
{
close();
error=HA_ERR_OUT_OF_MEM;
diff --git a/sql/item.cc b/sql/item.cc
index ffb18054750..c5b8d7a89ef 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1207,6 +1207,22 @@ bool Item_name_const::is_null()
return value_item->is_null();
}
+
+Item_name_const::Item_name_const(Item *name_arg, Item *val):
+ value_item(val), name_item(name_arg)
+{
+ if (!(valid_args= name_item->basic_const_item() &&
+ (value_item->basic_const_item() ||
+ ((value_item->type() == FUNC_ITEM) &&
+ (((Item_func *) value_item)->functype() ==
+ Item_func::NEG_FUNC) &&
+ (((Item_func *) value_item)->key_item()->type() !=
+ FUNC_ITEM)))))
+ my_error(ER_WRONG_ARGUMENTS, MYF(0), "NAME_CONST");
+ Item::maybe_null= TRUE;
+}
+
+
Item::Type Item_name_const::type() const
{
/*
@@ -1218,8 +1234,17 @@ Item::Type Item_name_const::type() const
if (item->type() == FIELD_ITEM)
((Item_field *) item)->...
we return NULL_ITEM in the case to avoid wrong casting.
+
+ valid_args guarantees value_item->basic_const_item(); if type is
+ FUNC_ITEM, then we have a fudged item_func_neg() on our hands
+ and return the underlying type.
*/
- return valid_args ? value_item->type() : NULL_ITEM;
+ return valid_args ?
+ (((value_item->type() == FUNC_ITEM) &&
+ (((Item_func *) value_item)->functype() == Item_func::NEG_FUNC)) ?
+ ((Item_func *) value_item)->key_item()->type() :
+ value_item->type()) :
+ NULL_ITEM;
}
@@ -1240,6 +1265,7 @@ bool Item_name_const::fix_fields(THD *thd, Item **ref)
return TRUE;
}
set_name(item_name->ptr(), (uint) item_name->length(), system_charset_info);
+ collation.set(value_item->collation.collation, DERIVATION_IMPLICIT);
max_length= value_item->max_length;
decimals= value_item->decimals;
fixed= 1;
@@ -2385,14 +2411,14 @@ default_set_param_func(Item_param *param,
Item_param::Item_param(unsigned pos_in_query_arg) :
- strict_type(FALSE),
state(NO_VALUE),
item_result_type(STRING_RESULT),
/* Don't pretend to be a literal unless value for this item is set. */
item_type(PARAM_ITEM),
param_type(MYSQL_TYPE_VARCHAR),
pos_in_query(pos_in_query_arg),
- set_param_func(default_set_param_func)
+ set_param_func(default_set_param_func),
+ limit_clause_param(FALSE)
{
name= (char*) "?";
/*
@@ -2581,8 +2607,13 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
{
item_result_type= entry->type;
unsigned_flag= entry->unsigned_flag;
- if (strict_type && required_result_type != item_result_type)
- DBUG_RETURN(1);
+ if (limit_clause_param)
+ {
+ my_bool unused;
+ set_int(entry->val_int(&unused), MY_INT64_NUM_DECIMAL_DIGITS);
+ item_type= Item::INT_ITEM;
+ DBUG_RETURN(!unsigned_flag && value.integer < 0 ? 1 : 0);
+ }
switch (item_result_type) {
case REAL_RESULT:
set_double(*(double*)entry->value);
@@ -3907,6 +3938,18 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
else if (!from_field)
goto error;
+ if (!outer_fixed && cached_table && cached_table->select_lex &&
+ context->select_lex &&
+ cached_table->select_lex != context->select_lex)
+ {
+ int ret;
+ if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
+ goto error;
+ else if (!ret)
+ return FALSE;
+ outer_fixed= 1;
+ }
+
/*
if it is not expression from merged VIEW we will set this field.
@@ -3922,18 +3965,6 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
if (from_field == view_ref_found)
return FALSE;
- if (!outer_fixed && cached_table && cached_table->select_lex &&
- context->select_lex &&
- cached_table->select_lex != context->select_lex)
- {
- int ret;
- if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
- goto error;
- else if (!ret)
- return FALSE;
- outer_fixed= 1;
- }
-
set_field(from_field);
if (thd->lex->in_sum_func &&
thd->lex->in_sum_func->nest_level ==
@@ -4087,6 +4118,30 @@ bool Item_field::subst_argument_checker(byte **arg)
}
+/**
+ Convert a numeric value to a zero-filled string
+
+ @param[in,out] item the item to operate on
+ @param field The field that this value is equated to
+
+ This function converts a numeric value to a string. In this conversion
+ the zero-fill flag of the field is taken into account.
+ This is required so the resulting string value can be used instead of
+ the field reference when propagating equalities.
+*/
+
+static void convert_zerofill_number_to_string(Item **item, Field_num *field)
+{
+ char buff[MAX_FIELD_WIDTH],*pos;
+ String tmp(buff,sizeof(buff), field->charset()), *res;
+
+ res= (*item)->val_str(&tmp);
+ field->prepend_zeros(res);
+ pos= (char *) sql_strmake (res->ptr(), res->length());
+ *item= new Item_string(pos, res->length(), field->charset());
+}
+
+
/*
Set a pointer to the multiple equality the field reference belongs to
(if any)
@@ -4135,6 +4190,13 @@ Item *Item_field::equal_fields_propagator(byte *arg)
if (!item ||
(cmp_context != (Item_result)-1 && item->cmp_context != cmp_context))
item= this;
+ else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type()))
+ {
+ if (item && cmp_context != INT_RESULT)
+ convert_zerofill_number_to_string(&item, (Field_num *)field);
+ else
+ item= this;
+ }
return item;
}
@@ -4306,6 +4368,49 @@ String *Item::check_well_formed_result(String *str, bool send_error)
return str;
}
+/*
+ Compare two items using a given collation
+
+ SYNOPSIS
+ eq_by_collation()
+ item item to compare with
+ binary_cmp TRUE <-> compare as binaries
+ cs collation to use when comparing strings
+
+ DESCRIPTION
+ This method works exactly as Item::eq if the collation cs coincides with
+ the collation of the compared objects. Otherwise, first the collations that
+ differ from cs are replaced for cs and then the items are compared by
+ Item::eq. After the comparison the original collations of items are
+ restored.
+
+ RETURN
+ 1 compared items has been detected as equal
+ 0 otherwise
+*/
+
+bool Item::eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs)
+{
+ CHARSET_INFO *save_cs= 0;
+ CHARSET_INFO *save_item_cs= 0;
+ if (collation.collation != cs)
+ {
+ save_cs= collation.collation;
+ collation.collation= cs;
+ }
+ if (item->collation.collation != cs)
+ {
+ save_item_cs= item->collation.collation;
+ item->collation.collation= cs;
+ }
+ bool res= eq(item, binary_cmp);
+ if (save_cs)
+ collation.collation= save_cs;
+ if (save_item_cs)
+ item->collation.collation= save_item_cs;
+ return res;
+}
+
/*
Create a field to hold a string value from an item
diff --git a/sql/item.h b/sql/item.h
index 5f511557f47..a948c5a45f7 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -873,12 +873,30 @@ public:
virtual Field::geometry_type get_geometry_type() const
{ return Field::GEOM_GEOMETRY; };
String *check_well_formed_result(String *str, bool send_error= 0);
+ bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs);
};
class sp_head;
+class Item_basic_constant :public Item
+{
+public:
+ /* to prevent drop fixed flag (no need parent cleanup call) */
+ void cleanup()
+ {
+ /*
+ Restore the original field name as it might not have been allocated
+ in the statement memory. If the name is auto generated, it must be
+ done again between subsequent executions of a prepared statement.
+ */
+ if (orig_name)
+ name= orig_name;
+ }
+};
+
+
/*****************************************************************************
The class is a base class for representation of stored routine variables in
the Item-hierarchy. There are the following kinds of SP-vars:
@@ -1113,14 +1131,7 @@ class Item_name_const : public Item
Item *name_item;
bool valid_args;
public:
- Item_name_const(Item *name_arg, Item *val):
- value_item(val), name_item(name_arg)
- {
- if (!(valid_args= name_item->basic_const_item() &
- value_item->basic_const_item()))
- my_error(ER_WRONG_ARGUMENTS, MYF(0), "NAME_CONST");
- Item::maybe_null= TRUE;
- }
+ Item_name_const(Item *name_arg, Item *val);
bool fix_fields(THD *, Item **);
@@ -1161,7 +1172,7 @@ bool agg_item_charsets(DTCollation &c, const char *name,
Item **items, uint nitems, uint flags, int item_sep);
-class Item_num: public Item
+class Item_num: public Item_basic_constant
{
public:
Item_num() {} /* Remove gcc warning */
@@ -1352,7 +1363,7 @@ public:
friend class st_select_lex_unit;
};
-class Item_null :public Item
+class Item_null :public Item_basic_constant
{
public:
Item_null(char *name_par=0)
@@ -1374,8 +1385,6 @@ public:
bool send(Protocol *protocol, String *str);
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_NULL; }
- /* to prevent drop fixed flag (no need parent cleanup call) */
- void cleanup() {}
bool basic_const_item() const { return 1; }
Item *clone_item() { return new Item_null(name); }
bool is_null() { return 1; }
@@ -1402,8 +1411,6 @@ class Item_param :public Item
char cnvbuf[MAX_FIELD_WIDTH];
String cnvstr;
Item *cnvitem;
- bool strict_type;
- enum Item_result required_result_type;
public:
enum enum_item_param_state
@@ -1533,11 +1540,8 @@ public:
Otherwise return FALSE.
*/
bool eq(const Item *item, bool binary_cmp) const;
- void set_strict_type(enum Item_result result_type_arg)
- {
- strict_type= TRUE;
- required_result_type= result_type_arg;
- }
+ /** Item is a argument to a limit clause. */
+ bool limit_clause_param;
};
@@ -1567,8 +1571,6 @@ public:
int save_in_field(Field *field, bool no_conversions);
bool basic_const_item() const { return 1; }
Item *clone_item() { return new Item_int(name,value,max_length); }
- // to prevent drop fixed flag (no need parent cleanup call)
- void cleanup() {}
void print(String *str);
Item_num *neg() { value= -value; return this; }
uint decimal_precision() const
@@ -1621,8 +1623,6 @@ public:
{
return new Item_decimal(name, &decimal_value, decimals, max_length);
}
- // to prevent drop fixed flag (no need parent cleanup call)
- void cleanup() {}
void print(String *str);
Item_num *neg()
{
@@ -1673,8 +1673,6 @@ public:
String *val_str(String*);
my_decimal *val_decimal(my_decimal *);
bool basic_const_item() const { return 1; }
- // to prevent drop fixed flag (no need parent cleanup call)
- void cleanup() {}
Item *clone_item()
{ return new Item_float(name, value, decimals, max_length); }
Item_num *neg() { value= -value; return this; }
@@ -1696,7 +1694,7 @@ public:
};
-class Item_string :public Item
+class Item_string :public Item_basic_constant
{
public:
Item_string(const char *str,uint length,
@@ -1780,8 +1778,6 @@ public:
max_length= str_value.numchars() * collation.collation->mbmaxlen;
}
void print(String *str);
- // to prevent drop fixed flag (no need parent cleanup call)
- void cleanup() {}
};
@@ -1839,10 +1835,10 @@ public:
};
-class Item_hex_string: public Item
+class Item_hex_string: public Item_basic_constant
{
public:
- Item_hex_string(): Item() {}
+ Item_hex_string() {}
Item_hex_string(const char *str,uint str_length);
enum Type type() const { return VARBIN_ITEM; }
double val_real()
@@ -1858,8 +1854,6 @@ public:
enum Item_result result_type () const { return STRING_RESULT; }
enum Item_result cast_to_int_type() const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
- // to prevent drop fixed flag (no need parent cleanup call)
- void cleanup() {}
void print(String *str);
bool eq(const Item *item, bool binary_cmp) const;
virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
@@ -1989,6 +1983,35 @@ public:
Item_field *filed_for_view_update()
{ return (*ref)->filed_for_view_update(); }
virtual Ref_Type ref_type() { return REF; }
+
+ // Row emulation: forwarding of ROW-related calls to ref
+ uint cols()
+ {
+ return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
+ }
+ Item* element_index(uint i)
+ {
+ return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
+ }
+ Item** addr(uint i)
+ {
+ return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
+ }
+ bool check_cols(uint c)
+ {
+ return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
+ : Item::check_cols(c);
+ }
+ bool null_inside()
+ {
+ return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
+ }
+ void bring_value()
+ {
+ if (ref && result_type() == ROW_RESULT)
+ (*ref)->bring_value();
+ }
+
};
@@ -2449,7 +2472,7 @@ private:
};
-class Item_cache: public Item
+class Item_cache: public Item_basic_constant
{
protected:
Item *example;
@@ -2486,8 +2509,6 @@ public:
static Item_cache* get_cache(const Item *item);
table_map used_tables() const { return used_table_map; }
virtual void keep_array() {}
- // to prevent drop fixed flag (no need parent cleanup call)
- void cleanup() {}
void print(String *str);
bool eq_def(Field *field)
{
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 81c303415ee..16f3e51d615 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -2995,7 +2995,10 @@ void in_string::set(uint pos,Item *item)
{
if (res->uses_buffer_owned_by(str))
res->copy();
- *str= *res;
+ if (item->type() == Item::FUNC_ITEM)
+ str->copy(*res);
+ else
+ *str= *res;
}
if (!str->charset())
{
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 561613032bc..60a17c21521 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -361,13 +361,13 @@ Item *create_func_space(Item *a)
if (cs->mbminlen > 1)
{
uint dummy_errors;
- sp= new Item_string("",0,cs);
+ sp= new Item_string("", 0, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
if (sp)
sp->str_value.copy(" ", 1, &my_charset_latin1, cs, &dummy_errors);
}
else
{
- sp= new Item_string(" ",1,cs);
+ sp= new Item_string(" ", 1, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
}
return sp ? new Item_func_repeat(sp, a) : 0;
}
diff --git a/sql/item_func.cc b/sql/item_func.cc
index cfe6c9a63d0..87e547d1f89 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -3729,6 +3729,18 @@ longlong Item_func_sleep::val_int()
DBUG_ASSERT(fixed == 1);
double time= args[0]->val_real();
+ /*
+ On 64-bit OSX pthread_cond_timedwait() waits forever
+ if passed abstime time has already been exceeded by
+ the system time.
+ When given a very short timeout (< 10 mcs) just return
+ immediately.
+ We assume that the lines between this test and the call
+ to pthread_cond_timedwait() will be executed in less than 0.00001 sec.
+ */
+ if (time < 0.00001)
+ return 0;
+
set_timespec_nsec(abstime, (ulonglong)(time * ULL(1000000000)));
pthread_cond_init(&cond, NULL);
@@ -3985,7 +3997,7 @@ double user_var_entry::val_real(my_bool *null_value)
/* Get the value of a variable as an integer */
-longlong user_var_entry::val_int(my_bool *null_value)
+longlong user_var_entry::val_int(my_bool *null_value) const
{
if ((*null_value= (value == 0)))
return LL(0);
@@ -5515,6 +5527,8 @@ Item_func_sp::make_field(Send_field *tmp_field)
DBUG_ENTER("Item_func_sp::make_field");
DBUG_ASSERT(sp_result_field);
sp_result_field->make_field(tmp_field);
+ if (name)
+ tmp_field->col_name= name;
DBUG_VOID_RETURN;
}
diff --git a/sql/item_func.h b/sql/item_func.h
index 940586fce01..6dcf32cba07 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -54,7 +54,8 @@ public:
NOT_FUNC, NOT_ALL_FUNC,
NOW_FUNC, TRIG_COND_FUNC,
SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
- EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC };
+ EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC,
+ NEG_FUNC };
enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
OPTIMIZE_EQUAL };
enum Type type() const { return FUNC_ITEM; }
@@ -466,7 +467,7 @@ public:
longlong int_op();
my_decimal *decimal_op(my_decimal *);
const char *func_name() const { return "-"; }
- virtual bool basic_const_item() const { return args[0]->basic_const_item(); }
+ enum Functype functype() const { return NEG_FUNC; }
void fix_length_and_dec();
void fix_num_length_and_dec();
uint decimal_precision() const { return args[0]->decimal_precision(); }
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 3d261dc2c36..3d6d46ab3f4 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -597,6 +597,7 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref)
result_field=0;
null_value=1;
fix_length_and_dec();
+ item= item->real_item();
if (item->type() == Item::FIELD_ITEM)
hybrid_field_type= ((Item_field*) item)->field->type();
else
@@ -3459,6 +3460,6 @@ void Item_func_group_concat::print(String *str)
Item_func_group_concat::~Item_func_group_concat()
{
- if (unique_filter)
+ if (!original && unique_filter)
delete unique_filter;
}
diff --git a/sql/log.cc b/sql/log.cc
index 0376facb473..15e8679171c 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -2496,12 +2496,7 @@ static void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
void
*/
-#ifdef EMBEDDED_LIBRARY
-void vprint_msg_to_log(enum loglevel level __attribute__((unused)),
- const char *format __attribute__((unused)),
- va_list argsi __attribute__((unused)))
-{}
-#else /*!EMBEDDED_LIBRARY*/
+#ifndef EMBEDDED_LIBRARY
static void print_buffer_to_file(enum loglevel level, const char *buffer)
{
time_t skr;
diff --git a/sql/log_event.cc b/sql/log_event.cc
index a28e883473a..bc231182f46 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -373,6 +373,7 @@ Log_event::Log_event(const char* buf,
#endif
when = uint4korr(buf);
server_id = uint4korr(buf + SERVER_ID_OFFSET);
+ data_written= uint4korr(buf + EVENT_LEN_OFFSET);
if (description_event->binlog_version==1)
{
log_pos= 0;
@@ -405,7 +406,7 @@ Log_event::Log_event(const char* buf,
binlog, so which will cause problems if the user uses this value
in CHANGE MASTER).
*/
- log_pos+= uint4korr(buf + EVENT_LEN_OFFSET);
+ log_pos+= data_written; /* purecov: inspected */
}
DBUG_PRINT("info", ("log_pos: %lu", (ulong) log_pos));
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index e0708db7a36..4f27994c13c 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -73,6 +73,7 @@ extern const char *primary_key_name;
#include "mysql_com.h"
#include <violite.h>
#include "unireg.h"
+#define IS_NUM(t) ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR || (t) == FIELD_TYPE_NEWDECIMAL)
void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size);
gptr sql_alloc(unsigned size);
@@ -1274,6 +1275,7 @@ void my_dbopt_free(void);
extern time_t server_start_time, flush_status_time;
extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH],
mysql_real_data_home[], *opt_mysql_tmpdir, mysql_charsets_dir[],
+ mysql_unpacked_real_data_home[],
def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
extern MY_TMPDIR mysql_tmpdir_list;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index dd0232284ef..08f881ce8ed 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -475,14 +475,13 @@ char log_error_file[FN_REFLEN], glob_hostname[FN_REFLEN];
char mysql_real_data_home[FN_REFLEN],
language[FN_REFLEN], reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN],
*opt_init_file, *opt_tc_log_file,
+ mysql_unpacked_real_data_home[FN_REFLEN],
def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
-
+char *mysql_data_home= mysql_real_data_home;
const key_map key_map_empty(0);
key_map key_map_full(0); // Will be initialized later
const char *opt_date_time_formats[3];
-
-char *mysql_data_home= mysql_real_data_home;
char server_version[SERVER_VERSION_LENGTH];
char *mysqld_unix_port, *opt_mysql_tmpdir;
const char **errmesg; /* Error messages */
@@ -2399,10 +2398,6 @@ static void init_signals(void)
struct sigaction sa;
DBUG_ENTER("init_signals");
- if (test_flags & TEST_SIGINT)
- {
- my_sigset(thr_kill_signal, end_thread_signal);
- }
my_sigset(THR_SERVER_ALARM,print_signal_warning); // Should never be called!
if (!(test_flags & TEST_NO_STACKTRACE) || (test_flags & TEST_CORE_ON_SIGNAL))
@@ -2439,7 +2434,6 @@ static void init_signals(void)
(void) sigemptyset(&set);
my_sigset(SIGPIPE,SIG_IGN);
sigaddset(&set,SIGPIPE);
- sigaddset(&set,SIGINT);
#ifndef IGNORE_SIGHUP_SIGQUIT
sigaddset(&set,SIGQUIT);
sigaddset(&set,SIGHUP);
@@ -2461,9 +2455,12 @@ static void init_signals(void)
sigaddset(&set,THR_SERVER_ALARM);
if (test_flags & TEST_SIGINT)
{
+ my_sigset(thr_kill_signal, end_thread_signal);
// May be SIGINT
sigdelset(&set, thr_kill_signal);
}
+ else
+ sigaddset(&set,SIGINT);
sigprocmask(SIG_SETMASK,&set,NULL);
pthread_sigmask(SIG_SETMASK,&set,NULL);
DBUG_VOID_RETURN;
@@ -5936,7 +5933,7 @@ log and this option does nothing anymore.",
"Data file autoextend increment in megabytes",
(gptr*) &srv_auto_extend_increment,
(gptr*) &srv_auto_extend_increment,
- 0, GET_LONG, REQUIRED_ARG, 8L, 1L, 1000L, 0, 1L, 0},
+ 0, GET_ULONG, REQUIRED_ARG, 8L, 1L, 1000L, 0, 1L, 0},
{"innodb_buffer_pool_awe_mem_mb", OPT_INNODB_BUFFER_POOL_AWE_MEM_MB,
"If Windows AWE is used, the size of InnoDB buffer pool allocated from the AWE memory.",
(gptr*) &innobase_buffer_pool_awe_mem_mb, (gptr*) &innobase_buffer_pool_awe_mem_mb, 0,
@@ -5949,7 +5946,7 @@ log and this option does nothing anymore.",
{"innodb_commit_concurrency", OPT_INNODB_COMMIT_CONCURRENCY,
"Helps in performance tuning in heavily concurrent environments.",
(gptr*) &srv_commit_concurrency, (gptr*) &srv_commit_concurrency,
- 0, GET_LONG, REQUIRED_ARG, 0, 0, 1000, 0, 1, 0},
+ 0, GET_ULONG, REQUIRED_ARG, 0, 0, 1000, 0, 1, 0},
{"innodb_concurrency_tickets", OPT_INNODB_CONCURRENCY_TICKETS,
"Number of times a thread is allowed to enter InnoDB within the same \
SQL query after it has once got the ticket",
@@ -7750,6 +7747,9 @@ static void fix_paths(void)
pos[1]= 0;
}
convert_dirname(mysql_real_data_home,mysql_real_data_home,NullS);
+ (void) fn_format(buff, mysql_real_data_home, "", "",
+ (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
+ (void) unpack_dirname(mysql_unpacked_real_data_home, buff);
convert_dirname(language,language,NullS);
(void) my_load_path(mysql_home,mysql_home,""); // Resolve current dir
(void) my_load_path(mysql_real_data_home,mysql_real_data_home,mysql_home);
diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc
index 65bf755b3f0..b309a39f583 100644
--- a/sql/repl_failsafe.cc
+++ b/sql/repl_failsafe.cc
@@ -109,11 +109,14 @@ void change_rpl_status(RPL_STATUS from_status, RPL_STATUS to_status)
}
-#define get_object(p, obj) \
+#define get_object(p, obj, msg) \
{\
uint len = (uint)*p++; \
if (p + len > p_end || len >= sizeof(obj)) \
+ {\
+ errmsg= msg;\
goto err; \
+ }\
strmake(obj,(char*) p,len); \
p+= len; \
}\
@@ -158,6 +161,7 @@ int register_slave(THD* thd, uchar* packet, uint packet_length)
int res;
SLAVE_INFO *si;
uchar *p= packet, *p_end= packet + packet_length;
+ const char *errmsg= "Wrong parameters to function register_slave";
if (check_access(thd, REPL_SLAVE_ACL, any_db,0,0,0,0))
return 1;
@@ -166,9 +170,9 @@ int register_slave(THD* thd, uchar* packet, uint packet_length)
thd->server_id= si->server_id= uint4korr(p);
p+= 4;
- get_object(p,si->host);
- get_object(p,si->user);
- get_object(p,si->password);
+ get_object(p,si->host, "Failed to register slave: too long 'report-host'");
+ get_object(p,si->user, "Failed to register slave: too long 'report-user'");
+ get_object(p,si->password, "Failed to register slave; too long 'report-password'");
if (p+10 > p_end)
goto err;
si->port= uint2korr(p);
@@ -187,8 +191,7 @@ int register_slave(THD* thd, uchar* packet, uint packet_length)
err:
my_free((gptr) si, MYF(MY_WME));
- my_message(ER_UNKNOWN_ERROR, "Wrong parameters to function register_slave",
- MYF(0));
+ my_message(ER_UNKNOWN_ERROR, errmsg, MYF(0)); /* purecov: inspected */
err2:
return 1;
}
diff --git a/sql/slave.cc b/sql/slave.cc
index 4cb36b8f401..a50c74e4730 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -699,7 +699,20 @@ int terminate_slave_thread(THD* thd, pthread_mutex_t* term_lock,
while (*slave_running) // Should always be true
{
DBUG_PRINT("loop", ("killing slave thread"));
- KICK_SLAVE(thd);
+
+ pthread_mutex_lock(&thd->LOCK_delete);
+#ifndef DONT_USE_THR_ALARM
+ /*
+ Error codes from pthread_kill are:
+ EINVAL: invalid signal number (can't happen)
+ ESRCH: thread already killed (can happen, should be ignored)
+ */
+ IF_DBUG(int err= ) pthread_kill(thd->real_id, thr_client_alarm);
+ DBUG_ASSERT(err != EINVAL);
+#endif
+ thd->awake(THD::NOT_KILLED);
+ pthread_mutex_unlock(&thd->LOCK_delete);
+
/*
There is a small chance that slave thread might miss the first
alarm. To protect againts it, resend the signal until it reacts
@@ -2685,7 +2698,7 @@ int st_relay_log_info::wait_for_pos(THD* thd, String* log_name,
longlong timeout)
{
if (!inited)
- return -1;
+ return -2;
int event_count = 0;
ulong init_abort_pos_wait;
int error=0;
@@ -2896,6 +2909,9 @@ void set_slave_thread_default_charset(THD* thd, RELAY_LOG_INFO *rli)
static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type)
{
DBUG_ENTER("init_slave_thread");
+#if !defined(DBUG_OFF)
+ int simulate_error= 0;
+#endif
thd->system_thread = (thd_type == SLAVE_THD_SQL) ?
SYSTEM_THREAD_SLAVE_SQL : SYSTEM_THREAD_SLAVE_IO;
thd->security_ctx->skip_grants();
@@ -2915,10 +2931,17 @@ static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type)
thd->thread_id = thread_id++;
pthread_mutex_unlock(&LOCK_thread_count);
+ DBUG_EXECUTE_IF("simulate_io_slave_error_on_init",
+ simulate_error|= (1 << SLAVE_THD_IO););
+ DBUG_EXECUTE_IF("simulate_sql_slave_error_on_init",
+ simulate_error|= (1 << SLAVE_THD_SQL););
+#if !defined(DBUG_OFF)
+ if (init_thr_lock() || thd->store_globals() || simulate_error & (1<< thd_type))
+#else
if (init_thr_lock() || thd->store_globals())
+#endif
{
thd->cleanup();
- delete thd;
DBUG_RETURN(-1);
}
@@ -3115,6 +3138,11 @@ int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int expected_error)
Check if condition stated in UNTIL clause of START SLAVE is reached.
SYNOPSYS
st_relay_log_info::is_until_satisfied()
+ master_beg_pos position of the beginning of to be executed event
+ (not log_pos member of the event that points to the
+ beginning of the following event)
+
+
DESCRIPTION
Checks if UNTIL condition is reached. Uses caching result of last
comparison of current log file name and target log file name. So cached
@@ -3139,7 +3167,7 @@ int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int expected_error)
false - condition not met
*/
-bool st_relay_log_info::is_until_satisfied()
+bool st_relay_log_info::is_until_satisfied(my_off_t master_beg_pos)
{
const char *log_name;
ulonglong log_pos;
@@ -3149,7 +3177,7 @@ bool st_relay_log_info::is_until_satisfied()
if (until_condition == UNTIL_MASTER_POS)
{
log_name= group_master_log_name;
- log_pos= group_master_log_pos;
+ log_pos= master_beg_pos;
}
else
{ /* until_condition == UNTIL_RELAY_POS */
@@ -3228,28 +3256,6 @@ static int exec_relay_log_event(THD* thd, RELAY_LOG_INFO* rli)
wait for something for example inside of next_event().
*/
pthread_mutex_lock(&rli->data_lock);
- /*
- This tests if the position of the end of the last previous executed event
- hits the UNTIL barrier.
- We would prefer to test if the position of the start (or possibly) end of
- the to-be-read event hits the UNTIL barrier, this is different if there
- was an event ignored by the I/O thread just before (BUG#13861 to be
- fixed).
- */
- if (rli->until_condition!=RELAY_LOG_INFO::UNTIL_NONE &&
- rli->is_until_satisfied())
- {
- char buf[22];
- sql_print_information("Slave SQL thread stopped because it reached its"
- " UNTIL position %s", llstr(rli->until_pos(), buf));
- /*
- Setting abort_slave flag because we do not want additional message about
- error in query execution to be printed.
- */
- rli->abort_slave= 1;
- pthread_mutex_unlock(&rli->data_lock);
- return 1;
- }
Log_event * ev = next_event(rli);
@@ -3267,6 +3273,27 @@ static int exec_relay_log_event(THD* thd, RELAY_LOG_INFO* rli)
int exec_res;
/*
+ This tests if the position of the beginning of the current event
+ hits the UNTIL barrier.
+ */
+ if (rli->until_condition != RELAY_LOG_INFO::UNTIL_NONE &&
+ rli->is_until_satisfied((thd->options & OPTION_BEGIN || !ev->log_pos) ?
+ rli->group_master_log_pos :
+ ev->log_pos - ev->data_written))
+ {
+ char buf[22];
+ sql_print_information("Slave SQL thread stopped because it reached its"
+ " UNTIL position %s", llstr(rli->until_pos(), buf));
+ /*
+ Setting abort_slave flag because we do not want additional message about
+ error in query execution to be printed.
+ */
+ rli->abort_slave= 1;
+ pthread_mutex_unlock(&rli->data_lock);
+ delete ev;
+ return 1;
+ }
+ /*
Queries originating from this server must be skipped.
Low-level events (Format_desc, Rotate, Stop) from this server
must also be skipped. But for those we don't want to modify
@@ -3516,6 +3543,7 @@ slave_begin:
thd= new THD; // note that contructor of THD uses DBUG_ !
THD_CHECK_SENTRY(thd);
+ mi->io_thd = thd;
pthread_detach_this_thread();
thd->thread_stack= (char*) &thd; // remember where our stack is
@@ -3526,7 +3554,6 @@ slave_begin:
sql_print_error("Failed during slave I/O thread initialization");
goto err;
}
- mi->io_thd = thd;
pthread_mutex_lock(&LOCK_thread_count);
threads.append(thd);
pthread_mutex_unlock(&LOCK_thread_count);
@@ -3866,9 +3893,11 @@ slave_begin:
thd = new THD; // note that contructor of THD uses DBUG_ !
thd->thread_stack = (char*)&thd; // remember where our stack is
+ rli->sql_thd= thd;
/* Inform waiting threads that slave has started */
rli->slave_run_id++;
+ rli->slave_running = 1;
pthread_detach_this_thread();
if (init_slave_thread(thd, SLAVE_THD_SQL))
@@ -3883,7 +3912,6 @@ slave_begin:
goto err;
}
thd->init_for_queries();
- rli->sql_thd= thd;
thd->temporary_tables = rli->save_temporary_tables; // restore temp tables
pthread_mutex_lock(&LOCK_thread_count);
threads.append(thd);
@@ -3896,7 +3924,6 @@ slave_begin:
start receiving data so we realize we are not caught up and
Seconds_Behind_Master grows. No big deal.
*/
- rli->slave_running = 1;
rli->abort_slave = 0;
pthread_mutex_unlock(&rli->run_lock);
pthread_cond_broadcast(&rli->start_cond);
@@ -3977,6 +4004,22 @@ Slave SQL thread aborted. Can't execute init_slave query");
}
}
+ /*
+ First check until condition - probably there is nothing to execute. We
+ do not want to wait for next event in this case.
+ */
+ pthread_mutex_lock(&rli->data_lock);
+ if (rli->until_condition != RELAY_LOG_INFO::UNTIL_NONE &&
+ rli->is_until_satisfied(rli->group_master_log_pos))
+ {
+ char buf[22];
+ sql_print_information("Slave SQL thread stopped because it reached its"
+ " UNTIL position %s", llstr(rli->until_pos(), buf));
+ pthread_mutex_unlock(&rli->data_lock);
+ goto err;
+ }
+ pthread_mutex_unlock(&rli->data_lock);
+
/* Read queries from the IO/THREAD until this thread is killed */
while (!sql_slave_killed(thd,rli))
diff --git a/sql/slave.h b/sql/slave.h
index c61787cdf3b..da548e145d3 100644
--- a/sql/slave.h
+++ b/sql/slave.h
@@ -348,7 +348,7 @@ typedef struct st_relay_log_info
void close_temporary_tables();
/* Check if UNTIL condition is satisfied. See slave.cc for more. */
- bool is_until_satisfied();
+ bool is_until_satisfied(my_off_t master_beg_pos);
inline ulonglong until_pos()
{
return ((until_condition == UNTIL_MASTER_POS) ? group_master_log_pos :
diff --git a/sql/sp.cc b/sql/sp.cc
index f8b039626f9..7224d3c4f0e 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -261,6 +261,7 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
char buff[65];
String str(buff, sizeof(buff), &my_charset_bin);
ulong sql_mode;
+ bool saved_time_zone_used= thd->time_zone_used;
Open_tables_state open_tables_state_backup;
DBUG_ENTER("db_find_routine");
DBUG_PRINT("enter", ("type: %d name: %.*s",
@@ -370,6 +371,11 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
definer, created, modified);
done:
+ /*
+ Restore the time zone flag as the timezone usage in proc table
+ does not affect replication.
+ */
+ thd->time_zone_used= saved_time_zone_used;
if (table)
close_proc_table(thd, &open_tables_state_backup);
DBUG_RETURN(ret);
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 8fdd054eb39..e9504f423ad 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -668,7 +668,9 @@ static ulong get_sort(uint count,...)
{
for (; *str ; str++)
{
- if (*str == wild_many || *str == wild_one || *str == wild_prefix)
+ if (*str == wild_prefix && str[1])
+ str++;
+ else if (*str == wild_many || *str == wild_one)
{
wild_pos= (uint) (str - start) + 1;
break;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 2fbb2135cc6..89c16b7e54c 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -2852,8 +2852,12 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags)
}
if (tables->lock_type != TL_UNLOCK && ! thd->locked_tables)
- tables->table->reginfo.lock_type= tables->lock_type == TL_WRITE_DEFAULT ?
- thd->update_lock_default : tables->lock_type;
+ {
+ if (tables->lock_type == TL_WRITE_DEFAULT)
+ tables->table->reginfo.lock_type= thd->update_lock_default;
+ else if (tables->table->s->tmp_table == NO_TMP_TABLE)
+ tables->table->reginfo.lock_type= tables->lock_type;
+ }
tables->table->grant= tables->grant;
process_view_routines:
diff --git a/sql/sql_class.h b/sql/sql_class.h
index aaa7bcf8104..45539f774b5 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -2337,7 +2337,7 @@ class user_var_entry
bool unsigned_flag;
double val_real(my_bool *null_value);
- longlong val_int(my_bool *null_value);
+ longlong val_int(my_bool *null_value) const;
String *val_str(my_bool *null_value, String *str, uint decimals);
my_decimal *val_decimal(my_bool *null_value, my_decimal *result);
DTCollation collation;
diff --git a/sql/sql_cursor.cc b/sql/sql_cursor.cc
index 2e98da42be1..c2345f1f2cd 100644
--- a/sql/sql_cursor.cc
+++ b/sql/sql_cursor.cc
@@ -88,6 +88,7 @@ class Materialized_cursor: public Server_side_cursor
public:
Materialized_cursor(select_result *result, TABLE *table);
+ int fill_item_list(THD *thd, List<Item> &send_fields);
virtual bool is_open() const { return table != 0; }
virtual int open(JOIN *join __attribute__((unused)));
virtual void fetch(ulong num_rows);
@@ -109,6 +110,7 @@ class Select_materialize: public select_union
{
select_result *result; /* the result object of the caller (PS or SP) */
public:
+ Materialized_cursor *materialized_cursor;
Select_materialize(select_result *result_arg) :result(result_arg) {}
virtual bool send_fields(List<Item> &list, uint flags);
};
@@ -152,7 +154,7 @@ int mysql_open_cursor(THD *thd, uint flags, select_result *result,
if (! (sensitive_cursor= new (thd->mem_root) Sensitive_cursor(thd, result)))
{
- delete result;
+ delete result_materialize;
return 1;
}
@@ -174,13 +176,13 @@ int mysql_open_cursor(THD *thd, uint flags, select_result *result,
/*
Possible options here:
- a sensitive cursor is open. In this case rc is 0 and
- result_materialize->table is NULL, or
+ result_materialize->materialized_cursor is NULL, or
- a materialized cursor is open. In this case rc is 0 and
- result_materialize->table is not NULL
- - an error occured during materializaton.
- result_materialize->table is not NULL, but rc != 0
+ result_materialize->materialized is not NULL
+ - an error occurred during materialization.
+ result_materialize->materialized_cursor is not NULL, but rc != 0
- successful completion of mysql_execute_command without
- a cursor: rc is 0, result_materialize->table is NULL,
+ a cursor: rc is 0, result_materialize->materialized_cursor is NULL,
sensitive_cursor is not open.
This is possible if some command writes directly to the
network, bypassing select_result mechanism. An example of
@@ -191,7 +193,7 @@ int mysql_open_cursor(THD *thd, uint flags, select_result *result,
if (sensitive_cursor->is_open())
{
- DBUG_ASSERT(!result_materialize->table);
+ DBUG_ASSERT(!result_materialize->materialized_cursor);
/*
It's safer if we grab THD state after mysql_execute_command
is finished and not in Sensitive_cursor::open(), because
@@ -202,18 +204,10 @@ int mysql_open_cursor(THD *thd, uint flags, select_result *result,
*pcursor= sensitive_cursor;
goto end;
}
- else if (result_materialize->table)
+ else if (result_materialize->materialized_cursor)
{
- Materialized_cursor *materialized_cursor;
- TABLE *table= result_materialize->table;
- MEM_ROOT *mem_root= &table->mem_root;
-
- if (!(materialized_cursor= new (mem_root)
- Materialized_cursor(result, table)))
- {
- rc= 1;
- goto err_open;
- }
+ Materialized_cursor *materialized_cursor=
+ result_materialize->materialized_cursor;
if ((rc= materialized_cursor->open(0)))
{
@@ -229,8 +223,6 @@ int mysql_open_cursor(THD *thd, uint flags, select_result *result,
err_open:
DBUG_ASSERT(! (sensitive_cursor && sensitive_cursor->is_open()));
delete sensitive_cursor;
- if (result_materialize->table)
- free_tmp_table(thd, result_materialize->table);
end:
delete result_materialize;
return rc;
@@ -544,6 +536,51 @@ Materialized_cursor::Materialized_cursor(select_result *result_arg,
}
+/**
+ Preserve the original metadata that would be sent to the client.
+
+ @param thd Thread identifier.
+ @param send_fields List of fields that would be sent.
+*/
+
+int Materialized_cursor::fill_item_list(THD *thd, List<Item> &send_fields)
+{
+ Query_arena backup_arena;
+ int rc;
+ List_iterator_fast<Item> it_org(send_fields);
+ List_iterator_fast<Item> it_dst(item_list);
+ Item *item_org;
+ Item *item_dst;
+
+ thd->set_n_backup_active_arena(this, &backup_arena);
+
+ if ((rc= table->fill_item_list(&item_list)))
+ goto end;
+
+ DBUG_ASSERT(send_fields.elements == item_list.elements);
+
+ /*
+ Unless we preserve the original metadata, it will be lost,
+ since new fields describe columns of the temporary table.
+ Allocate a copy of the name for safety only. Currently
+ items with original names are always kept in memory,
+ but in case this changes a memory leak may be hard to notice.
+ */
+ while ((item_dst= it_dst++, item_org= it_org++))
+ {
+ Send_field send_field;
+ Item_ident *ident= static_cast<Item_ident *>(item_dst);
+ item_org->make_field(&send_field);
+
+ ident->db_name= thd->strdup(send_field.db_name);
+ ident->table_name= thd->strdup(send_field.table_name);
+ }
+end:
+ thd->restore_active_arena(this, &backup_arena);
+ /* Check for thd->is_error() in case of OOM */
+ return rc || thd->net.report_error;
+}
+
int Materialized_cursor::open(JOIN *join __attribute__((unused)))
{
THD *thd= fake_unit.thd;
@@ -552,8 +589,7 @@ int Materialized_cursor::open(JOIN *join __attribute__((unused)))
thd->set_n_backup_active_arena(this, &backup_arena);
/* Create a list of fields and start sequential scan */
- rc= (table->fill_item_list(&item_list) ||
- result->prepare(item_list, &fake_unit) ||
+ rc= (result->prepare(item_list, &fake_unit) ||
table->file->ha_rnd_init(TRUE));
thd->restore_active_arena(this, &backup_arena);
if (rc == 0)
@@ -664,6 +700,24 @@ bool Select_materialize::send_fields(List<Item> &list, uint flags)
if (create_result_table(unit->thd, unit->get_unit_column_types(),
FALSE, thd->options | TMP_TABLE_ALL_COLUMNS, ""))
return TRUE;
+
+ materialized_cursor= new (&table->mem_root)
+ Materialized_cursor(result, table);
+
+ if (! materialized_cursor)
+ {
+ free_tmp_table(table->in_use, table);
+ table= 0;
+ return TRUE;
+ }
+ if (materialized_cursor->fill_item_list(unit->thd, list))
+ {
+ delete materialized_cursor;
+ table= 0;
+ materialized_cursor= 0;
+ return TRUE;
+ }
+
return FALSE;
}
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 1b7d26b6a00..eeb77cef583 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -35,6 +35,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
READ_RECORD info;
bool using_limit=limit != HA_POS_ERROR;
bool transactional_table, safe_update, const_cond;
+ bool triggers_applicable;
ha_rows deleted;
uint usable_index= MAX_KEY;
SELECT_LEX *select_lex= &thd->lex->select_lex;
@@ -93,6 +94,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
select_lex->no_error= thd->lex->ignore;
+ /* NOTE: TRUNCATE must not invoke triggers. */
+
+ triggers_applicable= table->triggers &&
+ thd->lex->sql_command != SQLCOM_TRUNCATE;
+
/*
Test if the user wants to delete all rows and deletion doesn't have
any side-effects (because of triggers), so we can use optimized
@@ -102,8 +108,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
*/
if (!using_limit && const_cond && (!conds || conds->val_int()) &&
!(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE)) &&
- (thd->lex->sql_command == SQLCOM_TRUNCATE ||
- !(table->triggers && table->triggers->has_delete_triggers()))
+ !(triggers_applicable && table->triggers->has_delete_triggers())
)
{
deleted= table->file->records;
@@ -217,7 +222,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
init_ftfuncs(thd, select_lex, 1);
thd_proc_info(thd, "updating");
- if (table->triggers)
+ if (triggers_applicable)
{
table->triggers->mark_fields_used(thd, TRG_EVENT_DELETE);
if (table->triggers->has_triggers(TRG_EVENT_DELETE,
@@ -239,7 +244,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
if (!(select && select->skip_record())&& !thd->net.report_error )
{
- if (table->triggers &&
+ if (triggers_applicable &&
table->triggers->process_triggers(thd, TRG_EVENT_DELETE,
TRG_ACTION_BEFORE, FALSE))
{
@@ -250,7 +255,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
if (!(error=table->file->delete_row(table->record[0])))
{
deleted++;
- if (table->triggers &&
+ if (triggers_applicable &&
table->triggers->process_triggers(thd, TRG_EVENT_DELETE,
TRG_ACTION_AFTER, FALSE))
{
@@ -730,8 +735,6 @@ void multi_delete::send_error(uint errcode,const char *err)
}
thd->transaction.all.modified_non_trans_table= true;
}
- DBUG_ASSERT(!normal_tables || !deleted ||
- thd->transaction.stmt.modified_non_trans_table);
DBUG_VOID_RETURN;
}
@@ -839,8 +842,6 @@ bool multi_delete::send_eof()
{
query_cache_invalidate3(thd, delete_tables, 1);
}
- DBUG_ASSERT(!normal_tables || !deleted ||
- thd->transaction.stmt.modified_non_trans_table);
if ((local_error == 0) || thd->transaction.stmt.modified_non_trans_table)
{
if (mysql_bin_log.is_open())
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 67906b086d6..f2a539fd02b 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -3006,7 +3006,8 @@ bool select_insert::send_eof()
((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
info.touched : info.updated);
id= autoinc_value_of_first_inserted_row > 0 ?
- autoinc_value_of_first_inserted_row : thd->last_insert_id;
+ autoinc_value_of_first_inserted_row : thd->insert_id_used ?
+ thd->last_insert_id : 0;
::send_ok(thd, (ulong) thd->row_count_func, id, buff);
DBUG_RETURN(0);
}
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index f6534e305ef..dee3f2b5b22 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -76,6 +76,7 @@ static void remove_escape(char *name);
static bool append_file_to_dir(THD *thd, const char **filename_ptr,
const char *table_name);
static bool check_show_create_table_access(THD *thd, TABLE_LIST *table);
+static bool test_if_data_home_dir(const char *dir);
const char *any_db="*any*"; // Special symbol for check_access
@@ -3091,6 +3092,20 @@ mysql_execute_command(THD *thd)
"INDEX DIRECTORY option ignored");
create_info.data_file_name= create_info.index_file_name= NULL;
#else
+
+ if (test_if_data_home_dir(lex->create_info.data_file_name))
+ {
+ my_error(ER_WRONG_ARGUMENTS,MYF(0),"DATA DIRECORY");
+ res= -1;
+ break;
+ }
+ if (test_if_data_home_dir(lex->create_info.index_file_name))
+ {
+ my_error(ER_WRONG_ARGUMENTS,MYF(0),"INDEX DIRECORY");
+ res= -1;
+ break;
+ }
+
/* Fix names if symlinked tables */
if (append_file_to_dir(thd, &create_info.data_file_name,
create_table->table_name) ||
@@ -7936,3 +7951,48 @@ bool check_string_length(LEX_STRING *str, const char *err_msg,
return TRUE;
}
+
+
+/*
+ Check if path does not contain mysql data home directory
+
+ SYNOPSIS
+ test_if_data_home_dir()
+ dir directory
+ conv_home_dir converted data home directory
+ home_dir_len converted data home directory length
+
+ RETURN VALUES
+ 0 ok
+ 1 error
+*/
+
+static bool test_if_data_home_dir(const char *dir)
+{
+ char path[FN_REFLEN], conv_path[FN_REFLEN];
+ uint dir_len, home_dir_len= strlen(mysql_unpacked_real_data_home);
+ DBUG_ENTER("test_if_data_home_dir");
+
+ if (!dir)
+ DBUG_RETURN(0);
+
+ (void) fn_format(path, dir, "", "",
+ (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
+ dir_len= unpack_dirname(conv_path, dir);
+
+ if (home_dir_len <= dir_len)
+ {
+ if (lower_case_file_system)
+ {
+ if (!my_strnncoll(default_charset_info, (const uchar*) conv_path,
+ home_dir_len,
+ (const uchar*) mysql_unpacked_real_data_home,
+ home_dir_len))
+ DBUG_RETURN(1);
+ }
+ else if (!memcmp(conv_path, mysql_unpacked_real_data_home, home_dir_len))
+ DBUG_RETURN(1);
+ }
+ DBUG_RETURN(0);
+}
+
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index d06b3386e5a..33eeff03d0a 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1512,6 +1512,44 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
}
+/**
+ @brief Validate and prepare for execution CREATE VIEW statement
+
+ @param stmt prepared statement
+
+ @note This function handles create view commands.
+
+ @retval FALSE Operation was a success.
+ @retval TRUE An error occured.
+*/
+
+static bool mysql_test_create_view(Prepared_statement *stmt)
+{
+ DBUG_ENTER("mysql_test_create_view");
+ THD *thd= stmt->thd;
+ LEX *lex= stmt->lex;
+ bool res= TRUE;
+ /* Skip first table, which is the view we are creating */
+ bool link_to_local;
+ TABLE_LIST *view= lex->unlink_first_table(&link_to_local);
+ TABLE_LIST *tables= lex->query_tables;
+
+ if (create_view_precheck(thd, tables, view, lex->create_view_mode))
+ goto err;
+
+ if (open_normal_and_derived_tables(thd, tables, 0))
+ goto err;
+
+ lex->view_prepare_mode= 1;
+ res= select_like_stmt_test(stmt, 0, 0);
+
+err:
+ /* put view back for PS rexecuting */
+ lex->link_first_table_back(view, link_to_local);
+ DBUG_RETURN(res);
+}
+
+
/*
Validate and prepare for execution a multi update statement.
@@ -1730,6 +1768,7 @@ static bool check_prepared_statement(Prepared_statement *stmt,
my_message(ER_UNSUPPORTED_PS, ER(ER_UNSUPPORTED_PS), MYF(0));
goto error;
}
+ res= mysql_test_create_view(stmt);
break;
case SQLCOM_DO:
res= mysql_test_do_fields(stmt, tables, lex->insert_list);
@@ -2480,7 +2519,7 @@ void mysql_stmt_close(THD *thd, char *packet)
DBUG_ENTER("mysql_stmt_close");
if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_close")))
- DBUG_VOID_RETURN;
+ goto out;
/*
The only way currently a statement can be deallocated when it's
@@ -2489,6 +2528,9 @@ void mysql_stmt_close(THD *thd, char *packet)
DBUG_ASSERT(! (stmt->flags & (uint) Prepared_statement::IS_IN_USE));
(void) stmt->deallocate();
+out:
+ /* clear errors, response packet is not expected */
+ thd->clear_error();
DBUG_VOID_RETURN;
}
@@ -2555,10 +2597,7 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length)
#ifndef EMBEDDED_LIBRARY
/* Minimal size of long data packet is 6 bytes */
if (packet_length <= MYSQL_LONG_DATA_HEADER)
- {
- my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_send_long_data");
- DBUG_VOID_RETURN;
- }
+ goto out;
#endif
stmt_id= uint4korr(packet);
@@ -2566,7 +2605,7 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length)
if (!(stmt=find_prepared_statement(thd, stmt_id,
"mysql_stmt_send_long_data")))
- DBUG_VOID_RETURN;
+ goto out;
param_number= uint2korr(packet);
packet+= 2;
@@ -2578,7 +2617,7 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length)
stmt->last_errno= ER_WRONG_ARGUMENTS;
sprintf(stmt->last_error, ER(ER_WRONG_ARGUMENTS),
"mysql_stmt_send_long_data");
- DBUG_VOID_RETURN;
+ goto out;
}
#endif
@@ -2594,6 +2633,10 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length)
stmt->last_errno= ER_OUTOFMEMORY;
sprintf(stmt->last_error, ER(ER_OUTOFMEMORY), 0);
}
+
+out:
+ /* clear errors, response packet is not expected */
+ thd->clear_error();
DBUG_VOID_RETURN;
}
diff --git a/sql/sql_repl.h b/sql/sql_repl.h
index 1fbc6eb30cf..cf400218cc2 100644
--- a/sql/sql_repl.h
+++ b/sql/sql_repl.h
@@ -35,12 +35,6 @@ extern I_List<i_string> binlog_do_db, binlog_ignore_db;
extern int max_binlog_dump_events;
extern my_bool opt_sporadic_binlog_dump_fail;
-#define KICK_SLAVE(thd) do { \
- pthread_mutex_lock(&(thd)->LOCK_delete); \
- (thd)->awake(THD::NOT_KILLED); \
- pthread_mutex_unlock(&(thd)->LOCK_delete); \
- } while(0)
-
int start_slave(THD* thd, MASTER_INFO* mi, bool net_report);
int stop_slave(THD* thd, MASTER_INFO* mi, bool net_report);
bool change_master(THD* thd, MASTER_INFO* mi);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 9ef1823978e..d6e1582544e 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -360,10 +360,10 @@ fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
}
}
new_ref= direct_ref ?
- new Item_direct_ref(ref->context, item_ref, ref->field_name,
- ref->table_name, ref->alias_name_used) :
- new Item_ref(ref->context, item_ref, ref->field_name,
- ref->table_name, ref->alias_name_used);
+ new Item_direct_ref(ref->context, item_ref, ref->table_name,
+ ref->field_name, ref->alias_name_used) :
+ new Item_ref(ref->context, item_ref, ref->table_name,
+ ref->field_name, ref->alias_name_used);
if (!new_ref)
return TRUE;
ref->outer_ref= new_ref;
@@ -2899,7 +2899,9 @@ merge_key_fields(KEY_FIELD *start,KEY_FIELD *new_fields,KEY_FIELD *end,
}
}
else if (old->eq_func && new_fields->eq_func &&
- old->val->eq(new_fields->val, old->field->binary()))
+ old->val->eq_by_collation(new_fields->val,
+ old->field->binary(),
+ old->field->charset()))
{
old->level= and_level;
@@ -10806,7 +10808,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
we found a row, as no new rows can be added to the result.
*/
if (not_used_in_distinct && found_records != join->found_records)
- return NESTED_LOOP_OK;
+ return NESTED_LOOP_NO_MORE_ROWS;
}
else
join_tab->read_record.file->unlock_row();
@@ -11183,19 +11185,42 @@ join_read_key(JOIN_TAB *tab)
}
+/*
+ ref access method implementation: "read_first" function
+
+ SYNOPSIS
+ join_read_always_key()
+ tab JOIN_TAB of the accessed table
+
+ DESCRIPTION
+ This is "read_fist" function for the "ref" access method.
+
+ The functon must leave the index initialized when it returns.
+ ref_or_null access implementation depends on that.
+
+ RETURN
+ 0 - Ok
+ -1 - Row not found
+ 1 - Error
+*/
+
static int
join_read_always_key(JOIN_TAB *tab)
{
int error;
TABLE *table= tab->table;
+ /* Initialize the index first */
+ if (!table->file->inited)
+ table->file->ha_index_init(tab->ref.key);
+
+ /* Perform "Late NULLs Filtering" (see internals manual for explanations) */
for (uint i= 0 ; i < tab->ref.key_parts ; i++)
{
if ((tab->ref.null_rejecting & 1 << i) && tab->ref.items[i]->is_null())
return -1;
- }
- if (!table->file->inited)
- table->file->ha_index_init(tab->ref.key);
+ }
+
if (cp_buffer_from_ref(tab->join->thd, &tab->ref))
return -1;
if ((error=table->file->index_read(table->record[0],
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index ab277f63049..e4965748e24 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -979,7 +979,7 @@ multi_update::multi_update(TABLE_LIST *table_list,
tmp_tables(0), updated(0), found(0), fields(field_list),
values(value_list), table_count(0), copy_field(0),
handle_duplicates(handle_duplicates_arg), do_update(1), trans_safe(1),
- transactional_tables(1), ignore(ignore_arg), error_handled(0)
+ transactional_tables(0), ignore(ignore_arg), error_handled(0)
{}
@@ -1482,7 +1482,7 @@ void multi_update::send_error(uint errcode,const char *err)
if (trans_safe)
{
- DBUG_ASSERT(transactional_tables);
+ DBUG_ASSERT(!updated || transactional_tables);
(void) ha_autocommit_or_rollback(thd, 1);
}
else
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 920dcab49e0..3056109e86b 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -182,10 +182,33 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view)
TABLE_LIST decoy;
memcpy (&decoy, view, sizeof (TABLE_LIST));
- if (!open_table(thd, &decoy, thd->mem_root, &not_used, OPEN_VIEW_NO_PARSE) &&
- !decoy.view)
+
+ /*
+ Let's reset decoy.view before calling open_table(): when we start
+ supporting ALTER VIEW in PS/SP that may save us from a crash.
+ */
+
+ decoy.view= NULL;
+
+ /*
+ open_table() will return NULL if 'decoy' is idenitifying a view *and*
+ there is no TABLE object for that view in the table cache. However,
+ decoy.view will be set to 1.
+
+ If there is a TABLE-instance for the oject identified by 'decoy',
+ open_table() will return that instance no matter if it is a table or
+ a view.
+
+ Thus, there is no need to check for the return value of open_table(),
+ since the return value itself does not mean anything.
+ */
+
+ open_table(thd, &decoy, thd->mem_root, &not_used, OPEN_VIEW_NO_PARSE);
+
+ if (!decoy.view)
{
- /* It's a table */
+ /* It's a table. */
+ my_error(ER_WRONG_OBJECT, MYF(0), view->db, view->table_name, "VIEW");
return TRUE;
}
@@ -204,104 +227,31 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view)
return FALSE;
}
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
/**
- @brief Creating/altering VIEW procedure
+ @brief CREATE VIEW privileges pre-check.
@param thd thread handler
+ @param tables tables used in the view
@param views views to create
@param mode VIEW_CREATE_NEW, VIEW_ALTER, VIEW_CREATE_OR_REPLACE
- @note This function handles both create and alter view commands.
-
@retval FALSE Operation was a success.
@retval TRUE An error occured.
*/
-bool mysql_create_view(THD *thd, TABLE_LIST *views,
- enum_view_create_mode mode)
+bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
+ enum_view_create_mode mode)
{
LEX *lex= thd->lex;
- bool link_to_local;
/* first table in list is target VIEW name => cut off it */
- TABLE_LIST *view= lex->unlink_first_table(&link_to_local);
- TABLE_LIST *tables= lex->query_tables;
TABLE_LIST *tbl;
SELECT_LEX *select_lex= &lex->select_lex;
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
SELECT_LEX *sl;
-#endif
- SELECT_LEX_UNIT *unit= &lex->unit;
- bool res= FALSE;
- DBUG_ENTER("mysql_create_view");
-
- /* This is ensured in the parser. */
- DBUG_ASSERT(!lex->proc_list.first && !lex->result &&
- !lex->param_list.elements && !lex->derived_tables);
-
- if (mode != VIEW_CREATE_NEW)
- {
- if (mode == VIEW_ALTER &&
- fill_defined_view_parts(thd, view))
- {
- res= TRUE;
- goto err;
- }
- sp_cache_invalidate();
- }
-
- if (!lex->definer)
- {
- /*
- DEFINER-clause is missing; we have to create default definer in
- persistent arena to be PS/SP friendly.
- If this is an ALTER VIEW then the current user should be set as
- the definer.
- */
- Query_arena original_arena;
- Query_arena *ps_arena = thd->activate_stmt_arena_if_needed(&original_arena);
-
- if (!(lex->definer= create_default_definer(thd)))
- res= TRUE;
+ bool res= TRUE;
+ DBUG_ENTER("create_view_precheck");
- if (ps_arena)
- thd->restore_active_arena(ps_arena, &original_arena);
-
- if (res)
- goto err;
- }
-
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- /*
- check definer of view:
- - same as current user
- - current user has SUPER_ACL
- */
- if (lex->definer &&
- (strcmp(lex->definer->user.str, thd->security_ctx->priv_user) != 0 ||
- my_strcasecmp(system_charset_info,
- lex->definer->host.str,
- thd->security_ctx->priv_host) != 0))
- {
- if (!(thd->security_ctx->master_access & SUPER_ACL))
- {
- my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER");
- res= TRUE;
- goto err;
- }
- else
- {
- if (!is_acl_user(lex->definer->host.str,
- lex->definer->user.str))
- {
- push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
- ER_NO_SUCH_USER,
- ER(ER_NO_SUCH_USER),
- lex->definer->user.str,
- lex->definer->host.str);
- }
- }
- }
/*
Privilege check for view creation:
- user has CREATE VIEW privilege on view table
@@ -323,10 +273,8 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
(check_access(thd, DROP_ACL, view->db, &view->grant.privilege,
0, 0, is_schema_db(view->db)) ||
grant_option && check_grant(thd, DROP_ACL, view, 0, 1, 0))))
- {
- res= TRUE;
goto err;
- }
+
for (sl= select_lex; sl; sl= sl->next_select())
{
for (tbl= sl->get_table_list(); tbl; tbl= tbl->next_local)
@@ -340,7 +288,6 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
"ANY", thd->security_ctx->priv_user,
thd->security_ctx->priv_host, tbl->table_name);
- res= TRUE;
goto err;
}
/*
@@ -376,10 +323,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
if (check_access(thd, SELECT_ACL, tbl->db,
&tbl->grant.privilege, 0, 0, test(tbl->schema_table)) ||
grant_option && check_grant(thd, SELECT_ACL, tbl, 0, 1, 0))
- {
- res= TRUE;
goto err;
- }
}
}
}
@@ -403,8 +347,126 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
}
}
}
+
+ res= FALSE;
+
+err:
+ DBUG_RETURN(res || thd->net.report_error);
+}
+
+#else
+
+bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
+ enum_view_create_mode mode)
+{
+ return FALSE;
+}
+
#endif
+
+/**
+ @brief Creating/altering VIEW procedure
+
+ @param thd thread handler
+ @param views views to create
+ @param mode VIEW_CREATE_NEW, VIEW_ALTER, VIEW_CREATE_OR_REPLACE
+
+ @note This function handles both create and alter view commands.
+
+ @retval FALSE Operation was a success.
+ @retval TRUE An error occured.
+*/
+
+bool mysql_create_view(THD *thd, TABLE_LIST *views,
+ enum_view_create_mode mode)
+{
+ LEX *lex= thd->lex;
+ bool link_to_local;
+ /* first table in list is target VIEW name => cut off it */
+ TABLE_LIST *view= lex->unlink_first_table(&link_to_local);
+ TABLE_LIST *tables= lex->query_tables;
+ TABLE_LIST *tbl;
+ SELECT_LEX *select_lex= &lex->select_lex;
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ SELECT_LEX *sl;
+#endif
+ SELECT_LEX_UNIT *unit= &lex->unit;
+ bool res= FALSE;
+ DBUG_ENTER("mysql_create_view");
+
+ /* This is ensured in the parser. */
+ DBUG_ASSERT(!lex->proc_list.first && !lex->result &&
+ !lex->param_list.elements && !lex->derived_tables);
+
+ if (mode != VIEW_CREATE_NEW)
+ {
+ if (mode == VIEW_ALTER &&
+ fill_defined_view_parts(thd, view))
+ {
+ res= TRUE;
+ goto err;
+ }
+ sp_cache_invalidate();
+ }
+
+ if (!lex->definer)
+ {
+ /*
+ DEFINER-clause is missing; we have to create default definer in
+ persistent arena to be PS/SP friendly.
+ If this is an ALTER VIEW then the current user should be set as
+ the definer.
+ */
+ Query_arena original_arena;
+ Query_arena *ps_arena = thd->activate_stmt_arena_if_needed(&original_arena);
+
+ if (!(lex->definer= create_default_definer(thd)))
+ res= TRUE;
+
+ if (ps_arena)
+ thd->restore_active_arena(ps_arena, &original_arena);
+
+ if (res)
+ goto err;
+ }
+
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ /*
+ check definer of view:
+ - same as current user
+ - current user has SUPER_ACL
+ */
+ if (lex->definer &&
+ (strcmp(lex->definer->user.str, thd->security_ctx->priv_user) != 0 ||
+ my_strcasecmp(system_charset_info,
+ lex->definer->host.str,
+ thd->security_ctx->priv_host) != 0))
+ {
+ if (!(thd->security_ctx->master_access & SUPER_ACL))
+ {
+ my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER");
+ res= TRUE;
+ goto err;
+ }
+ else
+ {
+ if (!is_acl_user(lex->definer->host.str,
+ lex->definer->user.str))
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+ ER_NO_SUCH_USER,
+ ER(ER_NO_SUCH_USER),
+ lex->definer->user.str,
+ lex->definer->host.str);
+ }
+ }
+ }
+#endif
+
+ if ((res= create_view_precheck(thd, tables, view, mode)))
+ goto err;
+
if (open_and_lock_tables(thd, tables))
{
res= TRUE;
diff --git a/sql/sql_view.h b/sql/sql_view.h
index ab0920e0bf2..1d45283352b 100644
--- a/sql/sql_view.h
+++ b/sql/sql_view.h
@@ -15,6 +15,9 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
+ enum_view_create_mode mode);
+
bool mysql_create_view(THD *thd, TABLE_LIST *view,
enum_view_create_mode mode);
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 3de2ce2d37d..6eae98e14db 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -458,10 +458,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%pure_parser /* We have threads */
/*
- Currently there are 245 shift/reduce conflicts.
+ Currently there are 240 shift/reduce conflicts.
We should not introduce new conflicts any more.
*/
-%expect 245
+%expect 240
%token END_OF_INPUT
@@ -1124,6 +1124,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%type <interval_time_st> interval_time_st
+%type <interval_time_st> interval_time_stamp
+
%type <db_type> storage_engines
%type <row_type> row_types
@@ -2945,7 +2947,7 @@ create_table_option:
my_error(ER_WARN_DEPRECATED_SYNTAX, MYF(0), "RAID_CHUNKSIZE", "PARTITION");
MYSQL_YYABORT;
}
- | UNION_SYM opt_equal '(' table_list ')'
+ | UNION_SYM opt_equal '(' opt_table_list ')'
{
/* Move the union list to the merge_list */
LEX *lex=Lex;
@@ -3058,15 +3060,15 @@ column_def:
;
key_def:
- key_type opt_ident key_alg '(' key_list ')'
+ key_type opt_ident key_alg '(' key_list ')' key_alg
{
LEX *lex=Lex;
- Key *key= new Key($1, $2, $3, 0, lex->col_list);
+ Key *key= new Key($1, $2, $7 ? $7 : $3, 0, lex->col_list);
lex->alter_info.key_list.push_back(key);
lex->col_list.empty(); /* Alloced by sql_alloc */
}
- | opt_constraint constraint_key_type opt_ident key_alg '(' key_list ')'
+ | opt_constraint constraint_key_type opt_ident key_alg '(' key_list ')' key_alg
{
LEX *lex=Lex;
const char *key_name= $3 ? $3:$1;
@@ -5103,9 +5105,9 @@ simple_expr:
{ $$= new Item_datetime_typecast($3); }
| TIMESTAMP '(' expr ',' expr ')'
{ $$= new Item_func_add_time($3, $5, 1, 0); }
- | TIMESTAMP_ADD '(' interval_time_st ',' expr ',' expr ')'
+ | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
{ $$= new Item_date_add_interval($7,$5,$3,0); }
- | TIMESTAMP_DIFF '(' interval_time_st ',' expr ',' expr ')'
+ | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
{ $$= new Item_func_timestamp_diff($5,$7,$3); }
| TRIM '(' expr ')'
{ $$= new Item_func_trim($3); }
@@ -6081,21 +6083,40 @@ interval:
| HOUR_MICROSECOND_SYM { $$=INTERVAL_HOUR_MICROSECOND; }
| HOUR_MINUTE_SYM { $$=INTERVAL_HOUR_MINUTE; }
| HOUR_SECOND_SYM { $$=INTERVAL_HOUR_SECOND; }
- | MICROSECOND_SYM { $$=INTERVAL_MICROSECOND; }
| MINUTE_MICROSECOND_SYM { $$=INTERVAL_MINUTE_MICROSECOND; }
| MINUTE_SECOND_SYM { $$=INTERVAL_MINUTE_SECOND; }
| SECOND_MICROSECOND_SYM { $$=INTERVAL_SECOND_MICROSECOND; }
| YEAR_MONTH_SYM { $$=INTERVAL_YEAR_MONTH; };
+interval_time_stamp:
+ interval_time_st {}
+ | FRAC_SECOND_SYM {
+ $$=INTERVAL_MICROSECOND;
+ /*
+ FRAC_SECOND was mistakenly implemented with
+ a wrong resolution. According to the ODBC
+ standard it should be nanoseconds, not
+ microseconds. Changing it to nanoseconds
+ in MySQL would mean making TIMESTAMPDIFF
+ and TIMESTAMPADD to return DECIMAL, since
+ the return value would be too big for BIGINT
+ Hence we just deprecate the incorrect
+ implementation without changing its
+ resolution.
+ */
+ WARN_DEPRECATED("FRAC_SECOND", "MICROSECOND"); // Will be removed in 6.2
+ }
+ ;
+
interval_time_st:
DAY_SYM { $$=INTERVAL_DAY; }
| WEEK_SYM { $$=INTERVAL_WEEK; }
| HOUR_SYM { $$=INTERVAL_HOUR; }
- | FRAC_SECOND_SYM { $$=INTERVAL_MICROSECOND; }
| MINUTE_SYM { $$=INTERVAL_MINUTE; }
| MONTH_SYM { $$=INTERVAL_MONTH; }
| QUARTER_SYM { $$=INTERVAL_QUARTER; }
| SECOND_SYM { $$=INTERVAL_SECOND; }
+ | MICROSECOND_SYM { $$=INTERVAL_MICROSECOND; }
| YEAR_SYM { $$=INTERVAL_YEAR; }
;
@@ -6333,7 +6354,7 @@ limit_options:
limit_option:
param_marker
{
- ((Item_param *) $1)->set_strict_type(INT_RESULT);
+ ((Item_param *) $1)->limit_clause_param= TRUE;
}
| ULONGLONG_NUM { $$= new Item_uint($1.str, $1.length); }
| LONG_NUM { $$= new Item_uint($1.str, $1.length); }