This is an automated email from the ASF dual-hosted git repository.

terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 06899205900 Fix MySQL SHOW INDEX stripping suffix from non-sharding 
index names (#39853)
06899205900 is described below

commit 06899205900ce9c02b94da5ea5934d4c88875f6b
Author: Eunbin Son <[email protected]>
AuthorDate: Tue Sep 22 23:24:29 2026 +0900

    Fix MySQL SHOW INDEX stripping suffix from non-sharding index names (#39853)
    
    * Fix MySQL SHOW INDEX stripping suffix from non-sharding index names
    
    MySQLShardingShowIndexMergedResult applied the generated-index-name
    reverse lookup to every row, so a user-defined index such as
    uk_t_config on the non-sharding table t_config was returned as uk.
    Limit the lookup to rows of sharding tables, matching IndexToken,
    ShardingMetaDataReviseEntry and MySQLShardingShowCreateTableMergedResult,
    which all leave non-sharding index names untouched.
    
    * Fill actual PR number in Release Notes
    
    ---------
    
    Co-authored-by: Liang Zhang <[email protected]>
---
 RELEASE-NOTES.md                                   |  1 +
 .../type/MySQLShardingShowIndexMergedResult.java   | 12 +++++++----
 .../MySQLShardingShowIndexMergedResultTest.java    | 23 ++++++++++++++++++++--
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 456db79dd3e..affba762c46 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -86,6 +86,7 @@
 1. Sharding: Compute the Snowflake key generator epoch in UTC instead of the 
JVM default timezone - 
[#38932](https://github.com/apache/shardingsphere/pull/38932)
 1. Sharding: Fix order-dependent data source intersection in Cartesian routing 
- [#39407](https://github.com/apache/shardingsphere/pull/39407)
 1. Sharding: Fix incorrect AVG(DISTINCT) merge result across shards - 
[#39429](https://github.com/apache/shardingsphere/pull/39429)
+1. Sharding: Fix MySQL SHOW INDEX stripping table suffix from index names of 
non-sharding tables - 
[#39853](https://github.com/apache/shardingsphere/pull/39853)
 1. Sharding: Fix NOT BETWEEN on sharding column being routed as BETWEEN - 
[#39855](https://github.com/apache/shardingsphere/pull/39855)
 1. Sharding: Use configured sharding column name when checking UPDATE 
assignments - [#39864](https://github.com/apache/shardingsphere/pull/39864)
 1. Sharding: Fix INTERVAL sharding on one-sided range outside datetime bounds 
- [#39862](https://github.com/apache/shardingsphere/pull/39862)
diff --git 
a/features/sharding/dialect/mysql/src/main/java/org/apache/shardingsphere/sharding/merge/mysql/type/MySQLShardingShowIndexMergedResult.java
 
b/features/sharding/dialect/mysql/src/main/java/org/apache/shardingsphere/sharding/merge/mysql/type/MySQLShardingShowIndexMergedResult.java
index 653894332e6..213fdcc0fdc 100644
--- 
a/features/sharding/dialect/mysql/src/main/java/org/apache/shardingsphere/sharding/merge/mysql/type/MySQLShardingShowIndexMergedResult.java
+++ 
b/features/sharding/dialect/mysql/src/main/java/org/apache/shardingsphere/sharding/merge/mysql/type/MySQLShardingShowIndexMergedResult.java
@@ -21,7 +21,9 @@ import 
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementCont
 import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
 import 
org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryMergedResult;
 import 
org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryQueryResultRow;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.util.IndexMetaDataUtils;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import org.apache.shardingsphere.sharding.rule.ShardingTable;
@@ -51,18 +53,20 @@ public final class MySQLShardingShowIndexMergedResult 
extends MemoryMergedResult
             while (each.next()) {
                 MemoryQueryResultRow memoryResultSetRow = new 
MemoryQueryResultRow(each);
                 String actualTableName = 
memoryResultSetRow.getCell(1).toString();
-                String actualIndexName = 
memoryResultSetRow.getCell(3).toString();
                 Optional<ShardingTable> shardingTable = 
shardingRule.findShardingTableByActualTable(actualTableName);
-                Collection<String> candidateLogicIndexNames = new 
LinkedList<>();
                 if (shardingTable.isPresent()) {
                     String logicTableName = 
shardingTable.get().getLogicTable();
                     memoryResultSetRow.setCell(1, logicTableName);
-                    candidateLogicIndexNames = 
schema.getTable(logicTableName).getAllIndexes().stream().map(eachIndex -> 
eachIndex.getName()).collect(Collectors.toList());
+                    memoryResultSetRow.setCell(3, 
findLogicIndexName(memoryResultSetRow.getCell(3).toString(), actualTableName, 
schema.getTable(logicTableName)));
                 }
-                memoryResultSetRow.setCell(3, 
IndexMetaDataUtils.findGeneratedLogicIndexName(actualIndexName, 
actualTableName, candidateLogicIndexNames).orElse(actualIndexName));
                 result.add(memoryResultSetRow);
             }
         }
         return result;
     }
+    
+    private String findLogicIndexName(final String actualIndexName, final 
String actualTableName, final ShardingSphereTable logicTable) {
+        Collection<String> candidateLogicIndexNames = 
logicTable.getAllIndexes().stream().map(ShardingSphereIndex::getName).collect(Collectors.toList());
+        return IndexMetaDataUtils.findGeneratedLogicIndexName(actualIndexName, 
actualTableName, candidateLogicIndexNames).orElse(actualIndexName);
+    }
 }
diff --git 
a/features/sharding/dialect/mysql/src/test/java/org/apache/shardingsphere/sharding/merge/mysql/type/MySQLShardingShowIndexMergedResultTest.java
 
b/features/sharding/dialect/mysql/src/test/java/org/apache/shardingsphere/sharding/merge/mysql/type/MySQLShardingShowIndexMergedResultTest.java
index ea2d05e434e..88ae1004b40 100644
--- 
a/features/sharding/dialect/mysql/src/test/java/org/apache/shardingsphere/sharding/merge/mysql/type/MySQLShardingShowIndexMergedResultTest.java
+++ 
b/features/sharding/dialect/mysql/src/test/java/org/apache/shardingsphere/sharding/merge/mysql/type/MySQLShardingShowIndexMergedResultTest.java
@@ -62,13 +62,28 @@ class MySQLShardingShowIndexMergedResultTest {
     }
     
     @Test
-    void assertGetValueWithShortenedIndexName() throws SQLException {
+    void assertGetValueWithLegacyIndexName() throws SQLException {
+        ShardingTable shardingTable = mock(ShardingTable.class);
+        
when(rule.findShardingTableByActualTable("t_order_0")).thenReturn(Optional.of(shardingTable));
+        when(shardingTable.getLogicTable()).thenReturn("t_order");
+        when(schema.getTable("t_order")).thenReturn(new 
ShardingSphereTable("t_order", Collections.emptyList(),
+                Collections.singleton(new ShardingSphereIndex("t_order_index", 
Collections.emptyList(), false)), Collections.emptyList()));
         MySQLShardingShowIndexMergedResult actual = new 
MySQLShardingShowIndexMergedResult(rule, mock(SQLStatementContext.class), 
schema,
                 
Collections.singletonList(mockQueryResult(IndexMetaDataUtils.getActualIndexName("t_order_index",
 "t_order_0"))));
         assertTrue(actual.next());
+        assertThat(actual.getValue(1, String.class), is("t_order"));
         assertThat(actual.getValue(3, String.class), is("t_order_index"));
     }
     
+    @Test
+    void assertGetValueWithNonShardingTable() throws SQLException {
+        MySQLShardingShowIndexMergedResult actual = new 
MySQLShardingShowIndexMergedResult(rule, mock(SQLStatementContext.class), 
schema,
+                Collections.singletonList(mockQueryResult("t_config", 
"uk_t_config")));
+        assertTrue(actual.next());
+        assertThat(actual.getValue(1, String.class), is("t_config"));
+        assertThat(actual.getValue(3, String.class), is("uk_t_config"));
+    }
+    
     @Test
     void assertGetValueWithLogicalIndexNameEndingWithHashLikeSuffix() throws 
SQLException {
         ShardingTable shardingTable = mock(ShardingTable.class);
@@ -100,10 +115,14 @@ class MySQLShardingShowIndexMergedResultTest {
     }
     
     private QueryResult mockQueryResult(final String actualIndexName) throws 
SQLException {
+        return mockQueryResult("t_order_0", actualIndexName);
+    }
+    
+    private QueryResult mockQueryResult(final String actualTableName, final 
String actualIndexName) throws SQLException {
         QueryResult result = mock(QueryResult.class, RETURNS_DEEP_STUBS);
         when(result.getMetaData().getColumnCount()).thenReturn(3);
         when(result.next()).thenReturn(true, false);
-        when(result.getValue(1, Object.class)).thenReturn("t_order_0");
+        when(result.getValue(1, Object.class)).thenReturn(actualTableName);
         when(result.getValue(2, Object.class)).thenReturn(1);
         when(result.getValue(3, Object.class)).thenReturn(actualIndexName);
         return result;

Reply via email to