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

Unable to query information_schema.referential_constraints for DELETE_RULE column without qualifying column name #7376

Closed
mcronce opened this issue Jan 25, 2021 · 0 comments · Fixed by #7504

Comments

@mcronce
Copy link

mcronce commented Jan 25, 2021

Overview of the Issue

The haskell/persistent-mysql test fails trying to execute the following query (formatted for readability):

SELECT
    KCU.REFERENCED_TABLE_NAME,
    KCU.CONSTRAINT_NAME,
    KCU.ORDINAL_POSITION,
    DELETE_RULE,
    UPDATE_RULE
FROM
    INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU 
    INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC ON
        KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
WHERE
    KCU.TABLE_SCHEMA = 'test' AND 
    KCU.TABLE_NAME = 'data_type_table' AND 
    KCU.COLUMN_NAME = 'id' AND 
    KCU.REFERENCED_TABLE_SCHEMA = 'test'
    AND KCU.CONSTRAINT_NAME = 'data_type_table_id_fkey'
ORDER BY KCU.CONSTRAINT_NAME, KCU.COLUMN_NAME;

What's interesting is that if I DESCRIBE information_schema.referential_constraints, it reports that the column is there. Additionally, if I add table qualifiers to those two columns, it works:

SELECT
    KCU.REFERENCED_TABLE_NAME,
    KCU.CONSTRAINT_NAME,
    KCU.ORDINAL_POSITION,
    RC.DELETE_RULE,
    RC.UPDATE_RULE
FROM
    INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU
    INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC ON
        KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
WHERE
    KCU.TABLE_SCHEMA = 'test' AND
    KCU.TABLE_NAME = 'data_type_table' AND
    KCU.COLUMN_NAME = 'id' AND
    KCU.REFERENCED_TABLE_SCHEMA = 'test'
    AND KCU.CONSTRAINT_NAME = 'data_type_table_id_fkey'
ORDER BY KCU.CONSTRAINT_NAME, KCU.COLUMN_NAME;
Empty set (0.01 sec)

Reproduction Steps

Pasting the following query into a mysql CLI prompt will reproduce the issue:

SELECT DELETE_RULE, UPDATE_RULE FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC ON  KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME WHERE KCU.TABLE_SCHEMA = 'test' AND KCU.TABLE_NAME = 'data_type_table' AND KCU.COLUMN_NAME = 'id' AND KCU.REFERENCED_TABLE_SCHEMA = 'test' AND KCU.CONSTRAINT_NAME = 'data_type_table_id_fkey' ORDER BY KCU.CONSTRAINT_NAME, KCU.COLUMN_NAME;

Binary version

Using vttestserver, but from vtcombo in the same container:

$ /vt/bin/vtcombo -version
ERROR: logging before flag.Parse: E0122 18:55:31.686379    2285 syslogger.go:149] can't connect to syslog
Version: e259a08f0 (Git branch 'master') built on Fri Jan 22 04:19:58 UTC 2021 by vitess@b581768d34fd using go1.15.6 linux/amd64

Operating system and Environment details

Inside the vttestserver container:

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
vitess@3e5d5c6a960a:/$ uname -sr 
Linux 5.10.2-2-MANJARO
vitess@3e5d5c6a960a:/$ uname -m
x86_64

Log Fragments

E0122 19:45:25.903237     706 vtgate.go:440] Execute: symbol DELETE_RULE not found, request: map[BindVariables:map[vtg1:type:VARBINARY value:"test"  vtg2:type:VARBINARY value:"data_type_table"  vtg3:type:VARBINARY value:"id"  vtg4:type:VARBINARY value:"data_type_table_id_fkey" ] Session:autocommit:true target_string:"test" options:<included_fields:ALL > found_rows:1 row_count:-1 DDLStrategy:"direct" SessionUUID:"570c9022-5cea-11eb-a676-0242ac110003" enable_system_settings:true Sql:SELECT DELETE_RULE,     UPDATE_RULE FROM     INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU      INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC ON         KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME WHERE     KCU.TABLE_SCHEMA = 'test' AND      KCU.TABLE_NAME = 'data_type_table' AND      KCU.COLUMN_NAME = 'id' AND      KCU.REFERENCED_TABLE_SCHEMA = 'test'     AND KCU.CONSTRAINT_NAME = 'data_type_table_id_fkey' ORDER BY KCU.CONSTRAINT_NAME, KCU.COLUMN_NAME]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants