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

different behavior on foreign key with MySQL #18756

Closed
csuzhangxc opened this issue Jul 24, 2020 · 0 comments · Fixed by #18784 or pingcap/community#328
Closed

different behavior on foreign key with MySQL #18756

csuzhangxc opened this issue Jul 24, 2020 · 0 comments · Fixed by #18784 or pingcap/community#328
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@csuzhangxc
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

in MySQL 5.7.21

> create database db;
Query OK, 1 row affected

> create table db.t1 (c1 int primary key, c2 int);
Query OK, 0 rows affected

> create table db.t2 (c1 int primary key, c2 int);
Query OK, 0 rows affected

> alter table db.t1 add constraint fk foreign key (c2) references t2(c1);
Query OK, 0 rows affected

> show create table db.t1\G
***************************[ 1. row ]***************************
Table        | t1
Create Table | CREATE TABLE `t1` (
  `c1` int(11) NOT NULL,
  `c2` int(11) DEFAULT NULL,
  PRIMARY KEY (`c1`),
  KEY `fk` (`c2`),
  CONSTRAINT `fk` FOREIGN KEY (`c2`) REFERENCES `t2` (`c1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

in TiDB v4.0.0 (also for master branch with git commit 9995ad7)

> create database db;
Query OK, 1 row affected

> create table db.t1 (c1 int primary key, c2 int);
Query OK, 0 rows affected

> create table db.t2 (c1 int primary key, c2 int);
Query OK, 0 rows affected

> alter table db.t1 add constraint fk foreign key (c2) references t2(c1);
(1046, 'No database selected')

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

no error reported.

3. What did you see instead (Required)

(1046, 'No database selected')

4. Affected version (Required)

v4.0.0 (other versions are not tested)

5. Root Cause Analysis

@csuzhangxc csuzhangxc added the type/bug The issue is confirmed as a bug. label Jul 24, 2020
@ghost ghost added the sig/sql-infra SIG: SQL Infra label Jul 24, 2020
@zimulala zimulala added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. labels Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
3 participants