Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't exchange partition for table create fk then drop fk #51762

Closed
ywqzzy opened this issue Mar 14, 2024 · 2 comments · Fixed by #51808
Closed

can't exchange partition for table create fk then drop fk #51762

ywqzzy opened this issue Mar 14, 2024 · 2 comments · Fixed by #51808
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 affects-7.5 component/ddl This issue is related to DDL of TiDB. component/tablepartition This issue is related to Table Partition of TiDB. severity/major type/bug This issue is a bug.

Comments

@ywqzzy
Copy link
Contributor

ywqzzy commented Mar 14, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table pt36 (id int not null primary key auto_increment,t_id int not null) partition by hash(id) partitions 1;
create table nt36 (id int not null primary key auto_increment, t_id int not null,foreign key fk_id (t_id) references pt36(id));
ALTER TABLE nt36 DROP FOREIGN KEY fk_id;
alter table pt36 exchange partition p0 with table nt36;

2. What did you expect to see? (Required)

Success

3. What did you see instead (Required)

mysql> use test
Database changed
mysql> create table pt36 (id int not null primary key auto_increment,t_id int not null) partition by hash(id) partitions 1;
create table nt36 (id int not null primary key auto_increment, t_id int not null,foreign key fk_id (t_id) references pt36(id));
ALTER TABLE nt36 DROP FOREIGN KEY fk_id;
alter table pt36 exchange partition p0 with table nt36;Query OK, 0 rows affected (0.17 sec)

mysql> create table nt36 (id int not null primary key auto_increment, t_id int not null,foreign key fk_id (t_id) references pt36(id));
Query OK, 0 rows affected (0.45 sec)

mysql> ALTER TABLE nt36 DROP FOREIGN KEY fk_id;
Query OK, 0 rows affected (0.34 sec)

mysql> alter table pt36 exchange partition p0 with table nt36;
ERROR 1740 (HY000): Table to exchange with partition has foreign key references: 'nt36'

4. What is your TiDB version? (Required)

v6.5.5

@ywqzzy ywqzzy added component/ddl This issue is related to DDL of TiDB. component/tablepartition This issue is related to Table Partition of TiDB. and removed may-affects-7.1 may-affects-7.5 labels Mar 14, 2024
@jebter
Copy link

jebter commented Mar 15, 2024

TiDB [email protected]:test> create table pt36 (id int not null primary key auto_increment,t_id int not null) partition by hash(id) partitions 1; -> create table nt36 (id int not null primary key auto_increment, t_id int not null,foreign key fk_id (t_id) references pt36(id)); -> ALTER TABLE nt36 DROP FOREIGN KEY fk_id; -> alter table pt36 exchange partition p0 with table nt36; You're about to run a destructive command. Do you want to proceed? (y/n): y Your call! Query OK, 0 rows affected Time: 0.137s (1506, 'Foreign key clause is not yet supported in conjunction with partitioning') TiDB [email protected]:test> select tidb_version() \G ***************************[ 1. row ]*************************** tidb_version() | Release Version: v7.6.0 Edition: Community Git Commit Hash: 42960c3352d165810c79852b85ada448a68efa4c Git Branch: heads/refs/tags/v7.6.0 UTC Build Time: 2024-01-15 11:27:07 GoVersion: go1.21.5

@ywqzzy
Copy link
Contributor Author

ywqzzy commented Mar 15, 2024

TiDB [email protected]:test> create table pt36 (id int not null primary key auto_increment,t_id int not null) partition by hash(id) partitions 1; -> create table nt36 (id int not null primary key auto_increment, t_id int not null,foreign key fk_id (t_id) references pt36(id)); -> ALTER TABLE nt36 DROP FOREIGN KEY fk_id; -> alter table pt36 exchange partition p0 with table nt36; You're about to run a destructive command. Do you want to proceed? (y/n): y Your call! Query OK, 0 rows affected Time: 0.137s (1506, 'Foreign key clause is not yet supported in conjunction with partitioning') TiDB [email protected]:test> select tidb_version() \G ***************************[ 1. row ]*************************** tidb_version() | Release Version: v7.6.0 Edition: Community Git Commit Hash: 42960c3352d165810c79852b85ada448a68efa4c Git Branch: heads/refs/tags/v7.6.0 UTC Build Time: 2024-01-15 11:27:07 GoVersion: go1.21.5

Not a same issue.Since we can't add fk for partition table.

@YangKeao YangKeao added affects-5.4 This bug affects 5.4.x versions. affects-6.1 and removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 labels Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 affects-7.5 component/ddl This issue is related to DDL of TiDB. component/tablepartition This issue is related to Table Partition of TiDB. severity/major type/bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants