terrymanu commented on issue #28841:
URL:
https://github.com/apache/shardingsphere/issues/28841#issuecomment-3532159930
This is a confirmed Bug.
Through code analysis, the issue occurs in the
ShardingSphereResultSetUtils.createColumnLabelAndIndexMap() method. The
exception is triggered when a query meets all of the following conditions:
1. Query involves enhanced tables (sharding tables, encrypt tables, etc.)
2. Uses JOIN query
3. Uses mixed column selection pattern: SELECT A.column, B.*
## Root Cause
In the current implementation, when containsDerivedProjections() returns
true, the system uses expansion projection mode to build column label mapping
instead of using actual ResultSetMetaData. This causes some columns
(particularly from B.* expansion) to fail to map correctly to column
labels, resulting in "Can not get index from column label" exception when users
access columns by name.
Test Case Recommendation
To reproduce this issue, we recommend adding the following test case to
test/e2e/sql/src/test/resources/cases/dql/e2e-dql-select-join.xml:
```xml
<!-- Reproduce issue #28841: SELECT A.column, B.* pattern with enhanced
tables -->
<test-case sql="SELECT o.user_id, i.* FROM t_order o JOIN t_order_item i
ON o.order_id = i.order_id WHERE o.order_id = ?"
db-types="MySQL,PostgreSQL,openGauss"
scenario-types="db,tbl,dbtbl_with_readwrite_splitting">
<assertion parameters="1000:int"
expected-data-source-name="read_dataset" />
</test-case>
```
This test case simulates the user's specific scenario: selecting specific
columns (o.user_id) plus wildcard columns from another table (i.*).
## Fix Recommendation
Fix Direction: Improve Column Label Mapping Logic
In ShardingSphereResultSetUtils.createColumnLabelAndIndexMap(), ensure
that all columns are correctly mapped in expansion projection mode:
```java
// Recommended approach in
createColumnLabelAndIndexMapWithExpandProjections method
// Combine with ResultSetMetaData to ensure all columns are correctly
mapped
private static Map<String, Integer>
createColumnLabelAndIndexMapWithExpandProjections(
final SelectStatementContext statementContext, final ResultSetMetaData
resultSetMetaData) throws SQLException {
// Use expansion projections, but supplement with actual column
information from ResultSetMetaData
}
```
## Call for Volunteers
This is an important bug that affects user experience, particularly
impacting:
- Scenarios using sharding tables + JOIN queries
- Scenarios using encrypt tables + JOIN queries
- Business scenarios requiring mixed selection of specific columns and
wildcards
We welcome community contributor volunteers to:
1. Add e2e test cases to reproduce the issue
2. Implement the fix
3. Ensure the fix doesn't affect existing functionality
Interested contributors can leave a comment on this issue to express their
participation interest. We will provide necessary guidance and support.
--
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]