[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

could create partition table with FOREIGN KEY #32234

Closed
aytrack opened this issue Feb 10, 2022 · 4 comments
Closed

could create partition table with FOREIGN KEY #32234

aytrack opened this issue Feb 10, 2022 · 4 comments
Labels
component/tablepartition This issue is related to Table Partition of TiDB. sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.

Comments

@aytrack
Copy link
Contributor
aytrack commented Feb 10, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists product, product_order, customer;
CREATE TABLE product (
    category INT NOT NULL, id INT NOT NULL,
    price DECIMAL,
    PRIMARY KEY(category, id)
);
CREATE TABLE customer (
    id INT NOT NULL,
    PRIMARY KEY (id)
);

--error Foreign keys are not yet supported in conjunction with partitioning
CREATE TABLE product_order (
    no INT NOT NULL AUTO_INCREMENT,
    product_category INT NOT NULL,
    product_id INT NOT NULL,
    customer_id INT NOT NULL,

    PRIMARY KEY(no),
    INDEX (product_category, product_id),
    INDEX (customer_id),

    FOREIGN KEY (product_category, product_id)
      REFERENCES product(category, id)
      ON UPDATE CASCADE ON DELETE RESTRICT,

    FOREIGN KEY (customer_id)
      REFERENCES customer(id)
    ) partition by range (no) (
    partition p0 values less than (10),
    partition p1 values less than (20)
);

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

failed to create table product_order

3. What did you see instead (Required)

create table product_order successfully

MySQL root@127.0.0.1:test> show create table  product_order\G
***************************[ 1. row ]***************************
Table        | product_order
Create Table | CREATE TABLE `product_order` (
  `no` int(11) NOT NULL AUTO_INCREMENT,
  `product_category` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `customer_id` int(11) NOT NULL,
  PRIMARY KEY (`no`) /*T![clustered_index] CLUSTERED */,
  KEY `product_category` (`product_category`,`product_id`),
  KEY `customer_id` (`customer_id`),
  CONSTRAINT `product_category` FOREIGN KEY (`product_category`,`product_id`) REFERENCES `product` (`category`,`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE (`no`)
(PARTITION `p0` VALUES LESS THAN (10),
 PARTITION `p1` VALUES LESS THAN (20))

4. What is your TiDB version? (Required)

MySQL root@127.0.0.1:test> select tidb_version()\G
***************************[ 1. row ]***************************
tidb_version() | Release Version: v5.5.0-alpha-234-g19a020c59-dirty
Edition: Community
Git Commit Hash: 19a020c59956d1f430c41ca9d168a7417dc33490
Git Branch: master
UTC Build Time: 2022-01-27 03:45:36
GoVersion: go1.17.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@aytrack aytrack added type/bug The issue is confirmed as a bug. sig/sql-infra SIG: SQL Infra severity/moderate component/tablepartition This issue is related to Table Partition of TiDB. labels Feb 10, 2022
@hawkingrei hawkingrei added type/enhancement The issue or PR belongs to an enhancement. type/bug The issue is confirmed as a bug. and removed type/bug The issue is confirmed as a bug. type/enhancement The issue or PR belongs to an enhancement. labels Feb 10, 2022
@mjonss
Copy link
Contributor
mjonss commented Feb 10, 2022

So the issue is that there is no error when using foreign keys on partitioned tables, when MySQL would issue one:

ERROR 1506 (HY000): Foreign keys are not yet supported in conjunction with partitioning

But since TiDB does not support Foreign keys currently I do not think we should return an error for foreign keys on partitioned tables, since we do not do it for non-partitioned tables where we also do not support it (or rather we parse it and store the constraints, but we do not check or enforce the foreign key constraints).

Reference to Foreign key support in documentation: https://docs.pingcap.com/tidb/dev/constraints#foreign-key

I think this should be a feature request and maybe even closed as a duplicate of #18209.

@zimulala zimulala added type/enhancement The issue or PR belongs to an enhancement. and removed type/bug The issue is confirmed as a bug. severity/moderate labels Feb 11, 2022
@zimulala
Copy link
Contributor

@mjonss I think you can directly change the label, according to your explanation.
I updated the label. ^-^

I also feel that this PR can be closed first, @bb7133 what do you think?

@bb7133
Copy link
Member
bb7133 commented May 9, 2022

@zimulala Since it is an enhancement, I think we could keep it open.

@mjonss
Copy link
Contributor
mjonss commented May 22, 2023

Just checked v6.6.0, where foreign key starts to be supported in TiDB and it fails with the same error as in MySQL:

ERROR 1506 (HY000): Foreign key clause is not yet supported in conjunction with partitioning

(Same in nightly build of v7.2.0-alpha commit hash 94371a4)

Closing this issue

@mjonss mjonss closed this as completed May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/tablepartition This issue is related to Table Partition of TiDB. sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

5 participants