Skip to content

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

@crazycs520

Description

@crazycs520

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions