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

lijibing pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 120bf28d1e2 [fix](statistics)Skip shadow index while analyzing a 
table. (#42201) (#42414)
120bf28d1e2 is described below

commit 120bf28d1e2919362ef5eb14e06c684f9ecc3641
Author: Jibing-Li <64681310+jibing...@users.noreply.github.com>
AuthorDate: Fri Oct 25 13:44:42 2024 +0800

    [fix](statistics)Skip shadow index while analyzing a table. (#42201) 
(#42414)
    
    backport: https://github.com/apache/doris/pull/42201
---
 .../java/org/apache/doris/catalog/OlapTable.java   | 17 ++++-
 .../org/apache/doris/catalog/OlapTableTest.java    | 76 ++++++++++++++++++++++
 2 files changed, 90 insertions(+), 3 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
index 9957b93338e..123412827a1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
@@ -78,6 +78,7 @@ import org.apache.doris.thrift.TStorageType;
 import org.apache.doris.thrift.TTableDescriptor;
 import org.apache.doris.thrift.TTableType;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
@@ -897,7 +898,7 @@ public class OlapTable extends Table implements 
MTMVRelatedTableIf {
         if (full) {
             return indexIdToMeta.get(indexId).getSchema();
         } else {
-            return 
indexIdToMeta.get(indexId).getSchema().stream().filter(column -> 
column.isVisible())
+            return 
indexIdToMeta.get(indexId).getSchema().stream().filter(Column::isVisible)
                     .collect(Collectors.toList());
         }
     }
@@ -905,8 +906,8 @@ public class OlapTable extends Table implements 
MTMVRelatedTableIf {
     @Override
     public List<Column> getSchemaAllIndexes(boolean full) {
         List<Column> columns = Lists.newArrayList();
-        for (Long indexId : indexIdToMeta.keySet()) {
-            columns.addAll(getSchemaByIndexId(indexId, full));
+        for (MaterializedIndex index : getVisibleIndex()) {
+            columns.addAll(getSchemaByIndexId(index.getId(), full));
         }
         return columns;
     }
@@ -3083,4 +3084,14 @@ public class OlapTable extends Table implements 
MTMVRelatedTableIf {
     public boolean isPartitionColumnAllowNull() {
         return true;
     }
+
+    @VisibleForTesting
+    protected void addIndexIdToMetaForUnitTest(long id, MaterializedIndexMeta 
meta) {
+        indexIdToMeta.put(id, meta);
+    }
+
+    @VisibleForTesting
+    protected void addIndexNameToIdForUnitTest(String name, long id) {
+        indexNameToId.put(name, id);
+    }
 }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java
index fd394353cd2..8526b2d2271 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java
@@ -22,6 +22,7 @@ import org.apache.doris.catalog.TableIf.TableType;
 import org.apache.doris.common.FeConstants;
 import org.apache.doris.common.io.FastByteArrayOutputStream;
 import org.apache.doris.common.util.UnitTestUtil;
+import org.apache.doris.thrift.TStorageType;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -168,4 +169,79 @@ public class OlapTableTest {
 
         olapTable.getRowCountForPartitionIndex(11, 10, true);
     }
+
+    @Test
+    public void testGetSchemaAllIndexes() {
+        OlapTable table = new OlapTable();
+        List<Column> schema1 = Lists.newArrayList();
+        Column col1 = new Column("col1", PrimitiveType.INT);
+        Column col2 = new Column("col2", PrimitiveType.INT);
+        Column col3 = new Column("col3", PrimitiveType.INT);
+        Column col4 = new Column("col4", PrimitiveType.INT);
+        schema1.add(col1);
+        schema1.add(col2);
+        MaterializedIndexMeta meta1 = new MaterializedIndexMeta(1L, schema1, 
1, 1, (short) 1,
+                TStorageType.COLUMN, KeysType.DUP_KEYS, null);
+        table.addIndexIdToMetaForUnitTest(1, meta1);
+        table.addIndexNameToIdForUnitTest("index1", 1L);
+
+        List<Column> schema2 = Lists.newArrayList();
+        schema2.add(col3);
+        schema2.add(col4);
+        MaterializedIndexMeta meta2 = new MaterializedIndexMeta(2L, schema2, 
1, 1, (short) 1,
+                TStorageType.COLUMN, KeysType.DUP_KEYS, null);
+        table.addIndexIdToMetaForUnitTest(1, meta1);
+        table.addIndexIdToMetaForUnitTest(2, meta2);
+        table.addIndexNameToIdForUnitTest("index2", 2L);
+
+        MaterializedIndex index1 = new MaterializedIndex(1, 
MaterializedIndex.IndexState.NORMAL);
+        new MockUp<OlapTable>() {
+            @Mock
+            public List<MaterializedIndex> getVisibleIndex() {
+                return Lists.newArrayList(index1);
+            }
+        };
+
+        List<Column> schemaAllIndexes = table.getSchemaAllIndexes(false);
+        Assert.assertEquals(2, schemaAllIndexes.size());
+        Assert.assertFalse(schemaAllIndexes.contains(col3));
+        Assert.assertFalse(schemaAllIndexes.contains(col4));
+        Assert.assertTrue(schemaAllIndexes.contains(col1));
+        Assert.assertTrue(schemaAllIndexes.contains(col2));
+
+        MaterializedIndex index2 = new MaterializedIndex(2, 
MaterializedIndex.IndexState.NORMAL);
+        new MockUp<OlapTable>() {
+            @Mock
+            public List<MaterializedIndex> getVisibleIndex() {
+                return Lists.newArrayList(index2);
+            }
+        };
+        schemaAllIndexes = table.getSchemaAllIndexes(false);
+        Assert.assertEquals(2, schemaAllIndexes.size());
+        Assert.assertTrue(schemaAllIndexes.contains(col3));
+        Assert.assertTrue(schemaAllIndexes.contains(col4));
+        Assert.assertFalse(schemaAllIndexes.contains(col1));
+        Assert.assertFalse(schemaAllIndexes.contains(col2));
+
+        new MockUp<OlapTable>() {
+            @Mock
+            public List<MaterializedIndex> getVisibleIndex() {
+                return Lists.newArrayList(index1, index2);
+            }
+        };
+        schemaAllIndexes = table.getSchemaAllIndexes(false);
+        Assert.assertEquals(4, schemaAllIndexes.size());
+        Assert.assertTrue(schemaAllIndexes.contains(col3));
+        Assert.assertTrue(schemaAllIndexes.contains(col4));
+        Assert.assertTrue(schemaAllIndexes.contains(col1));
+        Assert.assertTrue(schemaAllIndexes.contains(col2));
+
+        col1.setIsVisible(false);
+        schemaAllIndexes = table.getSchemaAllIndexes(false);
+        Assert.assertEquals(3, schemaAllIndexes.size());
+        Assert.assertTrue(schemaAllIndexes.contains(col3));
+        Assert.assertTrue(schemaAllIndexes.contains(col4));
+        Assert.assertFalse(schemaAllIndexes.contains(col1));
+        Assert.assertTrue(schemaAllIndexes.contains(col2));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to