apache/shardingsphere

MySQL's behavior without current schema

Open

#28,469 创建于 2023年9月19日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)Java (6,902 fork)batch import
db: MySQLgood first issuestatus: volunteer wanted

仓库指标

Star
 (20,714 star)
PR 合并指标
 (平均合并 3天 14小时) (30 天内合并 194 个 PR)

描述

Question

  • When using shardingsphere-jdbc on MySQL, we can give jdbcUrl without schema

    • ex) jdbc:mysql://localhost:3306/
    • Then SELECT DATABASE() returns null
  • In this case, the masking feature is failed with org.apache.shardingsphere.infra.exception.TableNotExistsException: Table or view 'actor' does not exist..

    • Reference: #27879
  • Reason: metaDataContext queries to Database with below query. (Maybe generated with ResultSet java.sql.DatabaseMetaData.getTables())

     SELECT TABLE_SCHEMA            AS TABLE_CAT,
     NULL                    AS TABLE_SCHEM,
     TABLE_NAME,
     CASE
         WHEN TABLE_TYPE = 'BASE TABLE' THEN CASE
                                                 WHEN TABLE_SCHEMA = 'mysql' OR TABLE_SCHEMA = 'performance_schema'
                                                     THEN 'SYSTEM TABLE'
                                                 ELSE 'TABLE' END
         WHEN TABLE_TYPE = 'TEMPORARY' THEN 'LOCAL_TEMPORARY'
         ELSE TABLE_TYPE END AS TABLE_TYPE,
     TABLE_COMMENT           AS REMARKS,
     NULL                    AS TYPE_CAT,
     NULL                    AS TYPE_SCHEM,
     NULL                    AS TYPE_NAME,
     NULL                    AS SELF_REFERENCING_COL_NAME,
     NULL                    AS REF_GENERATION
     FROM INFORMATION_SCHEMA.TABLES
     WHERE TABLE_SCHEMA = ''   -- <-- This part makes empty result
     HAVING TABLE_TYPE IN ('TABLE', 'VIEW', 'SYSTEM TABLE', 'SYSTEM VIEW', null)
     ORDER BY TABLE_TYPE, TABLE_SCHEMA, TABLE_NAME;
    

Is this behavior is intended? I think we need to fetch all schemas in this case. Also, even though having current schema, quering to other schema's data is being failure, we need to fetch all schemas also.

贡献者指南