Commit 0c26c003 authored by Alexander Barkov's avatar Alexander Barkov

A preparatory patch for MDEV-7284 INDEX: CREATE OR REPLACE.

Removing "bool Key::create_if_not_exists" and deriving Key from
DDL_options instead.
parent 2a2cc164
......@@ -112,13 +112,12 @@ bool Key_part_spec::operator==(const Key_part_spec& other) const
*/
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),
columns(rhs.columns, mem_root),
name(rhs.name),
option_list(rhs.option_list),
generated(rhs.generated),
create_if_not_exists(rhs.create_if_not_exists)
generated(rhs.generated)
{
list_copy_and_replace_each_value(columns, mem_root);
}
......
......@@ -278,7 +278,7 @@ class Alter_column :public Sql_alloc {
};
class Key :public Sql_alloc {
class Key :public Sql_alloc, public DDL_options {
public:
enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT, SPATIAL, FOREIGN_KEY};
enum Keytype type;
......@@ -287,31 +287,30 @@ class Key :public Sql_alloc {
LEX_STRING name;
engine_option_value *option_list;
bool generated;
bool create_if_not_exists;
Key(enum Keytype type_par, const LEX_STRING &name_arg,
ha_key_alg algorithm_arg, bool generated_arg, bool if_not_exists_opt)
:type(type_par), key_create_info(default_key_create_info),
name(name_arg), option_list(NULL), generated(generated_arg),
create_if_not_exists(if_not_exists_opt)
ha_key_alg algorithm_arg, bool generated_arg, DDL_options_st ddl_options)
:DDL_options(ddl_options),
type(type_par), key_create_info(default_key_create_info),
name(name_arg), option_list(NULL), generated(generated_arg)
{
key_create_info.algorithm= algorithm_arg;
}
Key(enum Keytype type_par, const LEX_STRING &name_arg,
KEY_CREATE_INFO *key_info_arg,
bool generated_arg, List<Key_part_spec> &cols,
engine_option_value *create_opt, bool if_not_exists_opt)
:type(type_par), key_create_info(*key_info_arg), columns(cols),
name(name_arg), option_list(create_opt), generated(generated_arg),
create_if_not_exists(if_not_exists_opt)
engine_option_value *create_opt, DDL_options_st ddl_options)
:DDL_options(ddl_options),
type(type_par), key_create_info(*key_info_arg), columns(cols),
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_CREATE_INFO *key_info_arg, bool generated_arg,
List<Key_part_spec> &cols,
engine_option_value *create_opt, bool if_not_exists_opt)
:type(type_par), key_create_info(*key_info_arg), columns(cols),
option_list(create_opt), generated(generated_arg),
create_if_not_exists(if_not_exists_opt)
engine_option_value *create_opt, DDL_options_st ddl_options)
:DDL_options(ddl_options),
type(type_par), key_create_info(*key_info_arg), columns(cols),
option_list(create_opt), generated(generated_arg)
{
name.str= (char *)name_arg;
name.length= name_len_arg;
......@@ -344,9 +343,9 @@ class Foreign_key: public Key {
const LEX_STRING &ref_db_arg, const LEX_STRING &ref_table_arg,
List<Key_part_spec> &ref_cols,
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,
if_not_exists_opt),
ddl_options),
ref_db(ref_db_arg), ref_table(ref_table_arg), ref_columns(ref_cols),
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
match_opt(match_opt_arg)
......
......@@ -2857,7 +2857,7 @@ struct LEX: public Query_tables_list
ha_key_alg algorithm, DDL_options_st 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;
alter_info.key_list.push_back(last_key);
return false;
......@@ -2866,7 +2866,7 @@ struct LEX: public Query_tables_list
bool add_create_index(Key::Keytype type, const LEX_STRING &name,
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;
alter_info.key_list.push_back(last_key);
return false;
......
......@@ -5830,7 +5830,7 @@ handle_if_exists_options(THD *thd, TABLE *table, Alter_info *alter_info)
const char *keyname;
while ((key=key_it++))
{
if (!key->create_if_not_exists)
if (!key->if_not_exists())
continue;
/* If the name of the key is not specified, */
/* 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_create_info,
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);
}
}
......
......@@ -852,7 +852,9 @@ static void add_key_to_list(LEX *lex, LEX_STRING *field_name,
enum Key::Keytype type, bool check_exists)
{
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));
lex->alter_info.key_list.push_back(key);
}
......@@ -6055,8 +6057,7 @@ key_def:
{
if (Lex->check_add_key($4) ||
!(Lex->last_key= new Key(Key::MULTIPLE, $1.str ? $1 : $5,
HA_KEY_ALG_UNDEF, true,
$4.if_not_exists())))
HA_KEY_ALG_UNDEF, true, $4)))
MYSQL_YYABORT;
Lex->option_list= NULL;
}
......@@ -6071,7 +6072,7 @@ key_def:
lex->fk_delete_opt,
lex->fk_update_opt,
lex->fk_match_option,
$4.if_not_exists());
$4);
if (key == NULL)
MYSQL_YYABORT;
/*
......
......@@ -477,7 +477,7 @@ class Discrete_intervals_list {
DDL options:
- CREATE IF NOT EXISTS
- DROP IF EXISTS
- CRESTE LIKE
- CREATE LIKE
- REPLACE
*/
struct DDL_options_st
......@@ -544,6 +544,9 @@ class DDL_options: public DDL_options_st
{
public:
DDL_options() { init(); }
DDL_options(Options options) { init(options); }
DDL_options(const DDL_options_st &options)
{ DDL_options_st::operator=(options); }
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment