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

issue of KEY_COLUMN_USAGE table return wrong result about foreign key column #40490

Closed
crazycs520 opened this issue Jan 11, 2023 · 0 comments · Fixed by #40491
Closed

issue of KEY_COLUMN_USAGE table return wrong result about foreign key column #40490

crazycs520 opened this issue Jan 11, 2023 · 0 comments · Fixed by #40491
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. severity/minor sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@crazycs520
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

use test;
create table t1 (a int, b int, index(a, b));
create table t2 (a int, b int, index(a, b), constraint fk foreign key(a, b) references t1(a, b));

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

test> select CONSTRAINT_NAME, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA='test' and TABLE_NAME='t2' and REFERENCED_TABLE_SCHEMA is not null and REFERENCED_COLUMN_NAME is not null;
+-----------------+--------------+------------+-------------+-------------------------+-----------------------+------------------------+
| CONSTRAINT_NAME | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | REFERENCED_TABLE_SCHEMA | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME |
+-----------------+--------------+------------+-------------+-------------------------+-----------------------+------------------------+
| fk              | test         | t2         | a           | test                    | t1                    | a                      |
| fk              | test         | t2         | b           | test                    | t1                    | b                      |
+-----------------+--------------+------------+-------------+-------------------------+-----------------------+------------------------+

3. What did you see instead (Required)

test> select CONSTRAINT_NAME, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA='test' and TABLE_NAME='t2' and REFERENCED_TABLE_SCHEMA is not null and REFERENCED_COLUMN_NAME is not null;
+-----------------+--------------+------------+-------------+-------------------------+-----------------------+------------------------+
| CONSTRAINT_NAME | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | REFERENCED_TABLE_SCHEMA | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME |
+-----------------+--------------+------------+-------------+-------------------------+-----------------------+------------------------+
| fk              | test         | t2         | a           | test                    | t1                    | a                      |
| fk              | test         | t2         | b           | test                    | t1                    | a                      |
+-----------------+--------------+------------+-------------+-------------------------+-----------------------+------------------------+

4. What is your TiDB version? (Required)

***************************[ 1. row ]***************************
tidb_version() | Release Version: v6.6.0-alpha
Edition: Community
Git Commit Hash: bf2cc452066cb0269f4036d748ad4fa96eb021b8
Git Branch: heads/refs/tags/v6.6.0-alpha
UTC Build Time: 2023-01-04 14:25:26
GoVersion: go1.19.3
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. severity/minor sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
2 participants