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)
This commit is contained in:
Monty 2021-06-11 15:34:23 +03:00
parent 4ea1c48abe
commit af33202af7
12 changed files with 42 additions and 14 deletions

View File

@ -660,6 +660,8 @@ int thd_in_lock_tables(const MYSQL_THD thd);
int thd_tablespace_op(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); long long thd_test_options(const MYSQL_THD thd, long long test_options);
int thd_sql_command(const MYSQL_THD thd); 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); void thd_storage_lock_wait(MYSQL_THD thd, long long value);
int thd_tx_isolation(const MYSQL_THD thd); int thd_tx_isolation(const MYSQL_THD thd);
int thd_tx_is_read_only(const MYSQL_THD thd); int thd_tx_is_read_only(const MYSQL_THD thd);

View File

@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd); int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options); long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd); 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); void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd); int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd); int thd_tx_is_read_only(const THD* thd);

View File

@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd); int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options); long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd); 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); void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd); int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd); int thd_tx_is_read_only(const THD* thd);

View File

@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd); int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options); long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd); 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); void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd); int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd); int thd_tx_is_read_only(const THD* thd);

View File

@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd); int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options); long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd); 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); void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd); int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd); int thd_tx_is_read_only(const THD* thd);

View File

@ -560,6 +560,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd); int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options); long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd); 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); void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd); int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd); int thd_tx_is_read_only(const THD* thd);

View File

@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd); int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options); long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd); 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); void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd); int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd); int thd_tx_is_read_only(const THD* thd);

View File

@ -608,6 +608,8 @@ int thd_in_lock_tables(const THD* thd);
int thd_tablespace_op(const THD* thd); int thd_tablespace_op(const THD* thd);
long long thd_test_options(const THD* thd, long long test_options); long long thd_test_options(const THD* thd, long long test_options);
int thd_sql_command(const THD* thd); 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); void thd_storage_lock_wait(THD* thd, long long value);
int thd_tx_isolation(const THD* thd); int thd_tx_isolation(const THD* thd);
int thd_tx_is_read_only(const THD* thd); int thd_tx_is_read_only(const THD* thd);

View File

@ -499,6 +499,18 @@ int thd_sql_command(const THD *thd)
return (int) thd->lex->sql_command; 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" extern "C"
int thd_tx_isolation(const THD *thd) int thd_tx_isolation(const THD *thd)
{ {

View File

@ -4675,6 +4675,9 @@ create_like:
opt_create_select: opt_create_select:
/* empty */ {} /* empty */ {}
| opt_duplicate opt_as create_select_query_expression opt_versioning_option | 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: create_select_query_expression:

View File

@ -537,7 +537,8 @@ public:
OPT_OR_REPLACE= 16, // CREATE OR REPLACE TABLE OPT_OR_REPLACE= 16, // CREATE OR REPLACE TABLE
OPT_OR_REPLACE_SLAVE_GENERATED= 32,// REPLACE was added on slave, it was OPT_OR_REPLACE_SLAVE_GENERATED= 32,// REPLACE was added on slave, it was
// not in the original query on master. // not in the original query on master.
OPT_IF_EXISTS= 64 OPT_IF_EXISTS= 64,
OPT_CREATE_SELECT= 128 // CREATE ... SELECT
}; };
private: private:
@ -565,6 +566,8 @@ public:
{ return m_options & OPT_OR_REPLACE_SLAVE_GENERATED; } { return m_options & OPT_OR_REPLACE_SLAVE_GENERATED; }
bool like() const { return m_options & OPT_LIKE; } bool like() const { return m_options & OPT_LIKE; }
bool if_exists() const { return m_options & OPT_IF_EXISTS; } 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) void add(const DDL_options_st::Options other)
{ {
m_options= (Options) ((uint) m_options | (uint) other); m_options= (Options) ((uint) m_options | (uint) other);

View File

@ -13258,21 +13258,15 @@ int ha_innobase::delete_table(const char *name)
trx_t *trx= parent_trx; trx_t *trx= parent_trx;
if (!trx->lock.table_locks.empty() && 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 /* CREATE TABLE...PRIMARY KEY...SELECT ought to be dropping the
table because a duplicate key was detected. We shall hijack the table because a duplicate key was detected or a timeout occurred.
existing transaction to drop the table and commit the transaction.
If this is a partitioned table, one partition will use this hijacked We shall hijack the existing transaction to drop the table and
transaction; others will use a separate transaction, one per partition. */ 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->dict_operation_lock_mode);
ut_ad(trx->will_lock); ut_ad(trx->will_lock);
ut_ad(trx->state == TRX_STATE_ACTIVE); ut_ad(trx->state == TRX_STATE_ACTIVE);