mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
A preparatory patch for MDEV-7284 INDEX: CREATE OR REPLACE.
Removing "bool Key::create_if_not_exists" and deriving Key from DDL_options instead.
This commit is contained in:
@ -112,13 +112,12 @@ bool Key_part_spec::operator==(const Key_part_spec& other) const
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Key::Key(const Key &rhs, MEM_ROOT *mem_root)
|
Key::Key(const Key &rhs, MEM_ROOT *mem_root)
|
||||||
:type(rhs.type),
|
:DDL_options(rhs),type(rhs.type),
|
||||||
key_create_info(rhs.key_create_info),
|
key_create_info(rhs.key_create_info),
|
||||||
columns(rhs.columns, mem_root),
|
columns(rhs.columns, mem_root),
|
||||||
name(rhs.name),
|
name(rhs.name),
|
||||||
option_list(rhs.option_list),
|
option_list(rhs.option_list),
|
||||||
generated(rhs.generated),
|
generated(rhs.generated)
|
||||||
create_if_not_exists(rhs.create_if_not_exists)
|
|
||||||
{
|
{
|
||||||
list_copy_and_replace_each_value(columns, mem_root);
|
list_copy_and_replace_each_value(columns, mem_root);
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Key :public Sql_alloc {
|
class Key :public Sql_alloc, public DDL_options {
|
||||||
public:
|
public:
|
||||||
enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT, SPATIAL, FOREIGN_KEY};
|
enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT, SPATIAL, FOREIGN_KEY};
|
||||||
enum Keytype type;
|
enum Keytype type;
|
||||||
@ -287,31 +287,30 @@ public:
|
|||||||
LEX_STRING name;
|
LEX_STRING name;
|
||||||
engine_option_value *option_list;
|
engine_option_value *option_list;
|
||||||
bool generated;
|
bool generated;
|
||||||
bool create_if_not_exists;
|
|
||||||
|
|
||||||
Key(enum Keytype type_par, const LEX_STRING &name_arg,
|
Key(enum Keytype type_par, const LEX_STRING &name_arg,
|
||||||
ha_key_alg algorithm_arg, bool generated_arg, bool if_not_exists_opt)
|
ha_key_alg algorithm_arg, bool generated_arg, DDL_options_st ddl_options)
|
||||||
:type(type_par), key_create_info(default_key_create_info),
|
:DDL_options(ddl_options),
|
||||||
name(name_arg), option_list(NULL), generated(generated_arg),
|
type(type_par), key_create_info(default_key_create_info),
|
||||||
create_if_not_exists(if_not_exists_opt)
|
name(name_arg), option_list(NULL), generated(generated_arg)
|
||||||
{
|
{
|
||||||
key_create_info.algorithm= algorithm_arg;
|
key_create_info.algorithm= algorithm_arg;
|
||||||
}
|
}
|
||||||
Key(enum Keytype type_par, const LEX_STRING &name_arg,
|
Key(enum Keytype type_par, const LEX_STRING &name_arg,
|
||||||
KEY_CREATE_INFO *key_info_arg,
|
KEY_CREATE_INFO *key_info_arg,
|
||||||
bool generated_arg, List<Key_part_spec> &cols,
|
bool generated_arg, List<Key_part_spec> &cols,
|
||||||
engine_option_value *create_opt, bool if_not_exists_opt)
|
engine_option_value *create_opt, DDL_options_st ddl_options)
|
||||||
:type(type_par), key_create_info(*key_info_arg), columns(cols),
|
:DDL_options(ddl_options),
|
||||||
name(name_arg), option_list(create_opt), generated(generated_arg),
|
type(type_par), key_create_info(*key_info_arg), columns(cols),
|
||||||
create_if_not_exists(if_not_exists_opt)
|
name(name_arg), option_list(create_opt), generated(generated_arg)
|
||||||
{}
|
{}
|
||||||
Key(enum Keytype type_par, const char *name_arg, size_t name_len_arg,
|
Key(enum Keytype type_par, const char *name_arg, size_t name_len_arg,
|
||||||
KEY_CREATE_INFO *key_info_arg, bool generated_arg,
|
KEY_CREATE_INFO *key_info_arg, bool generated_arg,
|
||||||
List<Key_part_spec> &cols,
|
List<Key_part_spec> &cols,
|
||||||
engine_option_value *create_opt, bool if_not_exists_opt)
|
engine_option_value *create_opt, DDL_options_st ddl_options)
|
||||||
:type(type_par), key_create_info(*key_info_arg), columns(cols),
|
:DDL_options(ddl_options),
|
||||||
option_list(create_opt), generated(generated_arg),
|
type(type_par), key_create_info(*key_info_arg), columns(cols),
|
||||||
create_if_not_exists(if_not_exists_opt)
|
option_list(create_opt), generated(generated_arg)
|
||||||
{
|
{
|
||||||
name.str= (char *)name_arg;
|
name.str= (char *)name_arg;
|
||||||
name.length= name_len_arg;
|
name.length= name_len_arg;
|
||||||
@ -344,9 +343,9 @@ public:
|
|||||||
const LEX_STRING &ref_db_arg, const LEX_STRING &ref_table_arg,
|
const LEX_STRING &ref_db_arg, const LEX_STRING &ref_table_arg,
|
||||||
List<Key_part_spec> &ref_cols,
|
List<Key_part_spec> &ref_cols,
|
||||||
uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg,
|
uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg,
|
||||||
bool if_not_exists_opt)
|
DDL_options ddl_options)
|
||||||
:Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols, NULL,
|
:Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols, NULL,
|
||||||
if_not_exists_opt),
|
ddl_options),
|
||||||
ref_db(ref_db_arg), ref_table(ref_table_arg), ref_columns(ref_cols),
|
ref_db(ref_db_arg), ref_table(ref_table_arg), ref_columns(ref_cols),
|
||||||
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
|
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
|
||||||
match_opt(match_opt_arg)
|
match_opt(match_opt_arg)
|
||||||
|
@ -2857,7 +2857,7 @@ public:
|
|||||||
ha_key_alg algorithm, DDL_options_st ddl)
|
ha_key_alg algorithm, DDL_options_st ddl)
|
||||||
{
|
{
|
||||||
if (check_add_key(ddl) ||
|
if (check_add_key(ddl) ||
|
||||||
!(last_key= new Key(type, name, algorithm, false, ddl.if_not_exists())))
|
!(last_key= new Key(type, name, algorithm, false, ddl)))
|
||||||
return true;
|
return true;
|
||||||
alter_info.key_list.push_back(last_key);
|
alter_info.key_list.push_back(last_key);
|
||||||
return false;
|
return false;
|
||||||
@ -2866,7 +2866,7 @@ public:
|
|||||||
bool add_create_index(Key::Keytype type, const LEX_STRING &name,
|
bool add_create_index(Key::Keytype type, const LEX_STRING &name,
|
||||||
ha_key_alg algorithm, DDL_options_st ddl)
|
ha_key_alg algorithm, DDL_options_st ddl)
|
||||||
{
|
{
|
||||||
if (!(last_key= new Key(type, name, algorithm, false, ddl.if_not_exists())))
|
if (!(last_key= new Key(type, name, algorithm, false, ddl)))
|
||||||
return true;
|
return true;
|
||||||
alter_info.key_list.push_back(last_key);
|
alter_info.key_list.push_back(last_key);
|
||||||
return false;
|
return false;
|
||||||
|
@ -5830,7 +5830,7 @@ drop_create_field:
|
|||||||
const char *keyname;
|
const char *keyname;
|
||||||
while ((key=key_it++))
|
while ((key=key_it++))
|
||||||
{
|
{
|
||||||
if (!key->create_if_not_exists)
|
if (!key->if_not_exists())
|
||||||
continue;
|
continue;
|
||||||
/* If the name of the key is not specified, */
|
/* If the name of the key is not specified, */
|
||||||
/* let us check the name of the first key part. */
|
/* let us check the name of the first key part. */
|
||||||
@ -7627,7 +7627,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
|||||||
key= new Key(key_type, key_name, strlen(key_name),
|
key= new Key(key_type, key_name, strlen(key_name),
|
||||||
&key_create_info,
|
&key_create_info,
|
||||||
MY_TEST(key_info->flags & HA_GENERATED_KEY),
|
MY_TEST(key_info->flags & HA_GENERATED_KEY),
|
||||||
key_parts, key_info->option_list, FALSE);
|
key_parts, key_info->option_list, DDL_options());
|
||||||
new_key_list.push_back(key);
|
new_key_list.push_back(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -852,7 +852,9 @@ static void add_key_to_list(LEX *lex, LEX_STRING *field_name,
|
|||||||
enum Key::Keytype type, bool check_exists)
|
enum Key::Keytype type, bool check_exists)
|
||||||
{
|
{
|
||||||
Key *key;
|
Key *key;
|
||||||
key= new Key(type, null_lex_str, HA_KEY_ALG_UNDEF, false, check_exists);
|
key= new Key(type, null_lex_str, HA_KEY_ALG_UNDEF, false,
|
||||||
|
DDL_options(check_exists ? DDL_options::OPT_IF_NOT_EXISTS :
|
||||||
|
DDL_options::OPT_NONE));
|
||||||
key->columns.push_back(new Key_part_spec(*field_name, 0));
|
key->columns.push_back(new Key_part_spec(*field_name, 0));
|
||||||
lex->alter_info.key_list.push_back(key);
|
lex->alter_info.key_list.push_back(key);
|
||||||
}
|
}
|
||||||
@ -6055,8 +6057,7 @@ key_def:
|
|||||||
{
|
{
|
||||||
if (Lex->check_add_key($4) ||
|
if (Lex->check_add_key($4) ||
|
||||||
!(Lex->last_key= new Key(Key::MULTIPLE, $1.str ? $1 : $5,
|
!(Lex->last_key= new Key(Key::MULTIPLE, $1.str ? $1 : $5,
|
||||||
HA_KEY_ALG_UNDEF, true,
|
HA_KEY_ALG_UNDEF, true, $4)))
|
||||||
$4.if_not_exists())))
|
|
||||||
MYSQL_YYABORT;
|
MYSQL_YYABORT;
|
||||||
Lex->option_list= NULL;
|
Lex->option_list= NULL;
|
||||||
}
|
}
|
||||||
@ -6071,7 +6072,7 @@ key_def:
|
|||||||
lex->fk_delete_opt,
|
lex->fk_delete_opt,
|
||||||
lex->fk_update_opt,
|
lex->fk_update_opt,
|
||||||
lex->fk_match_option,
|
lex->fk_match_option,
|
||||||
$4.if_not_exists());
|
$4);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
MYSQL_YYABORT;
|
MYSQL_YYABORT;
|
||||||
/*
|
/*
|
||||||
|
@ -477,7 +477,7 @@ public:
|
|||||||
DDL options:
|
DDL options:
|
||||||
- CREATE IF NOT EXISTS
|
- CREATE IF NOT EXISTS
|
||||||
- DROP IF EXISTS
|
- DROP IF EXISTS
|
||||||
- CRESTE LIKE
|
- CREATE LIKE
|
||||||
- REPLACE
|
- REPLACE
|
||||||
*/
|
*/
|
||||||
struct DDL_options_st
|
struct DDL_options_st
|
||||||
@ -544,6 +544,9 @@ class DDL_options: public DDL_options_st
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DDL_options() { init(); }
|
DDL_options() { init(); }
|
||||||
|
DDL_options(Options options) { init(options); }
|
||||||
|
DDL_options(const DDL_options_st &options)
|
||||||
|
{ DDL_options_st::operator=(options); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user