From 30c965f8664cd0aad44847c0b99b618d385c2ffe Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Fri, 28 Jul 2023 17:13:55 +0400 Subject: [PATCH] MDEV-31777 ER_GET_ERRNO upon online alter on CONNECT table Forbid Online for CONNECT. --- sql/handler.h | 5 ++- sql/sql_table.cc | 36 +++++++++++-------- storage/connect/ha_connect.cc | 2 +- .../connect/mysql-test/connect/r/alter.result | 8 +++++ .../connect/mysql-test/connect/t/alter.test | 8 +++++ 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/sql/handler.h b/sql/handler.h index 480c79017abef..91349802c6533 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -371,7 +371,10 @@ enum chf_create_flags { /* Implements SELECT ... FOR UPDATE SKIP LOCKED */ #define HA_CAN_SKIP_LOCKED (1ULL << 61) -#define HA_LAST_TABLE_FLAG HA_CAN_SKIP_LOCKED +/* This engine is not compatible with Online ALTER TABLE */ +#define HA_NO_ONLINE_ALTER (1ULL << 62) + +#define HA_LAST_TABLE_FLAG HA_NO_ONLINE_ALTER /* bits in index_flags(index_number) for what you can do with index */ diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 63eb5e4e70e58..0eb7504ec17aa 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -9908,7 +9908,8 @@ bool online_alter_check_autoinc(const THD *thd, const Alter_info *alter_info, static const char *online_alter_check_supported(const THD *thd, const Alter_info *alter_info, - const TABLE *table, bool *online) + const TABLE *table, + const TABLE *new_table, bool *online) { DBUG_ASSERT(*online); @@ -9916,6 +9917,10 @@ const char *online_alter_check_supported(const THD *thd, if (!*online) return NULL; + *online= (new_table->file->ha_table_flags() & HA_NO_ONLINE_ALTER) == 0; + if (!*online) + return new_table->file->engine_name()->str; + *online= table->s->sequence == NULL; if (!*online) return "SEQUENCE"; @@ -11023,20 +11028,6 @@ do_continue:; if (fk_prepare_copy_alter_table(thd, table, alter_info, &alter_ctx)) goto err_new_table_cleanup; - if (online) - { - const char *reason= online_alter_check_supported(thd, alter_info, table, - &online); - if (reason && - alter_info->requested_lock == Alter_info::ALTER_TABLE_LOCK_NONE) - { - DBUG_ASSERT(!online); - my_error(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON, MYF(0), - "LOCK=NONE", reason, "LOCK=SHARED"); - goto err_new_table_cleanup; - } - } - if (!table->s->tmp_table) { // If EXCLUSIVE lock is requested, upgrade already. @@ -11108,6 +11099,21 @@ do_continue:; thd->session_tracker.state_change.mark_as_changed(thd); } + if (online) + { + const char *reason= online_alter_check_supported(thd, alter_info, table, + new_table, + &online); + if (reason && + alter_info->requested_lock == Alter_info::ALTER_TABLE_LOCK_NONE) + { + DBUG_ASSERT(!online); + my_error(ER_ALTER_OPERATION_NOT_SUPPORTED_REASON, MYF(0), + "LOCK=NONE", reason, "LOCK=SHARED"); + goto err_new_table_cleanup; + } + } + /* Note: In case of MERGE table, we do not attach children. We do not copy data for MERGE tables. Only the children have data. diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 502c1f4af6def..b8acf9571de6c 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -1174,7 +1174,7 @@ ulonglong ha_connect::table_flags() const // HA_FAST_KEY_READ | causes error when sorting (???) HA_NO_TRANSACTIONS | HA_DUPLICATE_KEY_NOT_IN_ORDER | HA_NO_BLOBS | HA_MUST_USE_TABLE_CONDITION_PUSHDOWN | - HA_REUSES_FILE_NAMES; + HA_REUSES_FILE_NAMES | HA_NO_ONLINE_ALTER; ha_connect *hp= (ha_connect*)this; PTOS pos= hp->GetTableOptionStruct(); diff --git a/storage/connect/mysql-test/connect/r/alter.result b/storage/connect/mysql-test/connect/r/alter.result index 09f4584a75e76..342d7c7279139 100644 --- a/storage/connect/mysql-test/connect/r/alter.result +++ b/storage/connect/mysql-test/connect/r/alter.result @@ -272,3 +272,11 @@ line 2Two 3Three DROP TABLE t1, t2; +# MDEV-31777 ER_GET_ERRNO upon online alter with concurrent DML on +# CONNECT table +CREATE TABLE t (a INT) ENGINE=CONNECT TABLE_TYPE=DOS; +Warnings: +Warning 1105 No file name. Table will use t.dos +ALTER TABLE t FORCE, ALGORITHM=COPY, LOCK=NONE; +ERROR 0A000: LOCK=NONE is not supported. Reason: CONNECT. Try LOCK=SHARED +DROP TABLE t; diff --git a/storage/connect/mysql-test/connect/t/alter.test b/storage/connect/mysql-test/connect/t/alter.test index 0eda635502756..18688a37934b3 100644 --- a/storage/connect/mysql-test/connect/t/alter.test +++ b/storage/connect/mysql-test/connect/t/alter.test @@ -133,6 +133,14 @@ SELECT * from t2; DROP TABLE t1, t2; + +--echo # MDEV-31777 ER_GET_ERRNO upon online alter with concurrent DML on +--echo # CONNECT table +CREATE TABLE t (a INT) ENGINE=CONNECT TABLE_TYPE=DOS; +--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +ALTER TABLE t FORCE, ALGORITHM=COPY, LOCK=NONE; +DROP TABLE t; + # # Clean up #