summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2015-03-20 13:51:41 +0400
committerAlexander Barkov <bar@mariadb.org>2015-03-20 13:51:41 +0400
commit0c26c0032c9654570021094fa64b2816dc4ac9ea (patch)
tree42c56e57f12032f6d991fc554764e15df0ede368 /sql
parent2a2cc164784b10a6c87f626a98b3363a976a5eb7 (diff)
downloadmariadb-git-0c26c0032c9654570021094fa64b2816dc4ac9ea.tar.gz
A preparatory patch for MDEV-7284 INDEX: CREATE OR REPLACE.
Removing "bool Key::create_if_not_exists" and deriving Key from DDL_options instead.
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_class.cc5
-rw-r--r--sql/sql_class.h31
-rw-r--r--sql/sql_lex.h4
-rw-r--r--sql/sql_table.cc4
-rw-r--r--sql/sql_yacc.yy9
-rw-r--r--sql/structs.h5
6 files changed, 30 insertions, 28 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 3071ba65155..ff27bfbac74 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -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);
}
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 19baf6783f7..d391d25c362 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -278,7 +278,7 @@ public:
};
-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 @@ public:
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 @@ public:
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)
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 4fa025166dd..a0da5a94c22 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -2857,7 +2857,7 @@ public:
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 @@ public:
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;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 898f70448ea..c4b07ad2035 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -5830,7 +5830,7 @@ drop_create_field:
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);
}
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 1fc8e5ababf..1153ff867e9 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -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;
/*
diff --git a/sql/structs.h b/sql/structs.h
index de062f4a2ad..191463af344 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -477,7 +477,7 @@ public:
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); }
};