diff --git a/fe/fe-core/src/main/java/com/starrocks/statistic/StatisticUtils.java b/fe/fe-core/src/main/java/com/starrocks/statistic/StatisticUtils.java index 561821a135672..c4a36d98b0d8e 100644 --- a/fe/fe-core/src/main/java/com/starrocks/statistic/StatisticUtils.java +++ b/fe/fe-core/src/main/java/com/starrocks/statistic/StatisticUtils.java @@ -368,9 +368,10 @@ public static List getCollectibleColumns(Table table) { isPrimaryEngine = KeysType.PRIMARY_KEYS.equals(((OlapTable) table).getKeysType()); } List columns = new ArrayList<>(); + Set partitionColumns = Sets.newHashSet(table.getPartitionColumnNames()); for (Column column : table.getBaseSchema()) { - // disable stats collection for generated columns - if (column.isGeneratedColumn()) { + // disable stats collection for auto generated columns, see SelectAnalyzer#analyzeSelect + if (column.isGeneratedColumn() && column.getName().startsWith(FeConstants.GENERATED_PARTITION_COLUMN_PREFIX)) { continue; } if (!column.isAggregated()) { diff --git a/fe/fe-core/src/test/java/com/starrocks/statistic/StatisticsCollectJobTest.java b/fe/fe-core/src/test/java/com/starrocks/statistic/StatisticsCollectJobTest.java index a87b53b00e25a..4a9b0471d1304 100644 --- a/fe/fe-core/src/test/java/com/starrocks/statistic/StatisticsCollectJobTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/statistic/StatisticsCollectJobTest.java @@ -1536,7 +1536,7 @@ public long getDataSize() { } @Test - public void testGetCollectibleColumns() throws Exception { + public void testGetCollectibleColumns1() throws Exception { starRocksAssert.withTable("CREATE TABLE test.t_gen_col (" + " c1 datetime NOT NULL," + " c2 bigint," + @@ -1547,8 +1547,23 @@ public void testGetCollectibleColumns() throws Exception { " PROPERTIES('replication_num'='1')"); Table table = starRocksAssert.getTable("test", "t_gen_col"); List cols = StatisticUtils.getCollectibleColumns(table); + Assert.assertTrue(cols.size() == 3); + Assert.assertTrue(cols.contains("c3")); + starRocksAssert.dropTable("test.t_gen_col"); + } + + @Test + public void testGetCollectibleColumns2() throws Exception { + starRocksAssert.withTable("CREATE TABLE test.t_gen_col (" + + " c1 datetime NOT NULL," + + " c2 bigint" + + " ) " + + " DUPLICATE KEY(c1) " + + " PARTITION BY c2, date_trunc('month', c1) " + + " PROPERTIES('replication_num'='1')"); + Table table = starRocksAssert.getTable("test", "t_gen_col"); + List cols = StatisticUtils.getCollectibleColumns(table); Assert.assertTrue(cols.size() == 2); - Assert.assertTrue(!cols.contains("c3")); starRocksAssert.dropTable("test.t_gen_col"); } }