You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
Run the test of mysql j connector on TiDB, and the test testBug95280 failed. It tests to get the FK information from JDBC. When the useIS=false, the test will pass, and when the useIS=true, the test failed (and get a redundant row).
When useIS=true, the mysql J connector will run the following SQL:
SELECT DISTINCT A.REFERENCED_TABLE_SCHEMA AS PKTABLE_CAT,
NULL AS PKTABLE_SCHEM,
A.REFERENCED_TABLE_NAME AS PKTABLE_NAME,
A.REFERENCED_COLUMN_NAME AS PKCOLUMN_NAME,
A.TABLE_SCHEMA AS FKTABLE_CAT,
NULL AS FKTABLE_SCHEM,
A.TABLE_NAME AS FKTABLE_NAME,
A.COLUMN_NAME AS FKCOLUMN_NAME,
A.ORDINAL_POSITION AS KEY_SEQ,
CASE
WHEN R.UPDATE_RULE = 'CASCADE' THEN 0
WHEN R.UPDATE_RULE = 'SET NULL' THEN 2
WHEN R.UPDATE_RULE = 'SET DEFAULT' THEN 4
WHEN R.UPDATE_RULE = 'RESTRICT' THEN 1
WHEN R.UPDATE_RULE = 'NO ACTION' THEN 1
ELSE 1
END AS UPDATE_RULE,
CASE
WHEN R.DELETE_RULE = 'CASCADE' THEN 0
WHEN R.DELETE_RULE = 'SET NULL' THEN 2
WHEN R.DELETE_RULE = 'SET DEFAULT' THEN 4
WHEN R.DELETE_RULE = 'RESTRICT' THEN 1
WHEN R.DELETE_RULE = 'NO ACTION' THEN 1
ELSE 1
END AS DELETE_RULE,
A.CONSTRAINT_NAME AS FK_NAME,
R.UNIQUE_CONSTRAINT_NAME AS PK_NAME,
7 AS DEFERRABILITY
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE A
JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS B USING (CONSTRAINT_NAME, TABLE_NAME)
JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS R ON (
R.CONSTRAINT_NAME = B.CONSTRAINT_NAME
AND R.TABLE_NAME = B.TABLE_NAME
AND R.CONSTRAINT_SCHEMA = B.TABLE_SCHEMA
)
WHERE B.CONSTRAINT_TYPE = 'FOREIGN KEY'
AND A.TABLE_SCHEMA = ?
AND A.TABLE_NAME = ?
AND A.REFERENCED_TABLE_SCHEMA IS NOT NULL
ORDER BY A.REFERENCED_TABLE_SCHEMA,
A.REFERENCED_TABLE_NAME,
A.ORDINAL_POSITION
Therefore, this issue can be reproduced by the following SQLs:
createdatabasedbBug95280_1;
createtabledbBug95280_1.table1(cat_id intnot null auto_increment primary key, cat_name varchar(255) not null, cat_description text) ENGINE=InnoDB;
createtabledbBug95280_1.table2(prd_id intnot null auto_increment primary key, prd_name varchar(355) not null, prd_price decimal, cat_id intnot null, FOREIGN KEY fk_cat(cat_id) REFERENCES table1(cat_id) ONUPDATE CASCADE ON DELETE RESTRICT) ENGINE=InnoDB;
createdatabasedbBug95280_2;
createtabledbBug95280_2.table1(cat_id intnot null auto_increment primary key, cat_name varchar(255) not null, cat_description text) ENGINE=InnoDB;
createtabledbBug95280_2.table2(prd_id intnot null auto_increment primary key, prd_name varchar(355) not null, prd_price decimal, cat_id intnot null, FOREIGN KEY fk_cat(cat_id) REFERENCES table1(cat_id) ONUPDATE CASCADE ON DELETE RESTRICT) ENGINE=InnoDB;
SELECT DISTINCTA.REFERENCED_TABLE_SCHEMAAS PKTABLE_CAT,
NULLAS PKTABLE_SCHEM,
A.REFERENCED_TABLE_NAMEAS PKTABLE_NAME,
A.REFERENCED_COLUMN_NAMEAS PKCOLUMN_NAME,
A.TABLE_SCHEMAAS FKTABLE_CAT,
NULLAS FKTABLE_SCHEM,
A.TABLE_NAMEAS FKTABLE_NAME,
A.COLUMN_NAMEAS FKCOLUMN_NAME,
A.ORDINAL_POSITIONAS KEY_SEQ,
CASE
WHEN R.UPDATE_RULE='CASCADE' THEN 0
WHEN R.UPDATE_RULE='SET NULL' THEN 2
WHEN R.UPDATE_RULE='SET DEFAULT' THEN 4
WHEN R.UPDATE_RULE='RESTRICT' THEN 1
WHEN R.UPDATE_RULE='NO ACTION' THEN 1
ELSE 1
END AS UPDATE_RULE,
CASE
WHEN R.DELETE_RULE='CASCADE' THEN 0
WHEN R.DELETE_RULE='SET NULL' THEN 2
WHEN R.DELETE_RULE='SET DEFAULT' THEN 4
WHEN R.DELETE_RULE='RESTRICT' THEN 1
WHEN R.DELETE_RULE='NO ACTION' THEN 1
ELSE 1
END AS DELETE_RULE,
A.CONSTRAINT_NAMEAS FK_NAME,
R.UNIQUE_CONSTRAINT_NAMEAS PK_NAME,
7AS DEFERRABILITY
FROMINFORMATION_SCHEMA.KEY_COLUMN_USAGE A
JOININFORMATION_SCHEMA.TABLE_CONSTRAINTS B USING (CONSTRAINT_NAME, TABLE_NAME)
JOININFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS R ON (
R.CONSTRAINT_NAME=B.CONSTRAINT_NAMEANDR.TABLE_NAME=B.TABLE_NAMEANDR.CONSTRAINT_SCHEMA=B.TABLE_SCHEMA
)
WHEREB.CONSTRAINT_TYPE='FOREIGN KEY'ANDA.TABLE_SCHEMA='dbBug95280_1'ANDA.TABLE_NAME='table2'ANDA.REFERENCED_TABLE_SCHEMAIS NOT NULLORDER BYA.REFERENCED_TABLE_SCHEMA,
A.REFERENCED_TABLE_NAME,
A.ORDINAL_POSITION;
YangKeao
changed the title
JDBC test related to schema and useInformationSchema=true failed
JDBC test related to schema, FK and useInformationSchema=true failed
Aug 2, 2024
Do you cover both @@tidb_schema_cache_size='512MB' and @@tidb_schema_cache_size = default?
I didn't try. I guess the issue is related to the implementation of predicates on information_schema.KEY_COLUMN_USAGE. The SQL select * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_schema = 'dbBug95280_1'; will return all rows and the condition where table_schema = 'dbBug95280_1' has no effect 🤔 .
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
Run the test of mysql j connector on TiDB, and the test
testBug95280
failed. It tests to get the FK information from JDBC. When theuseIS=false
, the test will pass, and when theuseIS=true
, the test failed (and get a redundant row).When
useIS=true
, the mysql J connector will run the following SQL:Therefore, this issue can be reproduced by the following SQLs:
2. What did you expect to see? (Required)
The test pass
And the SQL return one row
3. What did you see instead (Required)
The test failed
4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: