branch-2.1: [fix](mv)Fix direct select mv pre agg bug. #47658 (#47700)

Cherry-picked from #47658

Co-authored-by: James <lijibing@selectdb.com>
This commit is contained in:
github-actions[bot]
2025-02-10 21:45:00 +08:00
committed by GitHub
parent 470030b878
commit 6ceb010195
3 changed files with 28 additions and 1 deletions

View File

@ -251,7 +251,9 @@ public class BindRelation extends OneAnalysisRuleFactory {
List<Slot> childOutputSlots = olapScan.computeOutput();
List<Expression> groupByExpressions = new ArrayList<>();
List<NamedExpression> outputExpressions = new ArrayList<>();
List<Column> columns = olapTable.getBaseSchema();
List<Column> columns = olapScan.isIndexSelected()
? olapTable.getSchemaByIndexId(olapScan.getSelectedIndexId())
: olapTable.getBaseSchema();
for (Column col : columns) {
// use exist slot in the plan

View File

@ -0,0 +1,6 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !test_agg --
1 6
2 9
3 6

View File

@ -792,6 +792,25 @@ suite("test_analyze_mv") {
assertEquals("1", result[0][7])
assertEquals("5", result[0][8])
sql """drop table if exists testMvDirectSelect"""
sql """
CREATE TABLE testMvDirectSelect (
key1 int NOT NULL,
key2 int NOT NULL,
value int SUM
)ENGINE=OLAP
AGGREGATE KEY(key1, key2)
COMMENT "OLAP"
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES (
"replication_num" = "1"
);
"""
createMV("CREATE MATERIALIZED VIEW aggMv as select key1, SUM(value) from testMvDirectSelect group by key1;")
sql """insert into testMvDirectSelect values (1, 1, 1), (1, 2, 2), (1, 3, 3), (2, 1, 4), (2, 2, 5), (3, 2, 6)"""
qt_test_agg """select * from testMvDirectSelect index aggMv order by mv_key1"""
sql """drop database if exists test_analyze_mv"""
}