summaryrefslogtreecommitdiff
path: root/sql/sql_insert.cc
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2015-12-13 00:10:40 +0100
committerSergei Golubchik <serg@mariadb.org>2015-12-13 00:10:40 +0100
commit162399515813a4e23c8735473f9d2dd622a6679b (patch)
tree39077fdabea60983c59899ce3d28e84c4d97c7e6 /sql/sql_insert.cc
parent5908d7ebb81bc2d52c67e519a4643372cb9f08bd (diff)
parent0ed474484c037a32bea32abaecd3ff770f40bd49 (diff)
downloadmariadb-git-162399515813a4e23c8735473f9d2dd622a6679b.tar.gz
Merge branch '5.5' into 10.0
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r--sql/sql_insert.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index aa748c6d72c..beede79bfcf 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -2002,7 +2002,7 @@ public:
*/
MDL_request grl_protection;
- Delayed_insert()
+ Delayed_insert(SELECT_LEX *current_select)
:locks_in_memory(0), table(0),tables_in_use(0),stacked_inserts(0),
status(0), handler_thread_initialized(FALSE), group_count(0)
{
@@ -2012,7 +2012,7 @@ public:
strmake_buf(thd.security_ctx->priv_user, thd.security_ctx->user);
thd.current_tablenr=0;
thd.set_command(COM_DELAYED_INSERT);
- thd.lex->current_select= 0; // for my_message_sql
+ thd.lex->current_select= current_select;
thd.lex->sql_command= SQLCOM_INSERT; // For innodb::store_lock()
/*
Prevent changes to global.lock_wait_timeout from affecting
@@ -2189,7 +2189,7 @@ bool delayed_get_table(THD *thd, MDL_request *grl_protection_request,
*/
if (! (di= find_handler(thd, table_list)))
{
- if (!(di= new Delayed_insert()))
+ if (!(di= new Delayed_insert(thd->lex->current_select)))
goto end_create;
thread_safe_increment32(&thread_count, &thread_count_lock);
@@ -2832,6 +2832,16 @@ pthread_handler_t handle_delayed_insert(void *arg)
if (di->open_and_lock_table())
goto err;
+ /*
+ INSERT DELAYED generally expects thd->lex->current_select to be NULL,
+ since this is not an attribute of the current thread. This can lead to
+ problems if the thread that spawned the current one disconnects.
+ current_select will then point to freed memory. But current_select is
+ required to resolve the partition function. So, after fulfilling that
+ requirement, we set the current_select to 0.
+ */
+ thd->lex->current_select= NULL;
+
/* Tell client that the thread is initialized */
mysql_cond_signal(&di->cond_client);