Skip to content

Commit

Permalink
Added DDL_options_st *thd_ddl_options(const MYSQL_THD thd)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
montywi committed Jun 14, 2021
1 parent 4ea1c48 commit af33202
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 14 deletions.
2 changes: 2 additions & 0 deletions include/mysql/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_audit.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@
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);
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_auth.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@
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);
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_data_type.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@
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);
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_encryption.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@
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);
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_ftparser.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@
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);
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_function.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@
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);
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_password_validation.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@
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);
Expand Down
12 changes: 12 additions & 0 deletions sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion sql/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 7 additions & 13 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit af33202

Please sign in to comment.