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

   ##  Root Cause
     MySQL no-FROM queries are routed to the admin branch 
(MySQLAdminExecutorCreator → UnicastResourceShowExecutor). This executor builds 
a QueryHeader with 3 columns, but the row data collected from the backend only 
has 2 columns. The mismatch
     causes DatabaseAdminQueryBackendHandler to read a third column and throw 
an out-of-bounds exception.
   
   ##  Analysis
   
     - Trigger: the session has no selected database (no schema in 
handshake/connection) and executes a no-FROM multi-expression query.
     - In the admin branch, the column metadata shows 3 columns, but the row 
data list has only 2 elements; AbstractMemoryQueryResult.getValue accessing the 
3rd column overflows.
     - If the connection specifies a logic database or runs USE <db> first, it 
follows the normal query path where columns and data align, so the issue does 
not appear.
     - Official usage guidance: ShardingSphere-Proxy docs 
https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-proxy/
 recommend specifying a logic database on connect to avoid the admin branch for 
ordinary queries.
   
   ##  Conclusion (Fix Suggestion)
     This is an admin-branch defect in 5.5.2. Fix by aligning column count and 
row data in UnicastResourceShowExecutor, or by skipping the admin branch for 
normal multi-expression no-FROM selects.
   
     Example fix (5.5.2 path 
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UnicastResourceShowExecutor.java):
   
     private QueryResult createQueryResult() throws SQLException {
         List<MemoryQueryResultDataRow> rows = new LinkedList<>();
         int columnCount = getQueryResultMetaData().getColumnCount();
         while (databaseConnector.next()) {
             List<Object> data = databaseConnector.getRowData().getData();
             List<Object> aligned = new ArrayList<>(columnCount);
             aligned.addAll(data.size() >= columnCount ? data.subList(0, 
columnCount) : data);
             while (aligned.size() < columnCount) {
                 aligned.add(null); // choose null or empty string per protocol 
expectation
             }
             rows.add(new MemoryQueryResultDataRow(aligned));
         }
         return new RawMemoryQueryResult(getQueryResultMetaData(), rows);
     }
   
     Alternative (more conservative): in MySQLAdminExecutorCreator, for “no 
FROM + multi-expression” that is not a special function/system variable, return 
Optional.empty() so it goes through the normal query pipeline instead of the 
admin executor.
   
     Community contributors are warmly invited to submit a PR to implement and 
test this fix—thanks for the report!


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