diff options
author | Nikita Malyavin <nikitamalyavin@gmail.com> | 2021-03-03 00:16:27 +0300 |
---|---|---|
committer | Nikita Malyavin <nikitamalyavin@gmail.com> | 2021-03-10 17:46:19 +0300 |
commit | e0c940aa565c6d8527f33162061d76b156eb2c6e (patch) | |
tree | 562b80391aedae12171954e21058a72c6e83ed3d | |
parent | dcf0333f7fea1d35e0e9f68fe26a0259a2890b35 (diff) | |
download | mariadb-git-fk_in_progress.tar.gz |
Add referenced table to prelocking list during CREATE TABLE with FKfk_in_progress
-rw-r--r-- | mysql-test/main/func_regexp_pcre.result | 20 | ||||
-rw-r--r-- | mysql-test/main/partition.result | 2 | ||||
-rw-r--r-- | mysql-test/main/partition.test | 4 | ||||
-rw-r--r-- | mysql-test/main/union.result | 2 | ||||
-rw-r--r-- | mysql-test/main/union.test | 2 | ||||
-rw-r--r-- | mysql-test/suite/gcol/inc/gcol_keys.inc | 12 | ||||
-rw-r--r-- | mysql-test/suite/gcol/r/gcol_keys_innodb.result | 12 | ||||
-rw-r--r-- | mysql-test/suite/gcol/r/gcol_keys_myisam.result | 12 | ||||
-rw-r--r-- | mysql-test/suite/innodb/r/foreign_key.result | 1 | ||||
-rw-r--r-- | mysql-test/suite/innodb/r/innodb-fk-warnings.result | 1 | ||||
-rw-r--r-- | mysql-test/suite/innodb/r/innodb-fk.result | 3 | ||||
-rw-r--r-- | mysql-test/suite/vcol/inc/vcol_keys.inc | 12 | ||||
-rw-r--r-- | mysql-test/suite/vcol/r/vcol_keys_innodb.result | 12 | ||||
-rw-r--r-- | mysql-test/suite/vcol/r/vcol_keys_myisam.result | 12 | ||||
-rw-r--r-- | sql/lock.cc | 6 | ||||
-rw-r--r-- | sql/sql_class.cc | 4 | ||||
-rw-r--r-- | sql/sql_class.h | 11 | ||||
-rw-r--r-- | sql/sql_lex.cc | 35 | ||||
-rw-r--r-- | sql/sql_lex.h | 7 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 7 |
20 files changed, 118 insertions, 59 deletions
diff --git a/mysql-test/main/func_regexp_pcre.result b/mysql-test/main/func_regexp_pcre.result index 3b0688fc70e..771e22b3155 100644 --- a/mysql-test/main/func_regexp_pcre.result +++ b/mysql-test/main/func_regexp_pcre.result @@ -526,31 +526,35 @@ c b SELECT REGEXP_REPLACE('a\rb','(*LF)(?m)^a$','c'); REGEXP_REPLACE('a\rb','(*LF)(?m)^a$','c') -a
b +a +b SELECT REGEXP_REPLACE('a\rb','(*CR)(?m)^a$','c'); REGEXP_REPLACE('a\rb','(*CR)(?m)^a$','c') -c
b +c +b SELECT REGEXP_REPLACE('a\rb','(*CRLF)(?m)^a$','c'); REGEXP_REPLACE('a\rb','(*CRLF)(?m)^a$','c') -a
b +a +b SELECT REGEXP_REPLACE('a\rb','(*ANYCRLF)(?m)^a$','c'); REGEXP_REPLACE('a\rb','(*ANYCRLF)(?m)^a$','c') -c
b +c +b SELECT REGEXP_REPLACE('a\r\nb','(*LF)(?m)^a$','c'); REGEXP_REPLACE('a\r\nb','(*LF)(?m)^a$','c') -a
+a b SELECT REGEXP_REPLACE('a\r\nb','(*CR)(?m)^a$','c'); REGEXP_REPLACE('a\r\nb','(*CR)(?m)^a$','c') -c
+c b SELECT REGEXP_REPLACE('a\r\nb','(*CRLF)(?m)^a$','c'); REGEXP_REPLACE('a\r\nb','(*CRLF)(?m)^a$','c') -c
+c b SELECT REGEXP_REPLACE('a\r\nb','(*ANYCRLF)(?m)^a$','c'); REGEXP_REPLACE('a\r\nb','(*ANYCRLF)(?m)^a$','c') -c
+c b SELECT REGEXP_REPLACE('aa','(a)\\g1','b'); REGEXP_REPLACE('aa','(a)\\g1','b') diff --git a/mysql-test/main/partition.result b/mysql-test/main/partition.result index 373522ded40..a3c88fed373 100644 --- a/mysql-test/main/partition.result +++ b/mysql-test/main/partition.result @@ -303,10 +303,12 @@ create index i2 on t1 (a); Warnings: Note 1831 Duplicate index `i2`. This is deprecated and will be disallowed in a future release drop table t1; +CREATE TABLE t0(a int); CREATE TABLE t1 (a INT, FOREIGN KEY (a) REFERENCES t0 (a)) ENGINE=MyISAM PARTITION BY HASH (a); ERROR HY000: Partitioned tables do not support FOREIGN KEY +DROP TABLE t0; CREATE TABLE t1 ( pk INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (pk) diff --git a/mysql-test/main/partition.test b/mysql-test/main/partition.test index 81752982959..c171c71c0ed 100644 --- a/mysql-test/main/partition.test +++ b/mysql-test/main/partition.test @@ -290,10 +290,12 @@ drop table t1; # # Bug#36001: Partitions: spelling and using some error messages # ---error ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING +CREATE TABLE t0(a int); +--error ER_FOREIGN_KEY_ON_PARTITIONED CREATE TABLE t1 (a INT, FOREIGN KEY (a) REFERENCES t0 (a)) ENGINE=MyISAM PARTITION BY HASH (a); +DROP TABLE t0; # # Bug#40954: Crash if range search and order by. diff --git a/mysql-test/main/union.result b/mysql-test/main/union.result index 293c9f54651..25c2834c513 100644 --- a/mysql-test/main/union.result +++ b/mysql-test/main/union.result @@ -581,7 +581,7 @@ insert into users values (1); insert into groups values (1); create table t1 ( id int not null auto_increment, primary key (id) ,user_name text ); create table t2 ( id int not null auto_increment, primary key (id) ,group_name text ); -create table t3 ( id int not null auto_increment, primary key (id) ,user_id int ,index user_idx (user_id) ,foreign key (user_id) references users(id) ,group_id int ,index group_idx (group_id) ,foreign key (group_id) references groups(id) ); +create table t3 ( id int not null auto_increment, primary key (id) ,user_id int ,index user_idx (user_id) ,foreign key (user_id) references t1(id) ,group_id int ,index group_idx (group_id) ,foreign key (group_id) references t2(id) ); insert into t1 (user_name) values ('Tester'); insert into t2 (group_name) values ('Group A'); insert into t2 (group_name) values ('Group B'); diff --git a/mysql-test/main/union.test b/mysql-test/main/union.test index 62e5c978602..5a6f37394d6 100644 --- a/mysql-test/main/union.test +++ b/mysql-test/main/union.test @@ -353,7 +353,7 @@ insert into users values (1); insert into groups values (1); create table t1 ( id int not null auto_increment, primary key (id) ,user_name text ); create table t2 ( id int not null auto_increment, primary key (id) ,group_name text ); -create table t3 ( id int not null auto_increment, primary key (id) ,user_id int ,index user_idx (user_id) ,foreign key (user_id) references users(id) ,group_id int ,index group_idx (group_id) ,foreign key (group_id) references groups(id) ); +create table t3 ( id int not null auto_increment, primary key (id) ,user_id int ,index user_idx (user_id) ,foreign key (user_id) references t1(id) ,group_id int ,index group_idx (group_id) ,foreign key (group_id) references t2(id) ); insert into t1 (user_name) values ('Tester'); insert into t2 (group_name) values ('Group A'); insert into t2 (group_name) values ('Group B'); diff --git a/mysql-test/suite/gcol/inc/gcol_keys.inc b/mysql-test/suite/gcol/inc/gcol_keys.inc index e59b368c261..f382dd8e1c4 100644 --- a/mysql-test/suite/gcol/inc/gcol_keys.inc +++ b/mysql-test/suite/gcol/inc/gcol_keys.inc @@ -130,22 +130,22 @@ if (!$skip_spatial_index_check) --echo # FOREIGN KEY --echo # Rejected FK options. ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update set null); ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update cascade); ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on delete set null); create table t1 (a int, b int generated always as (a+1) stored); ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE alter table t1 add foreign key (b) references t2(a) on update set null; ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE alter table t1 add foreign key (b) references t2(a) on update cascade; ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE alter table t1 add foreign key (b) references t2(a) on delete set null; drop table t1; diff --git a/mysql-test/suite/gcol/r/gcol_keys_innodb.result b/mysql-test/suite/gcol/r/gcol_keys_innodb.result index de3d82172dc..1912cea75e1 100644 --- a/mysql-test/suite/gcol/r/gcol_keys_innodb.result +++ b/mysql-test/suite/gcol/r/gcol_keys_innodb.result @@ -133,20 +133,20 @@ drop table t1; # Rejected FK options. create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update set null); -ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update cascade); -ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on delete set null); -ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int generated always as (a+1) stored); alter table t1 add foreign key (b) references t2(a) on update set null; -ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist alter table t1 add foreign key (b) references t2(a) on update cascade; -ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist alter table t1 add foreign key (b) references t2(a) on delete set null; -ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist drop table t1; create table t1 (a int, b int generated always as (a+1) virtual, foreign key (b) references t2(a)); diff --git a/mysql-test/suite/gcol/r/gcol_keys_myisam.result b/mysql-test/suite/gcol/r/gcol_keys_myisam.result index 3f00d344901..cf0281f5d1e 100644 --- a/mysql-test/suite/gcol/r/gcol_keys_myisam.result +++ b/mysql-test/suite/gcol/r/gcol_keys_myisam.result @@ -140,20 +140,20 @@ drop table t1; # Rejected FK options. create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update set null); -ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update cascade); -ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on delete set null); -ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int generated always as (a+1) stored); alter table t1 add foreign key (b) references t2(a) on update set null; -ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist alter table t1 add foreign key (b) references t2(a) on update cascade; -ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist alter table t1 add foreign key (b) references t2(a) on delete set null; -ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist drop table t1; # Allowed FK options. create table t2 (a int primary key, b char(5)); diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index 6c31d354e12..4ea8d5b9b82 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -256,6 +256,7 @@ ALTER IGNORE TABLE t1 ADD FOREIGN KEY (a) REFERENCES t2 (b); ERROR 42S02: Table 'test.t2' doesn't exist SHOW WARNINGS; Level Code Message +Error 1146 Table 'test.t2' doesn't exist DROP TABLE t1; # # MDEV-18139 ALTER IGNORE ... ADD FOREIGN KEY causes bogus error diff --git a/mysql-test/suite/innodb/r/innodb-fk-warnings.result b/mysql-test/suite/innodb/r/innodb-fk-warnings.result index ab200522443..af718da33a7 100644 --- a/mysql-test/suite/innodb/r/innodb-fk-warnings.result +++ b/mysql-test/suite/innodb/r/innodb-fk-warnings.result @@ -35,6 +35,7 @@ alter table t1 add constraint c1 foreign key (f1) references t11(f1); ERROR 42S02: Table 'test.t11' doesn't exist show warnings; Level Code Message +Error 1146 Table 'test.t11' doesn't exist drop table t1; create temporary table t1(a int not null primary key, b int, key(b)) engine=innodb; create temporary table t2(a int, foreign key(a) references t1(a)) engine=innodb; diff --git a/mysql-test/suite/innodb/r/innodb-fk.result b/mysql-test/suite/innodb/r/innodb-fk.result index 1a8bc42b408..a2b92aa7b78 100644 --- a/mysql-test/suite/innodb/r/innodb-fk.result +++ b/mysql-test/suite/innodb/r/innodb-fk.result @@ -52,7 +52,7 @@ CONSTRAINT fk3 FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE ERROR 42S02: Table 'test.t3' doesn't exist show warnings; Level Code Message -Error 1239 Incorrect foreign key definition for 't3': referenced table not found +Error 1146 Table 'test.t3' doesn't exist CREATE TABLE t2 ( id int(11) NOT NULL AUTO_INCREMENT, f2 int(11) NOT NULL, @@ -64,6 +64,7 @@ ALTER TABLE t2 ADD CONSTRAINT fk3 FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE ERROR 42S02: Table 'test.t3' doesn't exist show warnings; Level Code Message +Error 1146 Table 'test.t3' doesn't exist drop table t2; drop table t1; CREATE DATABASE kg_test1; diff --git a/mysql-test/suite/vcol/inc/vcol_keys.inc b/mysql-test/suite/vcol/inc/vcol_keys.inc index 7031f784506..6a78bc7dd3b 100644 --- a/mysql-test/suite/vcol/inc/vcol_keys.inc +++ b/mysql-test/suite/vcol/inc/vcol_keys.inc @@ -103,22 +103,22 @@ if (!$skip_spatial_index_check) --echo # FOREIGN KEY --echo # Rejected FK options. ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE create table t1 (a int, b int as (a+1) persistent, foreign key (b) references t2(a) on update set null); ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE create table t1 (a int, b int as (a+1) persistent, foreign key (b) references t2(a) on update cascade); ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE create table t1 (a int, b int as (a+1) persistent, foreign key (b) references t2(a) on delete set null); create table t1 (a int, b int as (a+1) persistent); ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE alter table t1 add foreign key (b) references t2(a) on update set null; ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE alter table t1 add foreign key (b) references t2(a) on update cascade; ---error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN +--error ER_NO_SUCH_TABLE alter table t1 add foreign key (b) references t2(a) on delete set null; drop table t1; diff --git a/mysql-test/suite/vcol/r/vcol_keys_innodb.result b/mysql-test/suite/vcol/r/vcol_keys_innodb.result index 25c6ace9d0f..86b22965f5c 100644 --- a/mysql-test/suite/vcol/r/vcol_keys_innodb.result +++ b/mysql-test/suite/vcol/r/vcol_keys_innodb.result @@ -107,20 +107,20 @@ drop table t1; # Rejected FK options. create table t1 (a int, b int as (a+1) persistent, foreign key (b) references t2(a) on update set null); -ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int as (a+1) persistent, foreign key (b) references t2(a) on update cascade); -ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int as (a+1) persistent, foreign key (b) references t2(a) on delete set null); -ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int as (a+1) persistent); alter table t1 add foreign key (b) references t2(a) on update set null; -ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist alter table t1 add foreign key (b) references t2(a) on update cascade; -ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist alter table t1 add foreign key (b) references t2(a) on delete set null; -ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist drop table t1; create table t1 (a int, b int as (a+1), foreign key (b) references t2(a)); ERROR 42S02: Table 'test.t2' doesn't exist diff --git a/mysql-test/suite/vcol/r/vcol_keys_myisam.result b/mysql-test/suite/vcol/r/vcol_keys_myisam.result index 1e6c854e0d9..fdb8325e5af 100644 --- a/mysql-test/suite/vcol/r/vcol_keys_myisam.result +++ b/mysql-test/suite/vcol/r/vcol_keys_myisam.result @@ -107,20 +107,20 @@ drop table t1; # Rejected FK options. create table t1 (a int, b int as (a+1) persistent, foreign key (b) references t2(a) on update set null); -ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int as (a+1) persistent, foreign key (b) references t2(a) on update cascade); -ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int as (a+1) persistent, foreign key (b) references t2(a) on delete set null); -ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist create table t1 (a int, b int as (a+1) persistent); alter table t1 add foreign key (b) references t2(a) on update set null; -ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist alter table t1 add foreign key (b) references t2(a) on update cascade; -ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist alter table t1 add foreign key (b) references t2(a) on delete set null; -ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column +ERROR 42S02: Table 'test.t2' doesn't exist drop table t1; # Allowed FK options. create table t2 (a int primary key, b char(5)); diff --git a/sql/lock.cc b/sql/lock.cc index ebe6f325e65..3df1eb0f516 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -148,11 +148,11 @@ lock_tables_check(THD *thd, TABLE **tables, uint count, uint flags) } } + if (t->s->table_category == TABLE_CATEGORY_SYSTEM) + system_count++; + if (t->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE) { - if (t->s->table_category == TABLE_CATEGORY_SYSTEM) - system_count++; - if (t->db_stat & HA_READ_ONLY) { my_error(ER_OPEN_AS_READONLY, MYF(0), t->alias.c_ptr_safe()); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 3ff2e2c10ca..f3f6d10b706 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -195,18 +195,20 @@ Foreign_key::Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root) constraint_name(rhs.constraint_name), ref_db(rhs.ref_db), ref_table(rhs.ref_table), + ref_table_list(rhs.ref_table_list), ref_columns(rhs.ref_columns,mem_root), fk_options(rhs.fk_options) { list_copy_and_replace_each_value(ref_columns, mem_root); } - void Foreign_key::init(const LEX_CSTRING& _ref_db, const LEX_CSTRING& _ref_table, + TABLE_LIST *_ref_table_list, st_fk_options _fk_options) { ref_db= _ref_db; ref_table= _ref_table; + ref_table_list= _ref_table_list; if (ref_columns.is_empty()) { ref_columns= columns; diff --git a/sql/sql_class.h b/sql/sql_class.h index 1979e85c31c..57e464c4d67 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -705,6 +705,7 @@ public: LEX_CSTRING constraint_name; LEX_CSTRING ref_db; LEX_CSTRING ref_table; + TABLE_LIST *ref_table_list; List<Key_part_spec> ref_columns; st_fk_options fk_options; Foreign_key(const LEX_CSTRING *name_arg, @@ -744,7 +745,7 @@ public: return !foreign; } void init(const LEX_CSTRING& _ref_db, const LEX_CSTRING& _ref_table, - st_fk_options _fk_options); + TABLE_LIST *_ref_table_list, st_fk_options _fk_options); Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root); /** Used to make a clone of this object for ALTER/CREATE TABLE @@ -1658,8 +1659,8 @@ public: class Server_side_cursor; /* - Struct to catch changes in column metadata that is sent to client. - in the "result set metadata". Used to support + Struct to catch changes in column metadata that is sent to client. + in the "result set metadata". Used to support MARIADB_CLIENT_CACHE_METADATA. */ struct send_column_info_state @@ -1672,7 +1673,7 @@ struct send_column_info_state /* Column info can only be changed by PreparedStatement::reprepare() - + There is a class of "weird" prepared statements like SELECT ? or SELECT @a that are not immutable, and depend on input parameters or user variables */ @@ -1779,7 +1780,7 @@ public: LEX_CSTRING db; send_column_info_state column_info_state; - + /* This is set to 1 of last call to send_result_to_client() was ok */ my_bool query_cache_is_applicable; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 4081a4e0c3c..2415e0287e5 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -11447,6 +11447,41 @@ bool LEX::add_column_foreign_key(const LEX_CSTRING &field_name, return false; } +bool LEX::init_last_foreign_key(Table_ident *ref_table_name) +{ + if (ref_table_name->db.str == NULL) + ref_table_name->db= query_tables->db; + + Table_ident lookup_ref_name(ref_table_name->db, ref_table_name->table); + if (lower_case_table_names) + lookup_ref_name.lowercase(thd->mem_root); + + if (ref_table_name->db.str == NULL) + copy_db_to(&ref_table_name->db); + TABLE_LIST *ref_table= find_table_in_list(query_tables, + &TABLE_LIST::next_global, + &lookup_ref_name.db, + &lookup_ref_name.table); + + if (ref_table == NULL && + !(thd->variables.option_bits & OPTION_NO_FOREIGN_KEY_CHECKS)) + { + ref_table= (TABLE_LIST *) thd->alloc(sizeof(TABLE_LIST)); + if (unlikely(ref_table == NULL)) + return true; + ref_table->init_one_table_for_prelocking(&lookup_ref_name.db, + &lookup_ref_name.table, + NULL, TL_READ, + TABLE_LIST::PRELOCK_NONE, + 0, 0, + &query_tables_last, + false); + } + last_foreign_key->init(ref_table_name->db, ref_table_name->table, ref_table, + fk_options); + return false; +} + bool LEX::stmt_grant_table(THD *thd, Grant_privilege *grant, diff --git a/sql/sql_lex.h b/sql/sql_lex.h index d16af3fb51a..aedc7c5a66a 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -4709,6 +4709,7 @@ public: bool add_column_foreign_key(const LEX_CSTRING &name, const LEX_CSTRING &constraint_name, DDL_options ddl_options); + bool init_last_foreign_key(Table_ident *ref_table_name); }; @@ -5046,6 +5047,12 @@ bool sp_create_assignment_instr(THD *thd, bool no_lookahead, bool need_set_keyword= true); void mark_or_conds_to_avoid_pushdown(Item *cond); +TABLE_LIST *find_table_in_list(TABLE_LIST *table, + TABLE_LIST *TABLE_LIST::*link, + const LEX_CSTRING *db_name, + const LEX_CSTRING *table_name); +int add_foreign_key_to_list(LEX *lex, LEX_CSTRING *name, Table_ident *table_name, + DDL_options ddl_options); #endif /* MYSQL_SERVER */ #endif /* SQL_LEX_INCLUDED */ diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 06875a38dc5..b6e34234217 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -5858,7 +5858,9 @@ column_def: } references { - Lex->last_foreign_key->init($4->db, $4->table, Lex->fk_options); + + if (unlikely(Lex->init_last_foreign_key($4))) + MYSQL_YYABORT; $$= $1; } ; @@ -5921,7 +5923,8 @@ key_def: } '(' key_list ')' references { - Lex->last_foreign_key->init($10->db, $10->table, Lex->fk_options); + if (unlikely(Lex->init_last_foreign_key($10))) + MYSQL_YYABORT; } ; |