Commit 5130f520 authored by Aleksey Midenkov's avatar Aleksey Midenkov

MDEV-20480 Obsolete internal parser for FK in InnoDB

Currently InnoDB uses internal parser for adding foreign keys. Remove
internal parser and use data parsed by SQL parser (sql_yacc) for
adding foreign keys.

- create_table_info_t::create_foreign_keys() replacement for
  dict_create_foreign_constraints_low();
- Pass constraint name via Foreign_key object.

Temporary until MDEV-20865:

- Pass alter_info as part of create_info.
parent 20b474be
......@@ -262,7 +262,7 @@ ALTER IGNORE TABLE t1 ADD FOREIGN KEY (a) REFERENCES t2 (b);
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
SHOW WARNINGS;
Level Code Message
Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Referenced table `test`.`t2` not found in the data dictionary near 'FOREIGN KEY (a) REFERENCES t2 (b)'.
Warning 150 Alter table `test`.`t1` with foreign key (a) constraint failed. Referenced table `test`.`t2` not found in the data dictionary.
Error 1005 Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t1`
DROP TABLE t1;
......
......@@ -25,7 +25,16 @@ create table t2(a int, constraint a foreign key a (a) references t1(a)) engine=i
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Create table `test`.`t2` with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near ' foreign key a (a) references t1(a)) engine=innodb'.
Warning 150 Create table `test`.`t2` with foreign key `a` constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns.
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t2`
drop table t1;
create table t1(a int unique, b int) engine=innodb;
create table t2(a int, b int, foreign key (a) references t1(a), foreign key (b) references t1(b)) engine=innodb;
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Create table `test`.`t2` with foreign key (b) constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns.
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t2`
drop table t1;
......@@ -42,7 +51,7 @@ alter table t2 add constraint b foreign key (b) references t2(b);
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Alter table `test`.`t2` with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near ' foreign key (b) references t2(b)'.
Warning 150 Alter table `test`.`t2` with foreign key `b` constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns.
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t2`
drop table t2, t1;
......@@ -51,7 +60,7 @@ alter table t1 add constraint c1 foreign key (f1) references t11(f1);
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Referenced table `test`.`t11` not found in the data dictionary near ' foreign key (f1) references t11(f1)'.
Warning 150 Alter table `test`.`t1` with foreign key `c1` constraint failed. Referenced table `test`.`t11` not found in the data dictionary.
Error 1005 Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t1`
drop table t1;
......@@ -74,14 +83,14 @@ create temporary table t2(a int, foreign key(a) references t1(a)) engine=innodb;
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Create table `mysqld.1`.`t2` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary near 'foreign key(a) references t1(a)) engine=innodb'.
Warning 150 Create table `test`.`t2` with foreign key constraint failed. Temporary tables can't have foreign key constraints.
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t2`
alter table t1 add foreign key(b) references t1(a);
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Alter table `mysqld.1`.`t1` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary near 'foreign key(b) references t1(a)'.
Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Temporary tables can't have foreign key constraints.
Error 1005 Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t1`
drop table t1;
......@@ -104,14 +113,14 @@ alter table t1 add constraint c1 foreign key (f1) references t1(f1) on update se
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Alter table `test`.`t1` with foreign key constraint failed. You have defined a SET NULL condition but column 'f1' is defined as NOT NULL in ' foreign key (f1) references t1(f1) on update set null' near ' on update set null'.
Warning 150 Alter table `test`.`t1` with foreign key `c1` constraint failed. You have defined a SET NULL condition but column 'f1' is defined as NOT NULL.
Error 1005 Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t1`
create table t2(a int not null, foreign key(a) references t1(f1) on delete set null) engine=innodb;
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Create table `test`.`t2` with foreign key constraint failed. You have defined a SET NULL condition but column 'a' is defined as NOT NULL in 'foreign key(a) references t1(f1) on delete set null) engine=innodb' near ' on delete set null) engine=innodb'.
Warning 150 Create table `test`.`t2` with foreign key (a) constraint failed. You have defined a SET NULL condition but column 'a' is defined as NOT NULL.
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t2`
drop table t1;
......@@ -120,7 +129,7 @@ create table t2(a char(20), key(a), foreign key(a) references t1(f1)) engine=inn
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Create table `test`.`t2` with foreign key constraint failed. Field type or character set for column 'a' does not mach referenced column 'f1' near 'foreign key(a) references t1(f1)) engine=innodb'.
Warning 150 Create table `test`.`t2` with foreign key (a) constraint failed. Field type or character set for column 'a' does not mach referenced column 'f1'.
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t2`
drop table t1;
......@@ -52,8 +52,7 @@ CONSTRAINT fk3 FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Create table `test`.`t2` with foreign key constraint failed. Referenced table `test`.`t3` not found in the data dictionary near ' FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE
) ENGINE=InnoDB'.
Warning 150 Create table `test`.`t2` with foreign key `fk3` constraint failed. Referenced table `test`.`t3` not found in the data dictionary.
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t2`
CREATE TABLE t2 (
......@@ -67,7 +66,7 @@ ALTER TABLE t2 ADD CONSTRAINT fk3 FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Alter table `test`.`t2` with foreign key constraint failed. Referenced table `test`.`t3` not found in the data dictionary near ' FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE'.
Warning 150 Alter table `test`.`t2` with foreign key `fk3` constraint failed. Referenced table `test`.`t3` not found in the data dictionary.
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `t2`
drop table t2;
......
......@@ -15,7 +15,7 @@ CREATE TABLE t1 (
# Below create table fails because constraint name test
# is reserved for above table.
#
--error 1005
--error ER_CANT_CREATE_TABLE
CREATE TABLE t2 (
id int(11) NOT NULL PRIMARY KEY,
a int(11) NOT NULL,
......@@ -37,18 +37,24 @@ drop table t1;
# No index for referenced columns
#
create table t1(a int) engine=innodb;
--error 1005
--error ER_CANT_CREATE_TABLE
create table t2(a int, constraint a foreign key a (a) references t1(a)) engine=innodb;
show warnings;
drop table t1;
create table t1(a int unique, b int) engine=innodb;
--error ER_CANT_CREATE_TABLE
create table t2(a int, b int, foreign key (a) references t1(a), foreign key (b) references t1(b)) engine=innodb;
show warnings;
drop table t1;
create table t1(a int not null primary key, b int) engine=innodb;
--error 1005
--error ER_CANT_CREATE_TABLE
create table t2(a int, b int, constraint a foreign key a (a) references t1(a),
constraint a foreign key a (a) references t1(b)) engine=innodb;
show warnings;
create table t2(a int, b int, constraint a foreign key a (a) references t1(a)) engine=innodb;
--error 1005
--error ER_CANT_CREATE_TABLE
alter table t2 add constraint b foreign key (b) references t2(b);
show warnings;
drop table t2, t1;
......@@ -58,7 +64,7 @@ drop table t2, t1;
#
create table t1 (f1 integer primary key) engine=innodb;
--error 1005
--error ER_CANT_CREATE_TABLE
alter table t1 add constraint c1 foreign key (f1) references t11(f1);
show warnings;
drop table t1;
......@@ -83,10 +89,10 @@ create temporary table t1(a int not null primary key, b int, key(b)) engine=inno
--echo Warning 150 Alter table `mysqld.1`.`t1` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary close to foreign key(b) references t1(a).
--echo Error 1005 Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
--echo Warning 1215 Cannot add foreign key constraint
--error 1005
--error ER_CANT_CREATE_TABLE
create temporary table t2(a int, foreign key(a) references t1(a)) engine=innodb;
show warnings;
--error 1005
--error ER_CANT_CREATE_TABLE
alter table t1 add foreign key(b) references t1(a);
show warnings;
drop table t1;
......@@ -109,10 +115,10 @@ drop table t1;
# ON UPDATE/DELETE SET NULL on NOT NULL column
#
create table t1 (f1 integer not null primary key) engine=innodb;
--error 1005
--error ER_CANT_CREATE_TABLE
alter table t1 add constraint c1 foreign key (f1) references t1(f1) on update set null;
show warnings;
--error 1005
--error ER_CANT_CREATE_TABLE
create table t2(a int not null, foreign key(a) references t1(f1) on delete set null) engine=innodb;
show warnings;
drop table t1;
......@@ -121,7 +127,7 @@ drop table t1;
# Incorrect types
#
create table t1 (id int not null primary key, f1 int, f2 int, key(f1)) engine=innodb;
--error 1005
--error ER_CANT_CREATE_TABLE
create table t2(a char(20), key(a), foreign key(a) references t1(f1)) engine=innodb;
show warnings;
drop table t1;
......@@ -1524,7 +1524,7 @@ ALTER TABLE child ADD FOREIGN KEY(p) REFERENCES parent(p);
ERROR HY000: Can't create table `test`.`child` (errno: 150 "Foreign key constraint is incorrectly formed")
show warnings;
Level Code Message
Warning 150 Alter table `test`.`child` with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near 'FOREIGN KEY(p) REFERENCES parent(p)'.
Warning 150 Alter table `test`.`child` with foreign key (p) constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns.
Error 1005 Can't create table `test`.`child` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `child`
ALTER TABLE parent DROP INDEX idx1;
......@@ -1532,7 +1532,7 @@ ALTER TABLE child ADD FOREIGN KEY(p) REFERENCES parent(p);
Got one of the listed errors
show warnings;
Level Code Message
Warning 150 Alter table `test`.`child` with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near 'FOREIGN KEY(p) REFERENCES parent(p)'.
Warning 150 Alter table `test`.`child` with foreign key (p) constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns.
Error 1005 Can't create table `test`.`child` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `child`
ALTER TABLE child DROP INDEX idx2;
......@@ -1540,7 +1540,7 @@ ALTER TABLE child ADD FOREIGN KEY(p) REFERENCES parent(p);
Got one of the listed errors
show warnings;
Level Code Message
Warning 150 Alter table `test`.`child` with foreign key constraint failed. There is only prefix index in the referenced table where the referenced columns appear as the first columns near 'FOREIGN KEY(p) REFERENCES parent(p)'.
Warning 150 Alter table `test`.`child` with foreign key (p) constraint failed. There is only prefix index in the referenced table where the referenced columns appear as the first columns.
Error 1005 Can't create table `test`.`child` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint for `child`
DROP TABLE child, parent;
......
......@@ -2190,10 +2190,14 @@ struct Table_scope_and_contents_source_st:
struct HA_CREATE_INFO: public Table_scope_and_contents_source_st,
public Schema_specification_st
{
/* TODO: remove after MDEV-20865 */
Alter_info *alter_info;
void init()
{
Table_scope_and_contents_source_st::init();
Schema_specification_st::init();
alter_info= NULL;
}
bool check_conflicting_charset_declarations(CHARSET_INFO *cs);
bool add_table_option_default_charset(CHARSET_INFO *cs)
......
......@@ -394,6 +394,7 @@ bool Sql_cmd_alter_table::execute(THD *thd)
*/
HA_CREATE_INFO create_info(lex->create_info);
Alter_info alter_info(lex->alter_info, thd->mem_root);
create_info.alter_info= &alter_info;
ulong priv=0;
ulong priv_needed= ALTER_ACL;
bool result;
......
......@@ -189,6 +189,7 @@ Key::Key(const Key &rhs, MEM_ROOT *mem_root)
Foreign_key::Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root)
:Key(rhs,mem_root),
constraint_name(rhs.constraint_name),
ref_db(rhs.ref_db),
ref_table(rhs.ref_table),
ref_columns(rhs.ref_columns,mem_root),
......
......@@ -393,12 +393,14 @@ class Foreign_key: public Key {
public:
enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
FK_MATCH_PARTIAL, FK_MATCH_SIMPLE};
LEX_CSTRING constraint_name;
LEX_CSTRING ref_db;
LEX_CSTRING ref_table;
List<Key_part_spec> ref_columns;
enum enum_fk_option delete_opt, update_opt;
enum fk_match_opt match_opt;
Foreign_key(const LEX_CSTRING *name_arg, List<Key_part_spec> *cols,
const LEX_CSTRING *constraint_name_arg,
const LEX_CSTRING *ref_db_arg, const LEX_CSTRING *ref_table_arg,
List<Key_part_spec> *ref_cols,
enum_fk_option delete_opt_arg, enum_fk_option update_opt_arg,
......@@ -406,6 +408,7 @@ class Foreign_key: public Key {
DDL_options ddl_options)
:Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols, NULL,
ddl_options),
constraint_name(*constraint_name_arg),
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)
......
......@@ -4154,6 +4154,7 @@ mysql_execute_command(THD *thd)
create_info.db_type= 0;
create_info.row_type= ROW_TYPE_NOT_USED;
create_info.default_table_charset= thd->variables.collation_database;
create_info.alter_info= &alter_info;
res= mysql_alter_table(thd, &first_table->db, &first_table->table_name,
&create_info, first_table, &alter_info,
......
......@@ -5652,6 +5652,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
local_create_info.init(create_info->create_like_options());
local_create_info.db_type= src_table->table->s->db_type();
local_create_info.row_type= src_table->table->s->row_type;
local_create_info.alter_info= &local_alter_info;
if (mysql_prepare_alter_table(thd, src_table->table, &local_create_info,
&local_alter_info, &local_alter_ctx))
goto err;
......@@ -10949,6 +10950,7 @@ bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy)
bzero((char*) &create_info, sizeof(create_info));
create_info.row_type=ROW_TYPE_NOT_USED;
create_info.default_table_charset=default_charset_info;
create_info.alter_info= &alter_info;
/* Force alter table to recreate table */
alter_info.flags= (ALTER_CHANGE_COLUMN | ALTER_RECREATE);
......@@ -11228,6 +11230,13 @@ bool Sql_cmd_create_table_like::execute(THD *thd)
goto end_with_restore_list;
}
/*
Since CREATE_INFO is not full without Alter_info, it is better to pass them
as a signle parameter. TODO: remove alter_info argument where create_info is
passed.
*/
create_info.alter_info= &alter_info;
/* Check privileges */
if ((res= create_table_precheck(thd, select_tables, create_table)))
goto end_with_restore_list;
......
......@@ -5779,6 +5779,7 @@ key_def:
Key *key= (new (thd->mem_root)
Foreign_key($5.str ? &$5 : &$1,
&lex->last_key->columns,
$1.str ? &$1 : &$5,
&$10->db,
&$10->table,
&lex->ref_list,
......
......@@ -5778,6 +5778,7 @@ key_def:
Key *key= (new (thd->mem_root)
Foreign_key($5.str ? &$5 : &$1,
&lex->last_key->columns,
$1.str ? &$1 : &$5,
&$10->db,
&$10->table,
&lex->ref_list,
......
This diff is collapsed.
This diff is collapsed.
......@@ -643,6 +643,9 @@ class create_table_info_t
/** Set m_tablespace_type. */
void set_tablespace_type(bool table_being_altered_is_file_per_table);
/** Create InnoDB foreign keys from MySQL alter_info. */
dberr_t create_foreign_keys();
/** Create the internal innodb table.
@param create_fk whether to add FOREIGN KEY constraints */
int create_table(bool create_fk = true);
......
......@@ -2863,6 +2863,7 @@ innobase_get_foreign_key_info(
char* referenced_table_name = NULL;
ulint num_fk = 0;
Alter_info* alter_info = ha_alter_info->alter_info;
const CHARSET_INFO* cs = innobase_get_charset(trx->mysql_thd);
DBUG_ENTER("innobase_get_foreign_key_info");
......@@ -2880,12 +2881,6 @@ innobase_get_foreign_key_info(
ulint num_col = 0;
ulint referenced_num_col = 0;
bool correct_option;
char* db_namep = NULL;
char* tbl_namep = NULL;
ulint db_name_len = 0;
ulint tbl_name_len = 0;
char db_name[MAX_DATABASE_NAME_LEN];
char tbl_name[MAX_TABLE_NAME_LEN];
Foreign_key* fk_key = static_cast<Foreign_key*>(&key);
......@@ -2933,45 +2928,14 @@ innobase_get_foreign_key_info(
add_fk[num_fk] = dict_mem_foreign_create();
#ifndef _WIN32
if (fk_key->ref_db.str) {
tablename_to_filename(fk_key->ref_db.str, db_name,
MAX_DATABASE_NAME_LEN);
db_namep = db_name;
db_name_len = strlen(db_name);
}
if (fk_key->ref_table.str) {
tablename_to_filename(fk_key->ref_table.str, tbl_name,
MAX_TABLE_NAME_LEN);
tbl_namep = tbl_name;
tbl_name_len = strlen(tbl_name);
}
#else
ut_ad(fk_key->ref_table.str);
tablename_to_filename(fk_key->ref_table.str, tbl_name,
MAX_TABLE_NAME_LEN);
innobase_casedn_str(tbl_name);
tbl_name_len = strlen(tbl_name);
tbl_namep = &tbl_name[0];
if (fk_key->ref_db.str != NULL) {
tablename_to_filename(fk_key->ref_db.str, db_name,
MAX_DATABASE_NAME_LEN);
innobase_casedn_str(db_name);
db_name_len = strlen(db_name);
db_namep = &db_name[0];
}
#endif
mutex_enter(&dict_sys.mutex);
referenced_table_name = dict_get_referenced_table(
table->name.m_name,
db_namep,
db_name_len,
tbl_namep,
tbl_name_len,
LEX_STRING_WITH_LEN(fk_key->ref_db),
LEX_STRING_WITH_LEN(fk_key->ref_table),
&referenced_table,
add_fk[num_fk]->heap);
add_fk[num_fk]->heap, cs);
/* Test the case when referenced_table failed to
open, if trx->check_foreigns is not set, we should
......@@ -2982,7 +2946,7 @@ innobase_get_foreign_key_info(
if (!referenced_table && trx->check_foreigns) {
mutex_exit(&dict_sys.mutex);
my_error(ER_FK_CANNOT_OPEN_PARENT,
MYF(0), tbl_namep);
MYF(0), fk_key->ref_table.str);
goto err_exit;
}
......@@ -3017,7 +2981,7 @@ innobase_get_foreign_key_info(
my_error(ER_FK_NO_INDEX_PARENT, MYF(0),
fk_key->name.str
? fk_key->name.str : "",
tbl_namep);
fk_key->ref_table.str);
goto err_exit;
}
} else {
......@@ -3029,7 +2993,8 @@ innobase_get_foreign_key_info(
/* Not possible to add a foreign key without a
referenced column */
mutex_exit(&dict_sys.mutex);
my_error(ER_CANNOT_ADD_FOREIGN, MYF(0), tbl_namep);
my_error(ER_CANNOT_ADD_FOREIGN, MYF(0),
fk_key->ref_table.str);
goto err_exit;
}
......
......@@ -62,7 +62,8 @@ dict_get_referenced_table(
const char* table_name, /*!< in: table name */
ulint table_name_len, /*!< in: table name length */
dict_table_t** table, /*!< out: table object or NULL */
mem_heap_t* heap); /*!< in: heap memory */
mem_heap_t* heap, /*!< in: heap memory */
CHARSET_INFO* from_cs); /*!< in: table name charset */
/*********************************************************************//**
Frees a foreign key struct. */
void
......@@ -79,6 +80,21 @@ dict_table_get_highest_foreign_id(
/*==============================*/
dict_table_t* table); /*!< in: table in the dictionary
memory cache */
/** Check whether the dict_table_t is a partition.
A partitioned table on the SQL level is composed of InnoDB tables,
where each InnoDB table is a [sub]partition including its secondary indexes
which belongs to the partition.
@param[in] table Table to check.
@return true if the dict_table_t is a partition else false. */
UNIV_INLINE
bool
dict_table_is_partition(const dict_table_t* table)
{
/* Check both P and p on all platforms in case it was moved to/from
WIN. */
return (strstr(table->name.m_name, "#p#")
|| strstr(table->name.m_name, "#P#"));
}
/********************************************************************//**
Return the end of table name where we have removed dbname and '/'.
@return table name */
......@@ -421,34 +437,6 @@ dict_foreign_replace_index(
to use table->col_names */
const dict_index_t* index) /*!< in: index to be replaced */
MY_ATTRIBUTE((nonnull(1,3), warn_unused_result));
/** Scans a table create SQL string and adds to the data dictionary
the foreign key constraints declared in the string. This function
should be called after the indexes for a table have been created.
Each foreign key constraint must be accompanied with indexes in
bot participating tables. The indexes are allowed to contain more
fields than mentioned in the constraint.
@param[in] trx transaction
@param[in] sql_string table create statement where
foreign keys are declared like:
FOREIGN KEY (a, b) REFERENCES table2(c, d),
table2 can be written also with the database
name before it: test.table2; the default
database id the database of parameter name
@param[in] sql_length length of sql_string
@param[in] name table full name in normalized form
@param[in] reject_fks if TRUE, fail with error code
DB_CANNOT_ADD_CONSTRAINT if any
foreign keys are found.
@return error code or DB_SUCCESS */
dberr_t
dict_create_foreign_constraints(
trx_t* trx,
const char* sql_string,
size_t sql_length,
const char* name,
ibool reject_fks)
MY_ATTRIBUTE((warn_unused_result));
/**********************************************************************//**
Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement.
@return DB_SUCCESS or DB_CANNOT_DROP_CONSTRAINT if syntax error or the
......
......@@ -518,6 +518,17 @@ ib_push_warning(
const char *format,/*!< in: warning message */
...);
/********************************************************************//**
Helper function to push warnings from InnoDB internals to SQL-layer. */
UNIV_INTERN
void
ib_foreign_warn(
trx_t* trx, /*!< in: trx */
dberr_t error, /*!< in: error code to push as warning */
const char *table_name,
const char *format,/*!< in: warning message */
...);
/*****************************************************************//**
Normalizes a table name string. A normalized name consists of the
database name catenated to '/' and table name. An example:
......
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