From f02af1d2295f108d96671b5a4f731ec998002dd5 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Wed, 31 Aug 2022 11:55:02 +0300 Subject: MDEV-25292 Refactoring: moved select_field_count into Alter_info. There is a need in MDEV-25292 to have both C_ALTER_TABLE and select_field_count in one call. Semantically creation mode and field count are two different things. Making creation mode negative constants and field count positive variable into one parameter seems to be a lazy hack for not making the second parameter. select_count does not make sense without alter_info->create_list, so the natural way is to hold it in Alter_info too. select_count is now stored in member select_field_count. --- sql/handler.cc | 9 ++++----- sql/handler.h | 6 ++---- sql/sql_alter.h | 8 ++++++++ sql/sql_insert.cc | 7 +++---- sql/sql_table.cc | 5 ++--- sql/sql_table.h | 7 +++---- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index 5743fc2a455..47fa92a0d2f 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -8187,7 +8187,7 @@ bool Table_scope_and_contents_source_st::vers_fix_system_fields( bool Table_scope_and_contents_source_st::vers_check_system_fields( THD *thd, Alter_info *alter_info, const Lex_table_name &table_name, - const Lex_table_name &db, int select_count) + const Lex_table_name &db) { if (!(options & HA_VERSIONED_TABLE)) return false; @@ -8208,7 +8208,7 @@ bool Table_scope_and_contents_source_st::vers_check_system_fields( SELECT go last there. */ bool is_dup= false; - if (fieldnr >= alter_info->create_list.elements - select_count) + if (fieldnr >= alter_info->field_count()) { List_iterator dup_it(alter_info->create_list); for (Create_field *dup= dup_it++; !is_dup && dup != f; dup= dup_it++) @@ -8616,10 +8616,9 @@ bool Table_period_info::check_field(const Create_field* f, bool Table_scope_and_contents_source_st::check_fields( THD *thd, Alter_info *alter_info, - const Lex_table_name &table_name, const Lex_table_name &db, int select_count) + const Lex_table_name &table_name, const Lex_table_name &db) { - return vers_check_system_fields(thd, alter_info, - table_name, db, select_count) || + return vers_check_system_fields(thd, alter_info, table_name, db) || check_period_fields(thd, alter_info); } diff --git a/sql/handler.h b/sql/handler.h index 60c6195e68e..027d8351831 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -2257,8 +2257,7 @@ struct Table_scope_and_contents_source_st: bool fix_period_fields(THD *thd, Alter_info *alter_info); bool check_fields(THD *thd, Alter_info *alter_info, const Lex_table_name &table_name, - const Lex_table_name &db, - int select_count= 0); + const Lex_table_name &db); bool check_period_fields(THD *thd, Alter_info *alter_info); bool vers_fix_system_fields(THD *thd, Alter_info *alter_info, @@ -2266,8 +2265,7 @@ struct Table_scope_and_contents_source_st: bool vers_check_system_fields(THD *thd, Alter_info *alter_info, const Lex_table_name &table_name, - const Lex_table_name &db, - int select_count= 0); + const Lex_table_name &db); }; diff --git a/sql/sql_alter.h b/sql/sql_alter.h index bf1edd4c964..142b71c725a 100644 --- a/sql/sql_alter.h +++ b/sql/sql_alter.h @@ -96,6 +96,7 @@ public: List alter_rename_key_list; // List of columns, used by both CREATE and ALTER TABLE. List create_list; + uint select_field_count; // Indexes whose ignorability needs to be changed. List alter_index_ignorability_list; List check_constraint_list; @@ -118,6 +119,7 @@ public: Alter_info() : + select_field_count(0), flags(0), partition_flags(0), keys_onoff(LEAVE_AS_IS), num_parts(0), @@ -134,6 +136,7 @@ public: create_list.empty(); alter_index_ignorability_list.empty(); check_constraint_list.empty(); + select_field_count= 0; flags= 0; partition_flags= 0; keys_onoff= LEAVE_AS_IS; @@ -234,6 +237,11 @@ public: */ enum_alter_table_algorithm algorithm(const THD *thd) const; + uint field_count() const + { + return create_list.elements - select_field_count; + } + private: Alter_info &operator=(const Alter_info &rhs); // not implemented Alter_info(const Alter_info &rhs); // not implemented diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index baa7f783266..d3919a161ed 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -4490,7 +4490,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List *items, TABLE tmp_table; // Used during 'Create_field()' TABLE_SHARE share; TABLE *table= 0; - uint select_field_count= items->elements; + alter_info->select_field_count= items->elements; /* Add selected items to field list */ List_iterator_fast it(*items); Item *item; @@ -4550,8 +4550,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List *items, if (create_info->check_fields(thd, alter_info, create_table->table_name, - create_table->db, - select_field_count)) + create_table->db)) DBUG_RETURN(NULL); DEBUG_SYNC(thd,"create_table_select_before_create"); @@ -4587,7 +4586,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List *items, &create_table->db, &create_table->table_name, create_info, alter_info, NULL, - select_field_count, create_table)) + C_ORDINARY_CREATE, create_table)) { DEBUG_SYNC(thd,"create_table_select_before_open"); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index c934d58087a..7cbc5fbada0 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2741,7 +2741,6 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, List_iterator_fast it(alter_info->create_list); List_iterator it2(alter_info->create_list); uint total_uneven_bit_length= 0; - int select_field_count= C_CREATE_SELECT(create_table_mode); bool tmp_table= create_table_mode == C_ALTER_TABLE; const bool create_simple= thd->lex->create_simple(); bool is_hash_field_needed= false; @@ -2781,7 +2780,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, DBUG_RETURN(TRUE); } - select_field_pos= alter_info->create_list.elements - select_field_count; + select_field_pos= alter_info->field_count(); null_fields= 0; create_info->varchar= 0; max_key_length= file->max_key_length(); @@ -2956,7 +2955,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, from the select tables. This order may differ on master and slave. We therefore mark it as unsafe. */ - if (select_field_count > 0 && auto_increment) + if (alter_info->select_field_count > 0 && auto_increment) thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_CREATE_SELECT_AUTOINC); /* Create keys */ diff --git a/sql/sql_table.h b/sql/sql_table.h index c9e4d969482..4d74aadc02a 100644 --- a/sql/sql_table.h +++ b/sql/sql_table.h @@ -124,11 +124,10 @@ bool add_keyword_to_query(THD *thd, String *result, const LEX_CSTRING *keyword, (which should be the number of fields in the SELECT ... part), and other cases use constants as defined below. */ -#define C_CREATE_SELECT(X) ((X) > 0 ? (X) : 0) #define C_ORDINARY_CREATE 0 -#define C_ALTER_TABLE -1 -#define C_ALTER_TABLE_FRM_ONLY -2 -#define C_ASSISTED_DISCOVERY -3 +#define C_ALTER_TABLE 1 +#define C_ALTER_TABLE_FRM_ONLY 2 +#define C_ASSISTED_DISCOVERY 3 int mysql_create_table_no_lock(THD *thd, DDL_LOG_STATE *ddl_log_state, -- cgit v1.2.1