MySQL Forums
Forum List  »  UDF

Failed to close tables in UDF functions in MySQL 5.6
Posted by: Jun Liu
Date: December 27, 2013 01:16PM

I'm trying to properly close tables that are opened in a UDF function. The idea was that the UDF is used to maintain consistency between two sets of tables. The UDF is called through a TRIGGER. I'm able to "correctly" open a list of tables by creating TABLE_LIST manually and use a new instance of the THD to open them, something like this,

THD *thd = new THD;
thd->thread_stack = (char*) &thd;
thd->set_db(city_sub_schema, strlen(city_sub_schema));
my_pthread_setspecific_ptr(THR_THD, the);

const unsigned int NUMBER_OF_TABLES = 5;
char* tableNames[NUMBER_OF_TABLES];

… set table names here ...

for (unsigned int i = 0; i < NUMBER_OF_TABLES; i++)
tables.init_one_table((char*)db_name, strlen(db_name), tableNames, strlen(tableNames),
if (i != NUMBER_OF_TABLES-1)
tables.next_local = tables.next_global = tables + 1 + i;
if (open_and_lock_tables(thd, tables, false, MYSQL_LOCK_IGNORE_TIMEOUT))
goto end;

However, when I'm trying to close them using the code block below,

delete the;

The above code failed to close tables as (assert failed) thd->transaction->stmt->is_empty() returns false.

I'm wondering if any one knows what's the proper way of closing opened tables with a THD instance.

Options: ReplyQuote

Written By
Failed to close tables in UDF functions in MySQL 5.6
December 27, 2013 01:16PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.