summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_isam.cc2
-rw-r--r--sql/ha_myisam.cc2
-rw-r--r--sql/ha_ndbcluster.cc2
-rw-r--r--sql/handler.cc2
-rw-r--r--sql/item.cc15
-rw-r--r--sql/item.h8
-rw-r--r--sql/item_cmpfunc.cc10
-rw-r--r--sql/item_subselect.cc3
-rw-r--r--sql/item_subselect.h2
-rw-r--r--sql/item_sum.cc2
-rw-r--r--sql/log_event.cc11
-rw-r--r--sql/mysql_priv.h3
-rw-r--r--sql/mysqld.cc10
-rw-r--r--sql/opt_range.cc22
-rw-r--r--sql/set_var.cc2
-rw-r--r--sql/sp_head.cc8
-rw-r--r--sql/sql_base.cc27
-rw-r--r--sql/sql_class.cc4
-rw-r--r--sql/sql_class.h4
-rw-r--r--sql/sql_lex.cc11
-rw-r--r--sql/sql_lex.h2
-rw-r--r--sql/sql_parse.cc26
-rw-r--r--sql/sql_prepare.cc11
-rw-r--r--sql/sql_select.cc52
-rw-r--r--sql/sql_table.cc2
-rw-r--r--sql/sql_union.cc5
-rw-r--r--sql/sql_view.cc8
-rw-r--r--sql/table.cc9
-rw-r--r--sql/tztime.cc49
-rw-r--r--sql/tztime.h2
-rw-r--r--sql/unireg.cc2
31 files changed, 187 insertions, 131 deletions
diff --git a/sql/ha_isam.cc b/sql/ha_isam.cc
index 85ab25a31d9..2fd75462329 100644
--- a/sql/ha_isam.cc
+++ b/sql/ha_isam.cc
@@ -330,7 +330,7 @@ int ha_isam::create(const char *name, register TABLE *form,
}
}
}
- DBUG_PRINT("loop",("found: %lx recpos: %d minpos: %d length: %d",
+ DBUG_PRINT("loop",("found: 0x%lx recpos: %d minpos: %d length: %d",
found,recpos,minpos,length));
if (recpos != minpos)
{ // Reserved space (Null bits?)
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 89288d6059f..4a6f2c556bf 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -1435,7 +1435,7 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
}
}
}
- DBUG_PRINT("loop",("found: %lx recpos: %d minpos: %d length: %d",
+ DBUG_PRINT("loop",("found: 0x%lx recpos: %d minpos: %d length: %d",
found,recpos,minpos,length));
if (recpos != minpos)
{ // Reserved space (Null bits?)
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 815aed13ce3..09cb0c0f02d 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -2297,6 +2297,8 @@ int ha_ndbcluster::extra(enum ha_extra_function operation)
break;
case HA_EXTRA_CHANGE_KEY_TO_DUP:
DBUG_PRINT("info", ("HA_EXTRA_CHANGE_KEY_TO_DUP"));
+ case HA_EXTRA_KEYREAD_PRESERVE_FIELDS:
+ DBUG_PRINT("info", ("HA_EXTRA_KEYREAD_PRESERVE_FIELDS"));
break;
}
diff --git a/sql/handler.cc b/sql/handler.cc
index 640c4f3710d..e7e1c807306 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -483,7 +483,7 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans)
if (trans == &thd->transaction.all && mysql_bin_log.is_open() &&
my_b_tell(&thd->transaction.trans_log))
{
- if (error= wait_if_global_read_lock(thd, 0, 0))
+ if ((error= wait_if_global_read_lock(thd, 0, 0)))
{
/*
Note that ROLLBACK [TO SAVEPOINT] does not have this test; it's
diff --git a/sql/item.cc b/sql/item.cc
index ecbe2d22fa4..5fa6b2400df 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -105,6 +105,15 @@ void Item::print_item_w_name(String *str)
}
+void Item::cleanup()
+{
+ DBUG_ENTER("Item::cleanup");
+ DBUG_PRINT("info", ("Item: 0x%lx", this));
+ DBUG_PRINT("info", ("Type: %d", (int)type()));
+ fixed=0;
+ DBUG_VOID_RETURN;
+}
+
Item_ident::Item_ident(const char *db_name_par,const char *table_name_par,
const char *field_name_par)
:orig_db_name(db_name_par), orig_table_name(table_name_par),
@@ -1397,9 +1406,9 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
}
if (!tmp)
return -1;
- else if (!refer)
+ if (!refer)
return 1;
- else if (tmp == not_found_field && refer == (Item **)not_found_item)
+ if (tmp == not_found_field && refer == (Item **)not_found_item)
{
if (upward_lookup)
{
@@ -1903,7 +1912,7 @@ bool Item::send(Protocol *protocol, String *buffer)
{
bool result;
enum_field_types type;
- LINT_INIT(result);
+ LINT_INIT(result); // Will be set if null_value == 0
switch ((type=field_type())) {
default:
diff --git a/sql/item.h b/sql/item.h
index 4d3f1736b4e..a9e4831b40b 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -143,13 +143,7 @@ public:
} /*lint -e1509 */
void set_name(const char *str,uint length, CHARSET_INFO *cs);
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
- virtual void cleanup()
- {
- DBUG_ENTER("Item::cleanup");
- DBUG_PRINT("info", ("Type: %d", (int)type()));
- fixed=0;
- DBUG_VOID_RETURN;
- }
+ virtual void cleanup();
virtual void make_field(Send_field *field);
virtual bool fix_fields(THD *, struct st_table_list *, Item **);
/*
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index f6daf0f5ed4..0356ea02ada 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -217,14 +217,10 @@ void Item_bool_func2::fix_length_and_dec()
in its memory: it will be reused on each execute.
*/
Item_arena *arena= thd->current_arena, backup;
- if (!arena->is_stmt_prepare())
- arena= 0;
- else
- thd->set_n_backup_item_arena(arena, &backup);
+ thd->set_n_backup_item_arena(arena, &backup);
conv= new Item_func_conv_charset(args[weak],
args[strong]->collation.collation);
- if (arena)
- thd->restore_backup_item_arena(arena, &backup);
+ thd->restore_backup_item_arena(arena, &backup);
conv->collation.set(args[weak]->collation.derivation);
conv->fix_fields(thd, 0, &conv);
}
@@ -1625,7 +1621,7 @@ cmp_item* cmp_item_row::make_same()
cmp_item_row::~cmp_item_row()
{
DBUG_ENTER("~cmp_item_row");
- DBUG_PRINT("enter",("this: %lx", this));
+ DBUG_PRINT("enter",("this: 0x%lx", this));
if (comparators)
{
for (uint i= 0; i < n; i++)
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 6d86d7d4b2d..23dbcf8af48 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -137,7 +137,6 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
DBUG_ASSERT(fixed == 0);
engine->set_thd((thd= thd_param));
- arena= thd->current_arena;
if (check_stack_overrun(thd, (gptr)&res))
return 1;
@@ -872,7 +871,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
ER_SELECT_REDUCED, warn_buff);
}
result= RES_REDUCE;
- goto end;
+ goto err;
}
}
}
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index e870feddedf..ed3dbfa9855 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -36,8 +36,6 @@ class Item_subselect :public Item_result_field
protected:
/* thread handler, will be assigned in fix_fields only */
THD *thd;
- /* Item_arena used or 0 */
- Item_arena *arena;
/* substitution instead of subselect in case of optimization */
Item *substitution;
/* unit of subquery */
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 13b6329daae..bfa0f86c744 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -64,7 +64,7 @@ Item_sum::Item_sum(THD *thd, Item_sum *item):
/*
- Save copy of arguments if we prepare prepared statement
+ Save copy of arguments if we are preparing a prepared statement
(arguments can be rewritten in get_tmp_table_item())
SYNOPSIS
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 97e041774f8..0c3b36c37b5 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -1266,6 +1266,8 @@ void Query_log_event::print(FILE* file, bool short_form,
{
// TODO: print the catalog ??
char buff[40],*end; // Enough for SET TIMESTAMP
+ bool different_db= 1;
+
if (!short_form)
{
print_header(file);
@@ -1273,9 +1275,7 @@ void Query_log_event::print(FILE* file, bool short_form,
(ulong) thread_id, (ulong) exec_time, error_code);
}
- bool different_db= 1;
-
- if (db && last_event_info->db)
+ if (db)
{
if ((different_db = memcmp(last_event_info->db, db, db_len + 1)))
memcpy(last_event_info->db, db, db_len + 1);
@@ -2300,7 +2300,7 @@ void Load_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_ev
}
bool different_db= 1;
- if (db && last_event_info->db)
+ if (db)
{
/*
If the database is different from the one of the previous statement, we
@@ -2845,7 +2845,8 @@ int Intvar_log_event::write_data(IO_CACHE* file)
*/
#ifdef MYSQL_CLIENT
-void Intvar_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_event_info)
+void Intvar_log_event::print(FILE* file, bool short_form,
+ LAST_EVENT_INFO* last_event_info)
{
char llbuff[22];
const char *msg;
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index c668e152df5..73ac000d953 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -1038,7 +1038,8 @@ void mysql_lock_abort_for_thread(THD *thd, TABLE *table);
MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b);
bool lock_global_read_lock(THD *thd);
void unlock_global_read_lock(THD *thd);
-bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh, bool is_not_commit);
+bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
+ bool is_not_commit);
void start_waiting_global_read_lock(THD *thd);
void make_global_read_lock_block_commit(THD *thd);
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 81651862255..24f6c4a3fa9 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -528,14 +528,14 @@ static void close_connections(void)
(void) pthread_mutex_lock(&LOCK_manager);
if (manager_thread_in_use)
{
- DBUG_PRINT("quit",("killing manager thread: %lx",manager_thread));
+ DBUG_PRINT("quit",("killing manager thread: 0x%lx",manager_thread));
(void) pthread_cond_signal(&COND_manager);
}
(void) pthread_mutex_unlock(&LOCK_manager);
/* kill connection thread */
#if !defined(__WIN__) && !defined(__EMX__) && !defined(OS2) && !defined(__NETWARE__)
- DBUG_PRINT("quit",("waiting for select thread: %lx",select_thread));
+ DBUG_PRINT("quit",("waiting for select thread: 0x%lx",select_thread));
(void) pthread_mutex_lock(&LOCK_thread_count);
while (select_thread_in_use)
@@ -2476,7 +2476,7 @@ static void init_ssl()
ssl_acceptor_fd= new_VioSSLAcceptorFd(opt_ssl_key, opt_ssl_cert,
opt_ssl_ca, opt_ssl_capath,
opt_ssl_cipher);
- DBUG_PRINT("info",("ssl_acceptor_fd: %lx", (long) ssl_acceptor_fd));
+ DBUG_PRINT("info",("ssl_acceptor_fd: 0x%lx", (long) ssl_acceptor_fd));
if (!ssl_acceptor_fd)
opt_use_ssl = 0;
}
@@ -4331,6 +4331,10 @@ Disable with --skip-isam.",
log and this option justs turns on --log-bin instead.",
(gptr*) &opt_update_logname, (gptr*) &opt_update_logname, 0, GET_STR,
OPT_ARG, 0, 0, 0, 0, 0, 0},
+ {"log-warnings", 'W', "Log some not critical warnings to the log file.",
+ (gptr*) &global_system_variables.log_warnings,
+ (gptr*) &max_system_variables.log_warnings, 0, GET_ULONG, OPT_ARG, 1, 0, 0,
+ 0, 0, 0},
{"low-priority-updates", OPT_LOW_PRIORITY_UPDATES,
"INSERT/DELETE/UPDATE has lower priority than selects.",
(gptr*) &global_system_variables.low_priority_updates,
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index e0e2b5c8045..e3a130f55f0 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -1633,8 +1633,9 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
if (!head->used_keys.is_clear_all())
{
int key_for_use= find_shortest_key(head, &head->used_keys);
- double key_read_time= get_index_only_read_time(&param, records,
- key_for_use);
+ double key_read_time= (get_index_only_read_time(&param, records,
+ key_for_use) +
+ (double) records / TIME_FOR_COMPARE);
DBUG_PRINT("info", ("'all'+'using index' scan will be using key %d, "
"read time %g", key_for_use, key_read_time));
if (key_read_time < read_time)
@@ -2111,6 +2112,12 @@ skip_to_ror_scan:
NOTES
It is assumed that we will read trough the whole key range and that all
key blocks are half full (normally things are much better).
+
+ TODO:
+ Move this to handler->read_time() by adding a flag 'index-only-read' to
+ this call. The reason for doing this is that the current function doesn't
+ handle the case when the row is stored in the b-tree (like in innodb
+ clustered index)
*/
inline double get_index_only_read_time(const PARAM* param, ha_rows records,
@@ -2125,6 +2132,7 @@ inline double get_index_only_read_time(const PARAM* param, ha_rows records,
return read_time;
}
+
typedef struct st_ror_scan_info
{
uint idx; /* # of used key in param->keys */
@@ -2992,7 +3000,8 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
!(pk_is_clustered && keynr == param->table->primary_key))
{
/* We can resolve this by only reading through this key. */
- found_read_time= get_index_only_read_time(param,found_records,keynr);
+ found_read_time= (get_index_only_read_time(param,found_records,keynr)+
+ (double) found_records / TIME_FOR_COMPARE);
}
else
{
@@ -3673,7 +3682,8 @@ tree_and(PARAM *param,SEL_TREE *tree1,SEL_TREE *tree2)
}
result_keys.set_bit(key1 - tree1->keys);
#ifdef EXTRA_DEBUG
- (*key1)->test_use_count(*key1);
+ if (*key1)
+ (*key1)->test_use_count(*key1);
#endif
}
}
@@ -4654,7 +4664,7 @@ void SEL_ARG::test_use_count(SEL_ARG *root)
ulong count=count_key_part_usage(root,pos->next_key_part);
if (count > pos->next_key_part->use_count)
{
- sql_print_error("Note: Use_count: Wrong count for key at %lx, %lu should be %lu",
+ sql_print_error("Note: Use_count: Wrong count for key at 0x%lx, %lu should be %lu",
pos,pos->next_key_part->use_count,count);
return;
}
@@ -4662,7 +4672,7 @@ void SEL_ARG::test_use_count(SEL_ARG *root)
}
}
if (e_count != elements)
- sql_print_error("Warning: Wrong use count: %u (should be %u) for tree at %lx",
+ sql_print_error("Warning: Wrong use count: %u (should be %u) for tree at 0x%lx",
e_count, elements, (gptr) this);
}
diff --git a/sql/set_var.cc b/sql/set_var.cc
index d92d5eb42b2..4b347f91869 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -2404,7 +2404,7 @@ bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
#endif
if (!(var->save_result.time_zone=
- my_tz_find(res, thd->lex->time_zone_tables_used)))
+ my_tz_find(res, thd->lex->time_zone_tables_used)))
{
my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
return 1;
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 16d13154263..d0ffe3fa051 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -262,6 +262,7 @@ sp_head::sp_head()
{
DBUG_ENTER("sp_head::sp_head");
+ state= INITIALIZED;
m_backpatch.empty();
m_lex.empty();
DBUG_VOID_RETURN;
@@ -498,8 +499,7 @@ sp_head::execute(THD *thd)
}
} while (ret == 0 && !thd->killed && !thd->query_error);
- if (thd->current_arena)
- cleanup_items(thd->current_arena->free_list);
+ cleanup_items(thd->current_arena->free_list);
thd->current_arena= old_arena;
done:
@@ -945,7 +945,9 @@ sp_head::restore_thd_mem_root(THD *thd)
{
DBUG_ENTER("sp_head::restore_thd_mem_root");
Item *flist= free_list; // The old list
- set_item_arena(thd); // Get new fre_list and mem_root
+ set_item_arena(thd); // Get new free_list and mem_root
+ state= INITIALIZED;
+
DBUG_PRINT("info", ("mem_root 0x%lx returned from thd mem root 0x%lx",
(ulong) &mem_root, (ulong) &thd->mem_root));
thd->free_list= flist; // Restore the old one
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 0aee91af0da..f07b93ec9f0 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1732,10 +1732,10 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
{
for (TABLE_LIST *cursor= (TABLE_LIST *) sl->table_list.first;
cursor;
- cursor=cursor->next)
+ cursor=cursor->next_local)
{
- if (cursor->table_list)
- cursor->table= cursor->table_list->table;
+ if (cursor->correspondent_table)
+ cursor->table= cursor->correspondent_table->table;
}
}
}
@@ -1948,15 +1948,8 @@ find_field_in_table(THD *thd, TABLE_LIST *table_list,
*ref= trans[i];
else
{
- Item_arena *arena= thd->current_arena, backup;
- if (!arena->is_stmt_prepare())
- arena= 0;
- else
- thd->set_n_backup_item_arena(arena, &backup);
- *ref= new Item_ref(trans + i, 0, table_list->view_name.str,
+ *ref= new Item_ref(trans + i, ref, table_list->view_name.str,
item_name);
- if (arena)
- thd->restore_backup_item_arena(arena, &backup);
/* as far as Item_ref have defined refernce it do not need tables */
if (*ref)
(*ref)->fix_fields(thd, 0, ref);
@@ -2440,14 +2433,14 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
if (!wild_num)
return 0;
Item_arena *arena= thd->current_arena, backup;
- if (!arena->is_stmt_prepare())
- arena= 0; // For easier test
/*
- If we are in preparing prepared statement phase then we have change
- temporary mem_root to statement mem root to save changes of SELECT list
+ Don't use arena if we are not in prepared statements or stored procedures
+ For PS/SP we have to use arena to remember the changes
*/
- if (arena)
+ if (arena->state == Item_arena::CONVENTIONAL_EXECUTION)
+ arena= 0; // For easier test later one
+ else
thd->set_n_backup_item_arena(arena, &backup);
List_iterator<Item> it(fields);
@@ -3057,7 +3050,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
err:
if (arena)
- thd->restore_backup_item_arena(arena, &backup);
+ thd->restore_backup_item_arena(arena, &backup);
DBUG_RETURN(1);
}
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 456b58ee95e..a807a4b75e5 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -1472,8 +1472,10 @@ void Statement::end_statement()
void Item_arena::set_n_backup_item_arena(Item_arena *set, Item_arena *backup)
{
+ DBUG_ENTER("Item_arena::set_n_backup_item_arena");
backup->set_item_arena(this);
set_item_arena(set);
+ DBUG_VOID_RETURN;
}
@@ -1482,7 +1484,7 @@ void Item_arena::restore_backup_item_arena(Item_arena *set, Item_arena *backup)
set->set_item_arena(this);
set_item_arena(backup);
// reset backup mem_root to avoid its freeing
- init_alloc_root(&backup->mem_root, 0, 0);
+ clear_alloc_root(&backup->mem_root);
}
void Item_arena::set_item_arena(Item_arena *set)
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 2b941b317f6..1612ab6fb17 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1031,6 +1031,10 @@ public:
return 0;
#endif
}
+ inline bool only_prepare()
+ {
+ return command == COM_PREPARE;
+ }
inline gptr trans_alloc(unsigned int size)
{
return alloc_root(&transaction.mem_root,size);
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index b0707955522..1f0b63b5df3 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -1014,7 +1014,7 @@ void st_select_lex::init_query()
subquery_in_having= explicit_limit= 0;
first_execution= 1;
first_cond_optimization= 1;
- parsing_place= SELECT_LEX_NODE::NO_MATTER;
+ parsing_place= NO_MATTER;
no_wrap_view_item= 0;
}
@@ -1659,11 +1659,6 @@ void st_select_lex_unit::set_limit(SELECT_LEX *values,
}
-st_lex::st_lex()
- :result(0)
-{}
-
-
/*
Unlink first table from global table list and first table from outer select
list (lex->select_lex)
@@ -1793,10 +1788,10 @@ void st_lex::link_first_table_back(TABLE_LIST *first,
void st_select_lex::fix_prepare_information(THD *thd, Item **conds)
{
- if (thd->current_arena && first_execution)
+ if (thd->current_arena->is_stmt_prepare() && first_execution)
{
- prep_where= where;
first_execution= 0;
+ prep_where= where;
}
}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index de0d5d90f16..d9eff46ea48 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -713,7 +713,7 @@ typedef struct st_lex
*/
bool empty_field_list_on_rset;
- st_lex()
+ st_lex() :result(0)
{
bzero((char *)&spfuns, sizeof(spfuns));
}
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 59a3e4b545b..a1180d29e99 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1958,6 +1958,20 @@ mysql_execute_command(THD *thd)
}
#endif /* !HAVE_REPLICATION */
+ if (lex->time_zone_tables_used)
+ {
+ TABLE_LIST *tmp;
+ if ((tmp= my_tz_get_table_list(thd, &lex->query_tables_last)) ==
+ &fake_time_zone_tables_list)
+ {
+ send_error(thd, 0);
+ DBUG_RETURN(-1);
+ }
+ lex->time_zone_tables_used= tmp;
+ if (!all_tables)
+ all_tables= tmp;
+ }
+
/*
When option readonly is set deny operations which change tables.
Except for the replication thread and the 'super' users.
@@ -2393,11 +2407,11 @@ mysql_execute_command(THD *thd)
if (lex->create_info.used_fields & HA_CREATE_USED_UNION)
{
TABLE_LIST *tab;
- for (tab= select_tables; tab; tab= tab->next)
+ for (tab= select_tables; tab; tab= tab->next_local)
{
- if (find_real_table_in_list((TABLE_LIST*) lex->create_info.
- merge_list.first,
- select_tables->db, tab->real_name))
+ if (find_table_in_local_list((TABLE_LIST*) lex->create_info.
+ merge_list.first,
+ select_tables->db, tab->real_name))
{
net_printf(thd, ER_UPDATE_TABLE_USED, tab->real_name);
goto create_error;
@@ -3767,7 +3781,7 @@ purposes internal to the MySQL server", MYF(0));
case SP_KEY_NOT_FOUND:
if (lex->drop_if_exists)
{
- push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST),
SP_COM_STRING(lex), lex->spname->m_name.str);
res= 0;
@@ -4699,7 +4713,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
new_field->sql_type= FIELD_TYPE_BLOB;
sprintf(warn_buff, ER(ER_AUTO_CONVERT), field_name, "CHAR",
(cs == &my_charset_bin) ? "BLOB" : "TEXT");
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_AUTO_CONVERT,
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_AUTO_CONVERT,
warn_buff);
/* fall through */
case FIELD_TYPE_BLOB:
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 5fccdd624de..c84d6457d4f 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -414,6 +414,7 @@ static void set_param_datetime(Item_param *param, uchar **pos, ulong len)
*pos+= length;
}
+
static void set_param_date(Item_param *param, uchar **pos, ulong len)
{
MYSQL_TIME tm;
@@ -1864,7 +1865,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
}
thd->set_statement(&thd->stmt_backup);
- thd->current_arena= 0;
+ thd->current_arena= thd;
DBUG_VOID_RETURN;
set_params_data_err:
@@ -1891,6 +1892,8 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name)
String expanded_query;
DBUG_ENTER("mysql_sql_stmt_execute");
+ DBUG_ASSERT(thd->free_list == NULL);
+
if (!(stmt= (Prepared_statement*)thd->stmt_map.find_by_name(stmt_name)))
{
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), stmt_name->length,
@@ -1906,9 +1909,8 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name)
DBUG_VOID_RETURN;
}
- DBUG_ASSERT(thd->free_list == NULL);
-
thd->set_n_backup_statement(stmt, &thd->stmt_backup);
+ thd->set_statement(stmt);
if (stmt->set_params_from_vars(stmt,
thd->stmt_backup.lex->prepared_stmt_params,
&expanded_query))
@@ -1916,9 +1918,7 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name)
my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE");
send_error(thd);
}
- thd->current_arena= stmt;
execute_stmt(thd, stmt, &expanded_query);
- thd->current_arena= 0;
DBUG_VOID_RETURN;
}
@@ -1941,7 +1941,6 @@ static void execute_stmt(THD *thd, Prepared_statement *stmt,
{
DBUG_ENTER("execute_stmt");
- thd->set_n_backup_statement(stmt, &thd->stmt_backup);
reset_stmt_for_execute(thd, stmt->lex);
if (expanded_query->length() &&
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index db3a0c90141..2d8ea72ed51 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -4910,13 +4910,13 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
JOIN_TAB *tab=join->join_tab+i;
JOIN_TAB *first_inner_tab= tab->first_inner;
table_map current_map= tab->table->map;
+ bool use_quick_range=0;
/*
Following force including random expression in last table condition.
It solve problem with select like SELECT * FROM t1 WHERE rand() > 0.5
*/
if (i == join->tables-1)
current_map|= OUTER_REF_TABLE_BIT | RAND_TABLE_BIT;
- bool use_quick_range=0;
used_tables|=current_map;
if (tab->type == JT_REF && tab->quick &&
@@ -4935,11 +4935,26 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
COND *tmp=make_cond_for_table(cond,used_tables,current_map);
if (!tmp && tab->quick)
{ // Outer join
- /*
- Hack to handle the case where we only refer to a table
- in the ON part of an OUTER JOIN.
- */
- tmp=new Item_int((longlong) 1,1); // Always true
+ if (tab->type != JT_ALL)
+ {
+ /*
+ Don't use the quick method
+ We come here in the case where we have 'key=constant' and
+ the test is removed by make_cond_for_table()
+ */
+ delete tab->quick;
+ tab->quick= 0;
+ }
+ else
+ {
+ /*
+ Hack to handle the case where we only refer to a table
+ in the ON part of an OUTER JOIN. In this case we want the code
+ below to check if we should use 'quick' instead.
+ */
+ tmp= new Item_int((longlong) 1,1); // Always true
+ }
+
}
if (tmp)
{
@@ -5989,6 +6004,7 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
NESTED_JOIN *nested_join;
TABLE_LIST *prev_table= 0;
List_iterator<TABLE_LIST> li(*join_list);
+ DBUG_ENTER("simplify_joins");
/*
Try to simplify join operations from join_list.
@@ -6122,36 +6138,34 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
li.replace(nested_join->join_list);
}
}
- return conds;
+ DBUG_RETURN(conds);
}
static COND *
optimize_cond(JOIN *join, COND *conds, Item::cond_result *cond_value)
{
+ THD *thd= join->thd;
SELECT_LEX *select= thd->lex->current_select;
DBUG_ENTER("optimize_cond");
- THD *thd= join->thd;
- SELECT_LEX *select= thd->lex->current_select;
if (select->first_cond_optimization)
{
- Item_arena *arena, backup;
+ /*
+ The following code will allocate the new items in a permanent
+ MEMROOT for prepared statements and stored procedures.
+ */
+
+ Item_arena *arena=thd->current_arena, backup;
select->first_cond_optimization= 0;
- arena= thd->current_arena;
- if (!arena->is_stmt_prepare())
- arena= 0;
- else
- thd->set_n_backup_item_arena(arena, &backup);
+ thd->set_n_backup_item_arena(arena, &backup);
/* Convert all outer joins to inner joins if possible */
conds= simplify_joins(join, join->join_list, conds, TRUE);
select->prep_where= conds ? conds->copy_andor_structure(thd) : 0;
- select->first_cond_optimization= 0;
- if (arena)
- thd->restore_backup_item_arena(arena, &backup);
+ thd->restore_backup_item_arena(arena, &backup);
}
if (!conds)
@@ -6161,7 +6175,7 @@ optimize_cond(JOIN *join, COND *conds, Item::cond_result *cond_value)
}
else
{
- DBUG_EXECUTE("where", print_where(conds, "after negation elimination"););
+ DBUG_EXECUTE("where", print_where(conds, "original"););
/* change field = field to field = const for each found field = const */
propagate_cond_constants((I_List<COND_CMP> *) 0,conds,conds);
/*
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 03c20be198e..1d4414426d0 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -2209,7 +2209,7 @@ table_exists:
char warn_buff[MYSQL_ERRMSG_SIZE];
my_snprintf(warn_buff, sizeof(warn_buff),
ER(ER_TABLE_EXISTS_ERROR), table_name);
- push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_TABLE_EXISTS_ERROR,warn_buff);
res= 0;
}
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 827d75a9848..d23e11d5443 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -290,13 +290,14 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
thd_arg->lex->current_select= lex_select_save;
if (!item_list.elements)
{
+ Field **field;
Item_arena *arena= thd->current_arena;
Item_arena backup;
if (!arena->is_stmt_prepare())
- arena= 0
+ arena= 0;
else
thd->set_n_backup_item_arena(arena, &backup);
- Field **field;
+
for (field= table->field; *field; field++)
{
Item_field *item= new Item_field(*field);
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 183b55ca12f..8cc342e99fe 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -271,9 +271,9 @@ int mysql_create_view(THD *thd,
}
#endif
- if (wait_if_global_read_lock(thd, 0))
+ if (wait_if_global_read_lock(thd, 0, 0))
{
- VOID(pthread_mutex_unlock(&LOCK_open));
+ res= -1;
goto err;
}
VOID(pthread_mutex_lock(&LOCK_open));
@@ -513,7 +513,9 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
will be TRUE as far as we make new table cache).
*/
Item_arena *arena= thd->current_arena, backup;
- if (arena)
+ if (!arena->is_stmt_prepare())
+ arena= 0;
+ else
thd->set_n_backup_item_arena(arena, &backup);
/* init timestamp */
diff --git a/sql/table.cc b/sql/table.cc
index 5d0c60718d3..d07d2ca085d 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -85,7 +85,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
SQL_CRYPT *crypted=0;
MEM_ROOT *old_root;
DBUG_ENTER("openfrm");
- DBUG_PRINT("enter",("name: '%s' form: %lx",name,outparam));
+ DBUG_PRINT("enter",("name: '%s' form: 0x%lx",name,outparam));
error=1;
disk_buff=NULL;
@@ -1548,9 +1548,7 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
/* view fields translation table */
if (!(transl=
- (Item**)(thd->current_arena ?
- thd->current_arena :
- thd)->alloc(select->item_list.elements * sizeof(Item*))))
+ (Item**)(thd->current_arena->alloc(select->item_list.elements * sizeof(Item*)))))
{
DBUG_RETURN(1);
}
@@ -1585,6 +1583,9 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
if (where)
{
Item_arena *arena= thd->current_arena, backup;
+ if (!arena->is_stmt_prepare())
+ arena= 0; // For easier test
+
if (!where->fixed && where->fix_fields(thd, ancestor, &where))
goto err;
diff --git a/sql/tztime.cc b/sql/tztime.cc
index af9af530fec..5b7162a6a0e 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -1406,20 +1406,30 @@ extern "C" byte* my_offset_tzs_get_key(Time_zone_offset *entry, uint *length,
for opening of time zone tables from preallocated array.
*/
-void
-tz_init_table_list(TABLE_LIST *tz_tabs)
+static void
+tz_init_table_list(TABLE_LIST *tz_tabs, TABLE_LIST ***global_next_ptr)
{
bzero(tz_tabs, sizeof(TABLE_LIST) * 4);
tz_tabs[0].alias= tz_tabs[0].real_name= (char*)"time_zone_name";
tz_tabs[1].alias= tz_tabs[1].real_name= (char*)"time_zone";
tz_tabs[2].alias= tz_tabs[2].real_name= (char*)"time_zone_transition_type";
tz_tabs[3].alias= tz_tabs[3].real_name= (char*)"time_zone_transition";
- tz_tabs[0].next= tz_tabs+1;
- tz_tabs[1].next= tz_tabs+2;
- tz_tabs[2].next= tz_tabs+3;
+ tz_tabs[0].next_global= tz_tabs[0].next_local= tz_tabs+1;
+ tz_tabs[1].next_global= tz_tabs[1].next_local= tz_tabs+2;
+ tz_tabs[2].next_global= tz_tabs[2].next_local= tz_tabs+3;
tz_tabs[0].lock_type= tz_tabs[1].lock_type= tz_tabs[2].lock_type=
tz_tabs[3].lock_type= TL_READ;
tz_tabs[0].db= tz_tabs[1].db= tz_tabs[2].db= tz_tabs[3].db= (char *)"mysql";
+
+ /* Link into global list */
+ tz_tabs[0].prev_global= *global_next_ptr;
+ tz_tabs[1].prev_global= &tz_tabs[0].next_global;
+ tz_tabs[2].prev_global= &tz_tabs[1].next_global;
+ tz_tabs[3].prev_global= &tz_tabs[2].next_global;
+
+ **global_next_ptr= tz_tabs;
+ /* Update last-global-pointer to point to pointer in last table */
+ *global_next_ptr= &tz_tabs[3].next_global;
}
@@ -1440,19 +1450,20 @@ tz_init_table_list(TABLE_LIST *tz_tabs)
*/
TABLE_LIST *
-my_tz_get_table_list(THD *thd)
+my_tz_get_table_list(THD *thd, TABLE_LIST ***global_next_ptr)
{
TABLE_LIST *tz_tabs;
+ DBUG_ENTER("my_tz_get_table_list");
if (!time_zone_tables_exist)
- return 0;
+ DBUG_RETURN(0);
if (!(tz_tabs= (TABLE_LIST *)thd->alloc(sizeof(TABLE_LIST) * 4)))
- return &fake_time_zone_tables_list;
+ DBUG_RETURN(&fake_time_zone_tables_list);
- tz_init_table_list(tz_tabs);
+ tz_init_table_list(tz_tabs, global_next_ptr);
- return tz_tabs;
+ DBUG_RETURN(tz_tabs);
}
@@ -1486,7 +1497,7 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap)
{
THD *thd;
TABLE_LIST *tables= 0;
- TABLE_LIST tables_buff[5];
+ TABLE_LIST tables_buff[5], **tmp_link, *first_table;
TABLE *table;
TZ_NAMES_ENTRY *tmp_tzname;
my_bool return_val= 1;
@@ -1553,9 +1564,10 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap)
(char*)"time_zone_leap_second";
tables_buff[0].lock_type= TL_READ;
tables_buff[0].db= thd->db;
- tables_buff[0].next= tables_buff + 1;
+ tables_buff[0].next_global= tables_buff[0].next_local= tables_buff + 1;
/* Fill TABLE_LIST for rest of the time zone describing tables */
- tz_init_table_list(tables_buff + 1);
+ tmp_link= &first_table;
+ tz_init_table_list(tables_buff + 1, &tmp_link);
if (open_tables(thd, tables_buff, &counter) ||
lock_tables(thd, tables_buff, counter))
@@ -1757,8 +1769,9 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables)
and it is specifically for this purpose).
*/
table= tz_tables->table;
- tz_tables= tz_tables->next;
- table->field[0]->store(tz_name->ptr(), tz_name->length(), &my_charset_latin1);
+ tz_tables= tz_tables->next_local;
+ table->field[0]->store(tz_name->ptr(), tz_name->length(),
+ &my_charset_latin1);
/*
It is OK to ignore ha_index_init()/ha_index_end() return values since
mysql.time_zone* tables are MyISAM and these operations always succeed
@@ -1769,7 +1782,9 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables)
if (table->file->index_read(table->record[0], (byte*)table->field[0]->ptr,
0, HA_READ_KEY_EXACT))
{
+#ifdef EXTRA_DEBUG
sql_print_error("Can't find description of time zone.");
+#endif
goto end;
}
@@ -1783,7 +1798,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables)
using the only index in this table).
*/
table= tz_tables->table;
- tz_tables= tz_tables->next;
+ tz_tables= tz_tables->next_local;
table->field[0]->store((longlong)tzid);
(void)table->file->ha_index_init(0);
@@ -1810,7 +1825,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables)
Right - using special index.
*/
table= tz_tables->table;
- tz_tables= tz_tables->next;
+ tz_tables= tz_tables->next_local;
table->field[0]->store((longlong)tzid);
(void)table->file->ha_index_init(0);
diff --git a/sql/tztime.h b/sql/tztime.h
index aabec260ec7..1325e921c67 100644
--- a/sql/tztime.h
+++ b/sql/tztime.h
@@ -59,7 +59,7 @@ public:
extern Time_zone * my_tz_UTC;
extern Time_zone * my_tz_SYSTEM;
-extern TABLE_LIST * my_tz_get_table_list(THD *thd);
+extern TABLE_LIST * my_tz_get_table_list(THD *thd, TABLE_LIST ***global_next_ptr);
extern Time_zone * my_tz_find(const String *name, TABLE_LIST *tz_tables);
extern my_bool my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap);
extern void my_tz_free();
diff --git a/sql/unireg.cc b/sql/unireg.cc
index c82fcc4abef..2a6abdb1cfd 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -321,7 +321,7 @@ static uint pack_keys(uchar *keybuff,uint key_count,KEY *keyinfo)
pos[6]=pos[7]=0; // For the future
pos+=8;
key_parts+=key->key_parts;
- DBUG_PRINT("loop",("flags: %d key_parts: %d at %lx",
+ DBUG_PRINT("loop",("flags: %d key_parts: %d at 0x%lx",
key->flags,key->key_parts,
key->key_part));
for (key_part=key->key_part,key_part_end=key_part+key->key_parts ;