Commit 351b912e authored by Konstantin Osipov's avatar Konstantin Osipov

Backport of:

----------------------------------------------------------
revno: 2617.69.25
committer: Konstantin Osipov <kostja@sun.com>
branch nick: 5.4-42546
timestamp: Fri 2009-08-14 23:52:00 +0400
message:
  A cleanup in open_tables() and lock_tables():
  change return type of these functions to bool from int,
  to follow convention in the rest of the code.
(Part of WL#4284 review fixes).

sql/mysql_priv.h:
  Change return type of open_talbes() and lock_tables() from
  int to bool.
sql/sql_base.cc:
  Change return type of open_tables() and lock_tables() from int to bool.
sql/sql_handler.cc:
  Use bool now that open_tables() returns bool.
parent 546e16eb
...@@ -1474,19 +1474,20 @@ int setup_ftfuncs(SELECT_LEX* select); ...@@ -1474,19 +1474,20 @@ int setup_ftfuncs(SELECT_LEX* select);
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order); int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
void wait_for_condition(THD *thd, pthread_mutex_t *mutex, void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
pthread_cond_t *cond); pthread_cond_t *cond);
int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags, bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags,
Prelocking_strategy *prelocking_strategy); Prelocking_strategy *prelocking_strategy);
inline int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags) inline bool
open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags)
{ {
DML_prelocking_strategy prelocking_strategy; DML_prelocking_strategy prelocking_strategy;
return open_tables(thd, tables, counter, flags, &prelocking_strategy); return open_tables(thd, tables, counter, flags, &prelocking_strategy);
} }
/* open_and_lock_tables with optional derived handling */ /* open_and_lock_tables with optional derived handling */
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables,
bool derived, uint flags, bool derived, uint flags,
Prelocking_strategy *prelocking_strategy); Prelocking_strategy *prelocking_strategy);
inline int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, inline bool open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables,
bool derived, uint flags) bool derived, uint flags)
{ {
DML_prelocking_strategy prelocking_strategy; DML_prelocking_strategy prelocking_strategy;
...@@ -1495,12 +1496,12 @@ inline int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, ...@@ -1495,12 +1496,12 @@ inline int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables,
&prelocking_strategy); &prelocking_strategy);
} }
/* simple open_and_lock_tables without derived handling */ /* simple open_and_lock_tables without derived handling */
inline int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables) inline bool simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
{ {
return open_and_lock_tables_derived(thd, tables, FALSE, 0); return open_and_lock_tables_derived(thd, tables, FALSE, 0);
} }
/* open_and_lock_tables with derived handling */ /* open_and_lock_tables with derived handling */
inline int open_and_lock_tables(THD *thd, TABLE_LIST *tables) inline bool open_and_lock_tables(THD *thd, TABLE_LIST *tables)
{ {
return open_and_lock_tables_derived(thd, tables, TRUE, 0); return open_and_lock_tables_derived(thd, tables, TRUE, 0);
} }
...@@ -1508,9 +1509,9 @@ inline int open_and_lock_tables(THD *thd, TABLE_LIST *tables) ...@@ -1508,9 +1509,9 @@ inline int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l, TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
thr_lock_type lock_type, uint flags); thr_lock_type lock_type, uint flags);
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags); bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags, bool lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags,
bool *need_reopen); bool *need_reopen);
int decide_logging_format(THD *thd, TABLE_LIST *tables); bool decide_logging_format(THD *thd, TABLE_LIST *tables);
TABLE *open_temporary_table(THD *thd, const char *path, const char *db, TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
const char *table_name, bool link_in_list); const char *table_name, bool link_in_list);
bool rm_temporary_table(handlerton *base, char *path); bool rm_temporary_table(handlerton *base, char *path);
......
...@@ -3801,17 +3801,16 @@ open_routines(THD *thd, Query_tables_list *prelocking_ctx, ...@@ -3801,17 +3801,16 @@ open_routines(THD *thd, Query_tables_list *prelocking_ctx,
prelocking it won't do such precaching and will simply reuse table list prelocking it won't do such precaching and will simply reuse table list
which is already built. which is already built.
@retval 0 OK @retval FALSE Success.
@retval -1 Error. @retval TRUE Error, reported.
*/ */
int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, bool open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
Prelocking_strategy *prelocking_strategy) Prelocking_strategy *prelocking_strategy)
{ {
TABLE_LIST *tables= NULL; TABLE_LIST *tables= NULL;
Open_table_context ot_ctx(thd); Open_table_context ot_ctx(thd);
int result=0; bool error= FALSE;
bool error;
MEM_ROOT new_frm_mem; MEM_ROOT new_frm_mem;
/* Also used for indicating that prelocking is need */ /* Also used for indicating that prelocking is need */
TABLE_LIST **query_tables_last_own; TABLE_LIST **query_tables_last_own;
...@@ -3856,16 +3855,16 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, ...@@ -3856,16 +3855,16 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
DBUG_ASSERT(thd->lex->query_tables == *start); DBUG_ASSERT(thd->lex->query_tables == *start);
if (open_routines(thd, thd->lex, error= open_routines(thd, thd->lex,
(Sroutine_hash_entry *)thd->lex->sroutines_list.first, (Sroutine_hash_entry *)thd->lex->sroutines_list.first,
prelocking_strategy, &need_prelocking)) prelocking_strategy, &need_prelocking);
if (error)
{ {
/* /*
Serious error during reading stored routines from mysql.proc table. Serious error during reading stored routines from mysql.proc table.
Something's wrong with the table or its contents, and an error has Something's wrong with the table or its contents, and an error has
been emitted; we must abort. been emitted; we must abort.
*/ */
result= -1;
goto err; goto err;
} }
else if (need_prelocking) else if (need_prelocking)
...@@ -3924,7 +3923,7 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, ...@@ -3924,7 +3923,7 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
{ {
continue; continue;
} }
DBUG_RETURN(-1); DBUG_RETURN(TRUE);
} }
DBUG_PRINT("tcache", ("opening table: '%s'.'%s' item: 0x%lx", DBUG_PRINT("tcache", ("opening table: '%s'.'%s' item: 0x%lx",
tables->db, tables->table_name, (long) tables)); tables->db, tables->table_name, (long) tables));
...@@ -3979,10 +3978,9 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, ...@@ -3979,10 +3978,9 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
it may change in future. it may change in future.
*/ */
if (ot_ctx.recover_from_failed_open_table_attempt(thd, tables)) if (ot_ctx.recover_from_failed_open_table_attempt(thd, tables))
{
result= -1;
goto err; goto err;
}
error= FALSE;
goto restart; goto restart;
} }
...@@ -3990,10 +3988,9 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, ...@@ -3990,10 +3988,9 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
{ {
DBUG_PRINT("info", ("open_table: ignoring table '%s'.'%s'", DBUG_PRINT("info", ("open_table: ignoring table '%s'.'%s'",
tables->db, tables->alias)); tables->db, tables->alias));
error= FALSE;
continue; continue;
} }
result= -1; // Fatal error
goto err; goto err;
} }
...@@ -4071,10 +4068,7 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, ...@@ -4071,10 +4068,7 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
query_tables_last_own= save_query_tables_last; query_tables_last_own= save_query_tables_last;
if (error) if (error)
{
result= -1;
goto err; goto err;
}
/* /*
Process elements of the prelocking set which were added Process elements of the prelocking set which were added
...@@ -4084,12 +4078,10 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, ...@@ -4084,12 +4078,10 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
prelocking strategy prescribes so, add tables it uses to the table prelocking strategy prescribes so, add tables it uses to the table
list and routines it might invoke to the prelocking set. list and routines it might invoke to the prelocking set.
*/ */
if (open_routines(thd, thd->lex, *sroutines_next, prelocking_strategy, error= open_routines(thd, thd->lex, *sroutines_next, prelocking_strategy,
&not_used)) &not_used);
{ if (error)
result= -1;
goto err; goto err;
}
} }
if (tables->lock_type != TL_UNLOCK && ! thd->locked_tables_mode) if (tables->lock_type != TL_UNLOCK && ! thd->locked_tables_mode)
...@@ -4105,12 +4097,10 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, ...@@ -4105,12 +4097,10 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
tables->table->grant= tables->grant; tables->table->grant= tables->grant;
/* Check and update metadata version of a base table. */ /* Check and update metadata version of a base table. */
if (check_and_update_table_version(thd, tables, tables->table->s)) error= check_and_update_table_version(thd, tables, tables->table->s);
{
result= -1;
goto err;
}
if (error)
goto err;
/* /*
After opening a MERGE table add the children to the query list of After opening a MERGE table add the children to the query list of
tables, so that they are opened too. tables, so that they are opened too.
...@@ -4121,7 +4111,7 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, ...@@ -4121,7 +4111,7 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
/* Non-MERGE tables ignore this call. */ /* Non-MERGE tables ignore this call. */
if (tables->table->file->extra(HA_EXTRA_ADD_CHILDREN_LIST)) if (tables->table->file->extra(HA_EXTRA_ADD_CHILDREN_LIST))
{ {
result= -1; error= TRUE;
goto err; goto err;
} }
...@@ -4147,19 +4137,18 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, ...@@ -4147,19 +4137,18 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
query_tables_last_own= save_query_tables_last; query_tables_last_own= save_query_tables_last;
if (error) if (error)
{
result= -1;
goto err; goto err;
}
if (open_routines(thd, thd->lex, *sroutines_next, prelocking_strategy, error= open_routines(thd, thd->lex, *sroutines_next, prelocking_strategy,
&not_used)) &not_used);
if (error)
{ {
/* /*
Serious error during reading stored routines from mysql.proc table. Serious error during reading stored routines from mysql.proc table.
Something is wrong with the table or its contents, and an error has Something is wrong with the table or its contents, and an error has
been emitted; we must abort. been emitted; we must abort.
*/ */
result= -1;
goto err; goto err;
} }
} }
...@@ -4182,25 +4171,25 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags, ...@@ -4182,25 +4171,25 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
DBUG_ASSERT(tbl->pos_in_table_list == tables); DBUG_ASSERT(tbl->pos_in_table_list == tables);
if (tbl->file->extra(HA_EXTRA_ATTACH_CHILDREN)) if (tbl->file->extra(HA_EXTRA_ATTACH_CHILDREN))
{ {
result= -1; error= TRUE;
goto err; goto err;
} }
} }
} }
err: err:
thd_proc_info(thd, 0); thd_proc_info(thd, 0);
free_root(&new_frm_mem, MYF(0)); // Free pre-alloced block free_root(&new_frm_mem, MYF(0)); // Free pre-alloced block
if (query_tables_last_own) if (query_tables_last_own)
thd->lex->mark_as_requiring_prelocking(query_tables_last_own); thd->lex->mark_as_requiring_prelocking(query_tables_last_own);
if (result && tables) if (error && tables)
{ {
tables->table= NULL; tables->table= NULL;
} }
DBUG_PRINT("tcache", ("returning: %d", result)); DBUG_PRINT("open_tables", ("returning: %d", (int) error));
DBUG_RETURN(result); DBUG_RETURN(error);
} }
...@@ -4659,9 +4648,9 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type, ...@@ -4659,9 +4648,9 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type,
@retval TRUE Error @retval TRUE Error
*/ */
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables,
bool derived, uint flags, bool derived, uint flags,
Prelocking_strategy *prelocking_strategy) Prelocking_strategy *prelocking_strategy)
{ {
uint counter; uint counter;
bool need_reopen; bool need_reopen;
...@@ -4672,8 +4661,7 @@ int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, ...@@ -4672,8 +4661,7 @@ int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables,
for ( ; ; ) for ( ; ; )
{ {
if (open_tables(thd, &tables, &counter, flags, prelocking_strategy)) if (open_tables(thd, &tables, &counter, flags, prelocking_strategy))
DBUG_RETURN(-1); DBUG_RETURN(TRUE);
DBUG_EXECUTE_IF("sleep_open_and_lock_after_open", { DBUG_EXECUTE_IF("sleep_open_and_lock_after_open", {
const char *old_proc_info= thd->proc_info; const char *old_proc_info= thd->proc_info;
thd->proc_info= "DBUG sleep"; thd->proc_info= "DBUG sleep";
...@@ -4684,11 +4672,11 @@ int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, ...@@ -4684,11 +4672,11 @@ int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables,
&need_reopen)) &need_reopen))
break; break;
if (!need_reopen) if (!need_reopen)
DBUG_RETURN(-1); DBUG_RETURN(TRUE);
if (thd->in_multi_stmt_transaction() && has_locks) if (thd->in_multi_stmt_transaction() && has_locks)
{ {
my_error(ER_LOCK_DEADLOCK, MYF(0)); my_error(ER_LOCK_DEADLOCK, MYF(0));
DBUG_RETURN(-1); DBUG_RETURN(TRUE);
} }
close_tables_for_reopen(thd, &tables); close_tables_for_reopen(thd, &tables);
} }
...@@ -4697,7 +4685,7 @@ int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, ...@@ -4697,7 +4685,7 @@ int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables,
(thd->fill_derived_tables() && (thd->fill_derived_tables() &&
mysql_handle_derived(thd->lex, &mysql_derived_filling)))) mysql_handle_derived(thd->lex, &mysql_derived_filling))))
DBUG_RETURN(TRUE); /* purecov: inspected */ DBUG_RETURN(TRUE); /* purecov: inspected */
DBUG_RETURN(0); DBUG_RETURN(FALSE);
} }
...@@ -4791,7 +4779,7 @@ static void mark_real_tables_as_free_for_reuse(TABLE_LIST *table) ...@@ -4791,7 +4779,7 @@ static void mark_real_tables_as_free_for_reuse(TABLE_LIST *table)
@param tables Tables involved in the query @param tables Tables involved in the query
*/ */
int decide_logging_format(THD *thd, TABLE_LIST *tables) bool decide_logging_format(THD *thd, TABLE_LIST *tables)
{ {
/* /*
In SBR mode, we are only proceeding if we are binlogging this In SBR mode, we are only proceeding if we are binlogging this
...@@ -4889,7 +4877,7 @@ int decide_logging_format(THD *thd, TABLE_LIST *tables) ...@@ -4889,7 +4877,7 @@ int decide_logging_format(THD *thd, TABLE_LIST *tables)
DBUG_PRINT("info", ("error: %d", error)); DBUG_PRINT("info", ("error: %d", error));
if (error) if (error)
return -1; return TRUE;
/* /*
We switch to row-based format if we are in mixed mode and one of We switch to row-based format if we are in mixed mode and one of
...@@ -4910,7 +4898,7 @@ int decide_logging_format(THD *thd, TABLE_LIST *tables) ...@@ -4910,7 +4898,7 @@ int decide_logging_format(THD *thd, TABLE_LIST *tables)
} }
} }
return 0; return FALSE;
} }
/* /*
...@@ -4942,8 +4930,8 @@ int decide_logging_format(THD *thd, TABLE_LIST *tables) ...@@ -4942,8 +4930,8 @@ int decide_logging_format(THD *thd, TABLE_LIST *tables)
-1 Error -1 Error
*/ */
int lock_tables(THD *thd, TABLE_LIST *tables, uint count, bool lock_tables(THD *thd, TABLE_LIST *tables, uint count,
uint flags, bool *need_reopen) uint flags, bool *need_reopen)
{ {
TABLE_LIST *table; TABLE_LIST *table;
...@@ -4975,7 +4963,7 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count, ...@@ -4975,7 +4963,7 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count,
TABLE **start,**ptr; TABLE **start,**ptr;
if (!(ptr=start=(TABLE**) thd->alloc(sizeof(TABLE*)*count))) if (!(ptr=start=(TABLE**) thd->alloc(sizeof(TABLE*)*count)))
DBUG_RETURN(-1); DBUG_RETURN(TRUE);
for (table= tables; table; table= table->next_global) for (table= tables; table; table= table->next_global)
{ {
if (!table->placeholder()) if (!table->placeholder())
...@@ -5002,7 +4990,7 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count, ...@@ -5002,7 +4990,7 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count,
if (! (thd->lock= mysql_lock_tables(thd, start, (uint) (ptr - start), if (! (thd->lock= mysql_lock_tables(thd, start, (uint) (ptr - start),
flags, need_reopen))) flags, need_reopen)))
DBUG_RETURN(-1); DBUG_RETURN(TRUE);
if (thd->lex->requires_prelocking() && if (thd->lex->requires_prelocking() &&
thd->lex->sql_command != SQLCOM_LOCK_TABLES) thd->lex->sql_command != SQLCOM_LOCK_TABLES)
...@@ -5030,7 +5018,7 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count, ...@@ -5030,7 +5018,7 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count,
{ {
mysql_unlock_tables(thd, thd->lock); mysql_unlock_tables(thd, thd->lock);
thd->lock= 0; thd->lock= 0;
DBUG_RETURN(-1); DBUG_RETURN(TRUE);
} }
} }
} }
...@@ -5075,14 +5063,14 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count, ...@@ -5075,14 +5063,14 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count,
{ {
my_error(ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG, MYF(0), my_error(ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG, MYF(0),
table->table->s->table_name.str); table->table->s->table_name.str);
DBUG_RETURN(-1); DBUG_RETURN(TRUE);
} }
} }
} }
if (check_lock_and_start_stmt(thd, table->table, table->lock_type)) if (check_lock_and_start_stmt(thd, table->table, table->lock_type))
{ {
DBUG_RETURN(-1); DBUG_RETURN(TRUE);
} }
} }
/* /*
......
...@@ -193,7 +193,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) ...@@ -193,7 +193,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
TABLE_LIST *hash_tables = NULL; TABLE_LIST *hash_tables = NULL;
char *db, *name, *alias; char *db, *name, *alias;
uint dblen, namelen, aliaslen, counter; uint dblen, namelen, aliaslen, counter;
int error; bool error;
TABLE *backup_open_tables; TABLE *backup_open_tables;
MDL_context backup_mdl_context; MDL_context backup_mdl_context;
DBUG_ENTER("mysql_ha_open"); DBUG_ENTER("mysql_ha_open");
...@@ -321,8 +321,8 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) ...@@ -321,8 +321,8 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
can close a single table only. can close a single table only.
*/ */
close_thread_tables(thd); close_thread_tables(thd);
my_error(ER_ILLEGAL_HA, MYF(0), tables->alias); my_error(ER_ILLEGAL_HA, MYF(0), hash_tables->alias);
error= 1; error= TRUE;
} }
else else
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment