Skip to content

MySQL's behavior without current schema #28469

Description

@134130

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..

  • 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions