terrymanu commented on issue #28469:
URL: 
https://github.com/apache/shardingsphere/issues/28469#issuecomment-3540598024

   Thank you for your detailed report and verification! After our team's 
in-depth analysis, this is indeed a bug in ShardingSphere's implementation that 
needs to maintain consistency with MySQL's native behavior.
   
   ##  Root Cause Confirmed
   
     ✅ Your verification is completely correct:
     - Standard MySQL: SELECT DATABASE() returns NULL
     - Current ShardingSphere: Uses TABLE_SCHEMA = '' filter
     - Core Issue: In SQL, NULL != '', causing incorrect query conditions
   
   ##  Specific Problem in Code
   
     We identified the problematic code in MySQLMetaDataLoader.java:
   
     // Lines 91, 135, 174 - NPE risk exists
     String databaseName = "".equals(connection.getCatalog()) ?
         
GlobalDataSourceRegistry.getInstance().getCachedDatabaseTables().get(tableNames.iterator().next())
 :
         connection.getCatalog();  // Throws NPE when connection.getCatalog() 
returns NULL
   
   ##  Fix Recommendation
   
     The correct approach should be:
     String catalog = connection.getCatalog();
     String databaseName = (catalog == null || catalog.isEmpty()) ?
         
GlobalDataSourceRegistry.getInstance().getCachedDatabaseTables().get(tableNames.iterator().next())
 :
         catalog;
   
     Or use Guava's Strings.isNullOrEmpty() method.
   
     🌟 Open Invitation to Community Contributors
   
     Since this is a community-owned open-source project, we're extending an 
invitation to all community participants to help solve this issue!
   
     Calling All Community Contributors - Let's Fix This Together!
   
     This is an excellent first-time contribution opportunity because:
     - ✅ Problem is well-defined with clear root cause
     - ✅ Small, controllable fix scope
     - ✅ Immediate improvement to user experience
     - ✅ Important fix for database behavior consistency
   
     Any community contributor can participate by following these steps:
   
     1. Claim the task: Comment "I'd like to work on this issue" below
     2. Set up development environment:
     git clone https://github.com/[your-username]/shardingsphere.git
     cd shardingsphere
     git checkout -b fix/mysql-null-schema-handling-28469
     3. Core modifications (File: 
database/connector/dialect/mysql/src/main/java/org/apache/shardingsphere/database/connector/mysql/metadata/data/loader/MySQLMetaDataLoader.java):
       - Line 91: Modify NULL check logic
       - Line 135: Modify NULL check logic
       - Line 174: Modify NULL check logic
     4. Add tests: Add test cases for NULL catalog scenarios in the 
corresponding test file
     5. Verify fix:
     ./mvnw test -Dtest=MySQLMetaDataLoaderTest
     ./mvnw spotless:apply
     ./mvnw install -DskipTests
     6. Submit PR: Describe the fix in detail and reference issue #28469
   
     We provide support for community contributors:
   
     - 🎯 Clear guidance: We've clearly identified problem locations and fix 
solutions
     - 📋 Code review: Provide professional and friendly code review services
     - 🤝 Technical support: Get help anytime during development
     - 🏆 Contribution recognition: All contributors will be recorded in the 
project's contributor list
   
     Why this fix is important?
   
     - 🔧 Improve user experience: Solve real-world usage scenarios without 
schema connections
     - 🎯 Behavior consistency: Ensure ShardingSphere maintains consistency with 
MySQL native behavior
     - 📈 Community value: Demonstrates Apache project's commitment to user 
experience
   
     The strength of community comes from everyone's participation! Even a 
small bug fix is an important contribution to the entire ShardingSphere 
ecosystem.
   
     Let's improve ShardingSphere together! 🚀
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to