Skip to content

[Bug][MySQL compatibility] Query to info schema table does not return correct results. #4361

@morningman

Description

@morningman

Describe the bug

SELECT TABLE_SCHEMA TABLE_CAT, NULL  TABLE_SCHEM,  TABLE_NAME, IF(TABLE_TYPE='BASE TABLE', 'TABLE', TABLE_TYPE) as TABLE_TYPE, TABLE_COMMENT REMARKS, NULL TYPE_CAT, NULL TYPE_SCHEM, NULL TYPE_NAME, NULL SELF_REFERENCING_COL_NAME,  NULL REF_GENERATION FROM INFORMATION_SCHEMA.TABLES  WHERE (ISNULL(database()) OR (TABLE_SCHEMA = database())) AND (TABLE_NAME LIKE '%') AND TABLE_TYPE IN ('BASE TABLE','VIEW','FOREIGN TABLE','MATERIALIZED VIEW','EXTERNAL TABLE') ORDER BY TABLE_TYPE, TABLE_SCHEMA, TABLE_NAME;

Above sql will return empty, which expected to return the table info in the current database.

Why

This is because database() function will return the full name of a database like default_cluster:db1.
But TABLE_SCHEMA returned from INFORMATION_SCHEMA.TABLES is the database name without default_cluster.
So the where predicate TABLE_SCHEMA = database() is false.

Metadata

Metadata

Assignees

Labels

area/mysql-compatibilityIssues or PRs related to the mysql compatibility

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions