Fix: Handle MySQL NULL schema behavior#38595
Open
AtharvaMa wants to merge 2 commits into
Open
Conversation
Author
|
Hi maintainers, could you please review my PR and trigger the CI/CD checks? |
Author
|
Hi maintainers, There is a styling error which I resolve could you please trigger the CI/CD checks..? |
Author
|
Hi everyone, I’m just checking in on the status of this PR. I’m happy to make any requested changes or address any feedback to help move this forward. Please let me know if there is anything I can do to assist with the review process. Thanks |
terrymanu
requested changes
May 28, 2026
terrymanu
left a comment
Member
There was a problem hiding this comment.
Decision
- Merge Verdict: Not Mergeable
- Reviewed Scope: Latest PR head
c0d23757d626c74e760a39f8ac9f3750ce8de0d1; local merge-base04cecfc6f980319ad3aa5c8fabce30f9b06ea61f; GitHub/pulls/38595/filesmatched localgit diff --name-statuswith 2 changed files:database/connector/dialect/mysql/src/main/java/org/apache/shardingsphere/database/connector/mysql/metadata/data/loader/MySQLMetaDataLoader.javaanddatabase/connector/dialect/mysql/src/test/java/org/apache/shardingsphere/database/connector/mysql/metadata/data/loader/MySQLMetaDataLoaderTest.java. Supporting paths checked:infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtils.java,infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java, andfeatures/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskRule.java. - Not Reviewed Scope: No GitHub Actions / CI status, no live MySQL JDBC or Proxy smoke, and no Maven test run. SQL parser family scan is not applicable because no parser files changed.
- Need Expert Review: Yes, a MySQL metadata/schema-loading maintainer should re-check the revised production-path behavior. No separate security or dependency review is needed.
Positive Feedback
- The change is small and targets the right MySQL metadata loader method.
- The new test covers one simple
nullcatalog case where the fallback table-to-schema cache is already populated.
Major Issues
- [Blocker] Null-catalog root cause is not fixed for the reported masking-only topology (
database/connector/dialect/mysql/src/main/java/org/apache/shardingsphere/database/connector/mysql/metadata/data/loader/MySQLMetaDataLoader.java:208)- Symptom: The new branch falls back to
GlobalDataSourceRegistry.getInstance().getCachedDatabaseTables().get(tableNames.iterator().next())whenConnection#getCatalog()isnullor empty (MySQLMetaDataLoader.java:209-211). However, the added test seeds that cache directly (MySQLMetaDataLoaderTest.java:97-100) instead of proving that the real schema-building path populates it. In the masking-only scenario from issue #28469,MaskRulecontributes aMaskTableMapperRuleAttributeonly (features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskRule.java:57), soDataNodes#getDataNodes(table)has no data node schema to cache.SchemaMetaDataUtilsonly writes the fallback cache while iterating data nodes whose data source name contains a schema (infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtils.java:96-105). - Risk: For
jdbc:mysql://host:3306/with no selected database, which MySQL documents as a valid state whereDATABASE()returnsNULL, this can still bind anullschema into the metadata SQL and return empty metadata. That leaves the originalTableNotExistsException/ wrong metadata path unresolved for the reported ShardingSphere-JDBC + Masking use case. - Action: Please fix the production fallback source, not only the cached-subset symptom. Either carry the authoritative schema into the loader material, or explicitly load the relevant schemas when MySQL has no current catalog. Please add a regression test through
SchemaMetaDataUtilsorGenericSchemaBuilderfor the masking-only no-current-schema path, without manually inserting intoGlobalDataSourceRegistry.
- Symptom: The new branch falls back to
Newly Introduced Issues
- [Blocker]
nullcatalog with an empty table set can now fail before metadata loading (database/connector/dialect/mysql/src/main/java/org/apache/shardingsphere/database/connector/mysql/metadata/data/loader/MySQLMetaDataLoader.java:210)- Symptom: The new
null == catalog || catalog.isEmpty()branch callstableNames.iterator().next()(MySQLMetaDataLoader.java:211). The existing empty-table test only covers a non-empty catalog (MySQLMetaDataLoaderTest.java:268), so the adjacent caseactualTableNames = emptypluscatalog = nullis unvalidated. - Risk: The MySQL loader's existing "load without requested table names" path can regress to
NoSuchElementExceptionbefore it decides whether to load all metadata, return empty metadata, or use an explicit schema. - Action: Please define the expected behavior for empty requested table names when MySQL has no current catalog, guard the fallback accordingly, and add a dedicated regression test.
- Symptom: The new
Next Steps
- Rework schema fallback so it comes from an authoritative production source instead of a manually seeded
tableName -> databaseglobal cache. - Add production-path regression coverage for ShardingSphere-JDBC + Masking with a MySQL URL that has no schema selected.
- Add at least one counterexample for fallback binding, such as missing cache, empty requested table set, or same table name in two schemas.
- Keep the current non-empty catalog and empty-string catalog cases covered.
- Run the scoped verification after the fix, for example:
./mvnw -pl database/connector/dialect/mysql -am -DskipITs -Dspotless.skip=true -Dtest=MySQLMetaDataLoaderTest -Dsurefire.failIfNoSpecifiedTests=false test, then run the project-required Spotless and Checkstyle gates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #28469
Changes proposed in this pull request:
-Changed
MySQLMetaDataLoader.javaso that it works right whenConnection.getCatalog() gives back null.-Added a specific unit test
assertLoadWithNullCataloginMySQLMetaDataLoaderTest.javato simulate thenullcatalog behavior and verify the metadata loads successfully.-Update the logic that incorrectly fell back to an empty string
""when the catalog was null(null != ""), preventing the subsequentTableNotExistsExceptionand NPEs.Before committing this PR, I'm sure that I have checked the following options:
./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.