Commit af33202a authored by Monty's avatar Monty

Added DDL_options_st *thd_ddl_options(const MYSQL_THD thd)

This is used by InnoDB to detect if CREATE...SELECT is used

Other things:
- Changed InnoDB to use thd_ddl_options()
- Removed lock checking code for create...select (Approved by Marko)
parent 4ea1c48a
......@@ -660,6 +660,8 @@ int thd_in_lock_tables(const MYSQL_THD thd);
int thd_tablespace_op(const MYSQL_THD thd);
long long thd_test_options(const MYSQL_THD thd, long long test_options);
int thd_sql_command(const MYSQL_THD thd);
struct DDL_options_st;
struct DDL_options_st *thd_ddl_options(const MYSQL_THD thd);
void thd_storage_lock_wait(MYSQL_THD thd, long long value);
int thd_tx_isolation(const MYSQL_THD thd);
int thd_tx_is_read_only(const MYSQL_THD thd);
......
......@@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd);
struct DDL_options_st;
struct DDL_options_st *thd_ddl_options(const THD* thd);
void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd);
......
......@@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd);
struct DDL_options_st;
struct DDL_options_st *thd_ddl_options(const THD* thd);
void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd);
......
......@@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd);
struct DDL_options_st;
struct DDL_options_st *thd_ddl_options(const THD* thd);
void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd);
......
......@@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd);
struct DDL_options_st;
struct DDL_options_st *thd_ddl_options(const THD* thd);
void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd);
......
......@@ -560,6 +560,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd);
struct DDL_options_st;
struct DDL_options_st *thd_ddl_options(const THD* thd);
void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd);
......
......@@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd);
struct DDL_options_st;
struct DDL_options_st *thd_ddl_options(const THD* thd);
void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd);
......
......@@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd);
struct DDL_options_st;
struct DDL_options_st *thd_ddl_options(const THD* thd);
void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd);
......
......@@ -499,6 +499,18 @@ int thd_sql_command(const THD *thd)
return (int) thd->lex->sql_command;
}
/*
Returns options used with DDL's, like IF EXISTS etc...
Will returns 'nonsense' if the command was not a DDL.
*/
extern "C"
struct DDL_options_st *thd_ddl_options(const THD *thd)
{
return &thd->lex->create_info;
}
extern "C"
int thd_tx_isolation(const THD *thd)
{
......
......@@ -4675,6 +4675,9 @@ create_like:
opt_create_select:
/* empty */ {}
| opt_duplicate opt_as create_select_query_expression opt_versioning_option
{
Lex->create_info.add(DDL_options_st::OPT_CREATE_SELECT);
}
;
create_select_query_expression:
......
......@@ -537,7 +537,8 @@ struct DDL_options_st
OPT_OR_REPLACE= 16, // CREATE OR REPLACE TABLE
OPT_OR_REPLACE_SLAVE_GENERATED= 32,// REPLACE was added on slave, it was
// not in the original query on master.
OPT_IF_EXISTS= 64
OPT_IF_EXISTS= 64,
OPT_CREATE_SELECT= 128 // CREATE ... SELECT
};
private:
......@@ -565,6 +566,8 @@ struct DDL_options_st
{ return m_options & OPT_OR_REPLACE_SLAVE_GENERATED; }
bool like() const { return m_options & OPT_LIKE; }
bool if_exists() const { return m_options & OPT_IF_EXISTS; }
bool is_create_select() const { return m_options & OPT_CREATE_SELECT; }
void add(const DDL_options_st::Options other)
{
m_options= (Options) ((uint) m_options | (uint) other);
......
......@@ -13258,21 +13258,15 @@ int ha_innobase::delete_table(const char *name)
trx_t *trx= parent_trx;
if (!trx->lock.table_locks.empty() &&
thd_sql_command(trx->mysql_thd) == SQLCOM_CREATE_TABLE)
thd_ddl_options(trx->mysql_thd)->is_create_select())
{
#if 0 // MDEV-21602 FIXME: this fails for innodb.innodb and some others
for (const lock_t *l : trx->lock.table_locks)
if (l && l->type_mode == (LOCK_IX | LOCK_TABLE) &&
l->un_member.tab_lock.table == table)
goto create_select;
sql_print_warning("InnoDB: CREATE...SELECT did not hold expected locks");
create_select:
#endif
/* CREATE TABLE...PRIMARY KEY...SELECT ought to be dropping the
table because a duplicate key was detected. We shall hijack the
existing transaction to drop the table and commit the transaction.
If this is a partitioned table, one partition will use this hijacked
transaction; others will use a separate transaction, one per partition. */
table because a duplicate key was detected or a timeout occurred.
We shall hijack the existing transaction to drop the table and
commit the transaction. If this is a partitioned table, one
partition will use this hijacked transaction; others will use a
separate transaction, one per partition. */
ut_ad(!trx->dict_operation_lock_mode);
ut_ad(trx->will_lock);
ut_ad(trx->state == TRX_STATE_ACTIVE);
......
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