summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2023-03-05 13:21:02 +0300
committerAleksey Midenkov <midenok@gmail.com>2023-03-26 22:23:21 +0300
commitb4844f2138fc8702fc0a7e53b619815c423e0fa0 (patch)
tree6325bbfebc68d592541fe1f51483694a133e88b0
parent62bd5446a92b26e9385adac433e50720b7400221 (diff)
downloadmariadb-git-b4844f2138fc8702fc0a7e53b619815c423e0fa0.tar.gz
-rw-r--r--mysql-test/main/foreign_key.result49
-rw-r--r--mysql-test/main/foreign_key.test45
-rw-r--r--sql/datadict.cc8
-rw-r--r--sql/datadict.h2
-rw-r--r--sql/sql_table.h1
5 files changed, 73 insertions, 32 deletions
diff --git a/mysql-test/main/foreign_key.result b/mysql-test/main/foreign_key.result
index 355cccfac49..7250cde8e0d 100644
--- a/mysql-test/main/foreign_key.result
+++ b/mysql-test/main/foreign_key.result
@@ -157,25 +157,25 @@ test.t1 check status OK
test.t2 check Note Found 1 foreign keys
test.t2 check status OK
drop table t2, t1;
-create database D;
-create table D.T1(id int primary key);
-create table t2(id int primary key, f1 int references D.T1(id));
-select * from D.T1;
+create database Test_MariaDB;
+create table Test_MariaDB.T1(id int primary key);
+create table t2(id int primary key, f1 int references Test_MariaDB.T1(id));
+select * from Test_MariaDB.T1;
id
-check table D.T1;
+check table Test_MariaDB.T1;
Table Op Msg_type Msg_text
-D.T1 check Note Found 1 referenced keys
-D.T1 check status OK
+Test_MariaDB.T1 check Note Found 1 referenced keys
+Test_MariaDB.T1 check status OK
drop table t2;
-check table D.T1;
+check table Test_MariaDB.T1;
Table Op Msg_type Msg_text
-D.T1 check status OK
+Test_MariaDB.T1 check status OK
flush tables;
-check table D.T1;
+check table Test_MariaDB.T1;
Table Op Msg_type Msg_text
-D.T1 check status OK
-drop table D.T1;
-drop database D;
+Test_MariaDB.T1 check status OK
+drop table Test_MariaDB.T1;
+drop database Test_MariaDB;
# Check rename column, lock tables
create or replace table t1 (id int primary key);
create or replace table t2 (id int primary key);
@@ -449,13 +449,31 @@ create or replace table t1 (id int primary key);
select * from t1;
id
create or replace database test2;
+create or replace database test3;
+create or replace database test4;
use test2;
create or replace table ch1 (
id int, id2 int,
foreign key (id) references test.t1 (id));
select * from ch1;
id id2
+use test3;
+create or replace table par2 (
+id int primary key);
+use test4;
+create or replace table par3 (
+id int primary key);
+create or replace table ch3 (
+id int, id2 int,
+foreign key (id) references par3 (id));
+select * from par3;
+id
+select * from ch3;
+id id2
use test;
+create or replace table ch2 (
+id int, id2 int,
+foreign key (id) references test3.par2 (id));
drop database test2;
check tables t1;
Table Op Msg_type Msg_text
@@ -465,6 +483,11 @@ check tables t1;
Table Op Msg_type Msg_text
test.t1 check status OK
drop tables t1;
+drop database test3;
+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (ch2_ibfk_1)
+drop table ch2;
+drop database test3;
+drop database test4;
# Check add foreign key
create or replace table t1(fld1 int not null primary key);
create or replace table t2(fld1 int not null, fld2 int as (fld1) virtual);
diff --git a/mysql-test/main/foreign_key.test b/mysql-test/main/foreign_key.test
index 29e9faa49be..174160b6655 100644
--- a/mysql-test/main/foreign_key.test
+++ b/mysql-test/main/foreign_key.test
@@ -175,20 +175,20 @@ flush tables;
check tables t1, t2;
drop table t2, t1;
-create database D;
-create table D.T1(id int primary key);
-create table t2(id int primary key, f1 int references D.T1(id));
-select * from D.T1;
---replace_result d.t1 D.T1
-check table D.T1;
+create database Test_MariaDB;
+create table Test_MariaDB.T1(id int primary key);
+create table t2(id int primary key, f1 int references Test_MariaDB.T1(id));
+select * from Test_MariaDB.T1;
+--replace_result test_mariadb.t1 Test_MariaDB.T1
+check table Test_MariaDB.T1;
drop table t2;
---replace_result d.t1 D.T1
-check table D.T1;
+--replace_result test_mariadb.t1 Test_MariaDB.T1
+check table Test_MariaDB.T1;
flush tables;
---replace_result d.t1 D.T1
-check table D.T1;
-drop table D.T1;
-drop database D;
+--replace_result test_mariadb.t1 Test_MariaDB.T1
+check table Test_MariaDB.T1;
+drop table Test_MariaDB.T1;
+drop database Test_MariaDB;
--echo # Check rename column, lock tables
create or replace table t1 (id int primary key);
@@ -312,17 +312,38 @@ drop tables ch1, t1;
create or replace table t1 (id int primary key);
select * from t1;
create or replace database test2;
+create or replace database test3;
+create or replace database test4;
use test2;
create or replace table ch1 (
id int, id2 int,
foreign key (id) references test.t1 (id));
select * from ch1;
+use test3;
+create or replace table par2 (
+ id int primary key);
+use test4;
+create or replace table par3 (
+ id int primary key);
+create or replace table ch3 (
+ id int, id2 int,
+ foreign key (id) references par3 (id));
+select * from par3;
+select * from ch3;
use test;
+create or replace table ch2 (
+ id int, id2 int,
+ foreign key (id) references test3.par2 (id));
drop database test2;
check tables t1;
flush tables t1;
check tables t1;
drop tables t1;
+--error ER_ROW_IS_REFERENCED_2
+drop database test3;
+drop table ch2;
+drop database test3;
+drop database test4;
--echo # Check add foreign key
create or replace table t1(fld1 int not null primary key);
diff --git a/sql/datadict.cc b/sql/datadict.cc
index 2f96957ad16..1410ad6bca6 100644
--- a/sql/datadict.cc
+++ b/sql/datadict.cc
@@ -360,9 +360,8 @@ bool Extra2_info::read(const uchar *frm_image, size_t frm_size)
uchar *
-Extra2_info::write(uchar *frm_image, size_t frm_size)
+Extra2_info::write(uchar *frm_image)
{
- // FIXME: what to do with frm_size here (and in read())?
uchar *pos;
/* write the extra2 segment */
pos = frm_image + FRM_HEADER_SIZE;
@@ -405,9 +404,6 @@ Extra2_info::write(uchar *frm_image, size_t frm_size)
DBUG_ASSERT(write_size == store_size());
DBUG_ASSERT(write_size <= 0xffff - FRM_HEADER_SIZE - 4);
-#if 0
- int4store(pos, filepos); // end of the extra2 segment
-#endif
return pos;
}
@@ -496,7 +492,7 @@ frm_err:
memcpy((void *)frm_dst, (void *)frm_src, FRM_HEADER_SIZE);
- if (!(pos= extra2.write(frm_dst, frm_size)))
+ if (!(pos= extra2.write(frm_dst)))
{
my_printf_error(ER_CANT_CREATE_TABLE,
"Cannot create table %`s: "
diff --git a/sql/datadict.h b/sql/datadict.h
index 666763ffd58..9c92255aaac 100644
--- a/sql/datadict.h
+++ b/sql/datadict.h
@@ -211,7 +211,7 @@ struct Extra2_info
}
bool read(const uchar* frm_image, size_t frm_size);
- uchar * write(uchar* frm_image, size_t frm_size);
+ uchar * write(uchar* frm_image);
};
class Table_name;
diff --git a/sql/sql_table.h b/sql/sql_table.h
index a9b19385a1c..84c78f07dd4 100644
--- a/sql/sql_table.h
+++ b/sql/sql_table.h
@@ -58,6 +58,7 @@ enum enum_explain_filename_mode
/* depends on errmsg.txt Database `db`, Table `t` ... */
#define EXPLAIN_FILENAME_MAX_EXTRA_LENGTH 63
+/* Shadow FRM is new FRM file that replaces the old one */
#define WFRM_WRITE_SHADOW 1
#define WFRM_INSTALL_SHADOW 2
#define WFRM_KEEP_SHARE 4