diff options
author | Monty <monty@mariadb.org> | 2021-06-11 15:34:23 +0300 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2021-06-14 17:03:19 +0300 |
commit | af33202af753da93e48f30b83c959c5a587f2458 (patch) | |
tree | c07af0078f547d4d493a1a8ed4192c3608d91b35 | |
parent | 4ea1c48abe3087a38a6260c8e21084de5e1a105b (diff) | |
download | mariadb-git-af33202af753da93e48f30b83c959c5a587f2458.tar.gz |
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)
-rw-r--r-- | include/mysql/plugin.h | 2 | ||||
-rw-r--r-- | include/mysql/plugin_audit.h.pp | 2 | ||||
-rw-r--r-- | include/mysql/plugin_auth.h.pp | 2 | ||||
-rw-r--r-- | include/mysql/plugin_data_type.h.pp | 2 | ||||
-rw-r--r-- | include/mysql/plugin_encryption.h.pp | 2 | ||||
-rw-r--r-- | include/mysql/plugin_ftparser.h.pp | 2 | ||||
-rw-r--r-- | include/mysql/plugin_function.h.pp | 2 | ||||
-rw-r--r-- | include/mysql/plugin_password_validation.h.pp | 2 | ||||
-rw-r--r-- | sql/sql_class.cc | 12 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 3 | ||||
-rw-r--r-- | sql/structs.h | 5 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 20 |
12 files changed, 42 insertions, 14 deletions
diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index 738ffc6c53f..d3301a36e82 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -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); diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index 07fe16ea92f..2e0cdff4b50 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -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); diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp index 18eebd5e04a..464c5514acb 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -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); diff --git a/include/mysql/plugin_data_type.h.pp b/include/mysql/plugin_data_type.h.pp index 3db2fdd0251..cb256e00cd7 100644 --- a/include/mysql/plugin_data_type.h.pp +++ b/include/mysql/plugin_data_type.h.pp @@ -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); diff --git a/include/mysql/plugin_encryption.h.pp b/include/mysql/plugin_encryption.h.pp index ff436bb24c4..11cd622861c 100644 --- a/include/mysql/plugin_encryption.h.pp +++ b/include/mysql/plugin_encryption.h.pp @@ -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); diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp index daefd6b2838..9a798627518 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -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); diff --git a/include/mysql/plugin_function.h.pp b/include/mysql/plugin_function.h.pp index 0f915c8413f..4b2a0fc7082 100644 --- a/include/mysql/plugin_function.h.pp +++ b/include/mysql/plugin_function.h.pp @@ -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); diff --git a/include/mysql/plugin_password_validation.h.pp b/include/mysql/plugin_password_validation.h.pp index fc8c3848f8c..eae776a753b 100644 --- a/include/mysql/plugin_password_validation.h.pp +++ b/include/mysql/plugin_password_validation.h.pp @@ -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); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 1d27854dc82..6317e578156 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -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) { diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index b91b657dea3..dc2eb4425f0 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -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: diff --git a/sql/structs.h b/sql/structs.h index fa0da6e0dbb..59bab6c6f18 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -537,7 +537,8 @@ public: 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 @@ public: { 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); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index bfb587bef6a..2c0a5f8f114 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -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); |