summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2023-01-18 16:52:06 +0300
committerAleksey Midenkov <midenok@gmail.com>2023-01-26 17:15:19 +0300
commit8d66abd3fdcacff10234dac98244730ad25f1fdc (patch)
tree904e43316e8adf49986cbd8caf94662cfde2c3fe
parent666a1f11847e3be1a98ce332dc511259587440cc (diff)
downloadmariadb-git-8d66abd3fdcacff10234dac98244730ad25f1fdc.tar.gz
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.
-rw-r--r--sql/handler.cc9
-rw-r--r--sql/handler.h7
-rw-r--r--sql/sql_alter.h8
-rw-r--r--sql/sql_insert.cc7
-rw-r--r--sql/sql_table.cc5
-rw-r--r--sql/sql_table.h7
6 files changed, 23 insertions, 20 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index 837a7be7ad6..591dfda931e 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -8208,7 +8208,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;
@@ -8229,7 +8229,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++)
@@ -8638,10 +8638,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 51266185e59..99088dd2d28 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -2262,8 +2262,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);
void vers_check_native();
@@ -2272,8 +2271,8 @@ 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> 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
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 5d713d2176e..d1eecea0472 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -4496,7 +4496,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;
@@ -4566,8 +4566,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List<Item> *items,
if (create_info->check_fields(thd, alter_info,
table_list->table_name,
- table_list->db,
- select_field_count))
+ table_list->db))
DBUG_RETURN(NULL);
DEBUG_SYNC(thd,"create_table_select_before_create");
@@ -4603,7 +4602,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List<Item> *items,
&table_list->db,
&table_list->table_name,
create_info, alter_info, NULL,
- select_field_count, table_list))
+ C_ORDINARY_CREATE, table_list))
{
DEBUG_SYNC(thd,"create_table_select_before_open");
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 3ca70ff93f0..3d294879aa3 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -2744,7 +2744,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;
@@ -2784,7 +2783,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();
@@ -2959,7 +2958,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,