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.
This commit is contained in:
parent
5369df741b
commit
f02af1d229
@ -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<Create_field> 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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
};
|
||||
|
||||
|
@ -96,6 +96,7 @@ public:
|
||||
List<Alter_rename_key> alter_rename_key_list;
|
||||
// List of columns, used by both CREATE and ALTER TABLE.
|
||||
List<Create_field> create_list;
|
||||
uint select_field_count;
|
||||
// Indexes whose ignorability needs to be changed.
|
||||
List<Alter_index_ignorability> alter_index_ignorability_list;
|
||||
List<Virtual_column_info> 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
|
||||
|
@ -4490,7 +4490,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List<Item> *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<Item> it(*items);
|
||||
Item *item;
|
||||
@ -4550,8 +4550,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List<Item> *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<Item> *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");
|
||||
|
||||
|
@ -2741,7 +2741,6 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
List_iterator_fast<Create_field> it(alter_info->create_list);
|
||||
List_iterator<Create_field> 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 */
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user