apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.71k stars 6.68k forks source link

NPE occurs when execute show tables statement #19115

Closed strongduanmu closed 2 years ago

strongduanmu commented 2 years ago

Bug Report

Which version of ShardingSphere did you use?

https://github.com/apache/shardingsphere/commit/cb3cbe99d8bb41d25e55f4bd404ecf7e5cfeb287

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-Proxy

Expected behavior

Execute show tables statement successfully.

Actual behavior

[INFO ] 2022-07-13 20:49:32.005 [ShardingSphere-Command-4] ShardingSphere-SQL - Logic SQL: select @@version_comment limit 1
[INFO ] 2022-07-13 20:49:32.006 [ShardingSphere-Command-4] ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional[org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.limit.LimitSegment@393cb72a], lock=Optional.empty, window=Optional.empty)
[INFO ] 2022-07-13 20:49:32.006 [ShardingSphere-Command-4] ShardingSphere-SQL - Actual SQL: rts_stock_wtcth_1 ::: select @@version_comment limit 1
[ERROR] 2022-07-13 20:49:41.205 [ShardingSphere-Command-4] o.a.s.p.f.c.CommandExecutorTask - Exception occur: 
java.lang.NullPointerException: null
        at org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor.ShowTablesExecutor.getAllTableNames(ShowTablesExecutor.java:85)
        at org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor.ShowTablesExecutor.getQueryResult(ShowTablesExecutor.java:74)
        at org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor.ShowTablesExecutor.execute(ShowTablesExecutor.java:67)
        at org.apache.shardingsphere.proxy.backend.text.admin.DatabaseAdminQueryBackendHandler.execute(DatabaseAdminQueryBackendHandler.java:56)
        at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:95)
        at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:108)
        at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:78)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
[ERROR] 2022-07-13 20:49:45.530 [ShardingSphere-Command-4] o.a.s.p.f.c.CommandExecutorTask - Exception occur: 
java.lang.NullPointerException: null
        at org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor.ShowTablesExecutor.getAllTableNames(ShowTablesExecutor.java:85)
        at org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor.ShowTablesExecutor.getQueryResult(ShowTablesExecutor.java:74)
        at org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor.ShowTablesExecutor.execute(ShowTablesExecutor.java:67)
        at org.apache.shardingsphere.proxy.backend.text.admin.DatabaseAdminQueryBackendHandler.execute(DatabaseAdminQueryBackendHandler.java:56)
        at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:95)
        at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:108)
        at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:78)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).

strongduanmu commented 2 years ago

I found that this is a bug caused by ShardingSphereMetaData, when we create uppercase database name and schema name, ShardingSphereMetaData cannot support case-insensitive configuration. We need to avoid using the schemas fields of ShardingSphereDatabase and databases field of ShardingSphereMetaData directly.