summaryrefslogtreecommitdiff
path: root/sql/sql_insert.cc
diff options
context:
space:
mode:
authorMarc Alff <marc.alff@sun.com>2009-09-17 03:20:11 -0600
committerMarc Alff <marc.alff@sun.com>2009-09-17 03:20:11 -0600
commit08ffe21317edee77503b13fac86e30c4b59ea17a (patch)
treed0d731222454addb05b3890fb2bc555da5af7d63 /sql/sql_insert.cc
parentf662d397c826b21851d7f43df34730f686e1b413 (diff)
parent4b4fcdd8f00247e4bfcce2229887d572a7aef7f2 (diff)
downloadmariadb-git-08ffe21317edee77503b13fac86e30c4b59ea17a.tar.gz
Merge mysql-next-mr --> mysql-trunk-signal
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r--sql/sql_insert.cc87
1 files changed, 48 insertions, 39 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index df5e3506f4b..7d2513bd419 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -2276,44 +2276,9 @@ void kill_delayed_threads(void)
}
-/*
- * Create a new delayed insert thread
-*/
-
-pthread_handler_t handle_delayed_insert(void *arg)
+static void handle_delayed_insert_impl(THD *thd, Delayed_insert *di)
{
- Delayed_insert *di=(Delayed_insert*) arg;
- THD *thd= &di->thd;
-
- pthread_detach_this_thread();
- /* Add thread to THD list so that's it's visible in 'show processlist' */
- pthread_mutex_lock(&LOCK_thread_count);
- thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
- thd->set_current_time();
- threads.append(thd);
- thd->killed=abort_loop ? THD::KILL_CONNECTION : THD::NOT_KILLED;
- pthread_mutex_unlock(&LOCK_thread_count);
-
- /*
- Wait until the client runs into pthread_cond_wait(),
- where we free it after the table is opened and di linked in the list.
- If we did not wait here, the client might detect the opened table
- before it is linked to the list. It would release LOCK_delayed_create
- and allow another thread to create another handler for the same table,
- since it does not find one in the list.
- */
- pthread_mutex_lock(&di->mutex);
-#if !defined( __WIN__) /* Win32 calls this in pthread_create */
- if (my_thread_init())
- {
- /* Can't use my_error since store_globals has not yet been called */
- thd->stmt_da->set_error_status(thd, ER_OUT_OF_RESOURCES,
- ER(ER_OUT_OF_RESOURCES), NULL);
- goto end;
- }
-#endif
-
- DBUG_ENTER("handle_delayed_insert");
+ DBUG_ENTER("handle_delayed_insert_impl");
thd->thread_stack= (char*) &thd;
if (init_thr_lock() || thd->store_globals())
{
@@ -2502,6 +2467,49 @@ err:
*/
ha_autocommit_or_rollback(thd, 1);
+ DBUG_VOID_RETURN;
+}
+
+
+/*
+ * Create a new delayed insert thread
+*/
+
+pthread_handler_t handle_delayed_insert(void *arg)
+{
+ Delayed_insert *di=(Delayed_insert*) arg;
+ THD *thd= &di->thd;
+
+ pthread_detach_this_thread();
+ /* Add thread to THD list so that's it's visible in 'show processlist' */
+ pthread_mutex_lock(&LOCK_thread_count);
+ thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
+ thd->set_current_time();
+ threads.append(thd);
+ thd->killed=abort_loop ? THD::KILL_CONNECTION : THD::NOT_KILLED;
+ pthread_mutex_unlock(&LOCK_thread_count);
+
+ /*
+ Wait until the client runs into pthread_cond_wait(),
+ where we free it after the table is opened and di linked in the list.
+ If we did not wait here, the client might detect the opened table
+ before it is linked to the list. It would release LOCK_delayed_create
+ and allow another thread to create another handler for the same table,
+ since it does not find one in the list.
+ */
+ pthread_mutex_lock(&di->mutex);
+#if !defined( __WIN__) /* Win32 calls this in pthread_create */
+ if (my_thread_init())
+ {
+ /* Can't use my_error since store_globals has not yet been called */
+ thd->stmt_da->set_error_status(thd, ER_OUT_OF_RESOURCES,
+ ER(ER_OUT_OF_RESOURCES), NULL);
+ goto end;
+ }
+#endif
+
+ handle_delayed_insert_impl(thd, di);
+
#ifndef __WIN__
end:
#endif
@@ -2525,7 +2533,8 @@ end:
my_thread_end();
pthread_exit(0);
- DBUG_RETURN(0);
+
+ return 0;
}
@@ -3600,7 +3609,7 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
DBUG_EXECUTE_IF("sleep_create_select_before_check_if_exists", my_sleep(6000000););
if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE) &&
- create_table->table->db_stat)
+ (create_table->table && create_table->table->db_stat))
{
/* Table already exists and was open at open_and_lock_tables() stage. */
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)