Skip to content

Commit a1f2942

Browse files
committed
fix regression test
1 parent 996994c commit a1f2942

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,8 @@ private boolean isGroupByEquals(Pair<Plan, LogicalAggregate<Plan>> queryTopPlanA
339339
LogicalAggregate<Plan> queryAggregate = queryTopPlanAndAggPair.value();
340340
LogicalAggregate<Plan> viewAggregate = viewTopPlanAndAggPair.value();
341341

342-
Set<Expression> queryGroupShuttledExpression = new HashSet<>();
343-
for (Expression queryExpression : ExpressionUtils.shuttleExpressionWithLineage(
344-
queryAggregate.getGroupByExpressions(), queryTopPlan, queryStructInfo.getTableBitSet())) {
345-
queryGroupShuttledExpression.add(queryExpression);
346-
}
342+
Set<Expression> queryGroupShuttledExpression = new HashSet<>(ExpressionUtils.shuttleExpressionWithLineage(
343+
queryAggregate.getGroupByExpressions(), queryTopPlan, queryStructInfo.getTableBitSet()));
347344

348345
// try to eliminate group by dimension by function dependency if group by expression is not in query
349346
Map<Expression, Expression> viewShuttledExpressionQueryBasedToGroupByExpressionMap = new HashMap<>();
@@ -363,7 +360,7 @@ private boolean isGroupByEquals(Pair<Plan, LogicalAggregate<Plan>> queryTopPlanA
363360
viewGroupExpressionQueryBased
364361
);
365362
}
366-
if (queryGroupShuttledExpression.equals(viewShuttledExpressionQueryBasedToGroupByExpressionMap.values())) {
363+
if (queryGroupShuttledExpression.equals(viewShuttledExpressionQueryBasedToGroupByExpressionMap.keySet())) {
367364
// return true, if equals directly
368365
return true;
369366
}
@@ -378,7 +375,7 @@ private boolean isGroupByEquals(Pair<Plan, LogicalAggregate<Plan>> queryTopPlanA
378375
// check is equals by equal filter eliminate
379376
Optional<LogicalFilter<Plan>> filterOptional = tempRewrittenPlan.collectFirst(LogicalFilter.class::isInstance);
380377
if (!filterOptional.isPresent()) {
381-
return false;
378+
return isGroupByEquals;
382379
}
383380
isGroupByEquals |= isGroupByEqualsAfterEqualFilterEliminate(
384381
(LogicalPlan) tempRewrittenPlan,
@@ -409,6 +406,7 @@ private static boolean isGroupByEqualsAfterEqualFilterEliminate(
409406
return false;
410407
}
411408
Set<Expression> viewShouldUniformExpressionSet = new HashSet<>();
409+
// calc the group by expr which is needed to roll up and should be uniform
412410
for (Map.Entry<Expression, Expression> expressionEntry :
413411
viewShuttledExprQueryBasedToViewGroupByExprMap.entrySet()) {
414412
if (queryGroupShuttledExpression.contains(expressionEntry.getKey())) {

regression-test/data/nereids_rules_p0/mv/agg_optimize_when_uniform/agg_optimize_when_uniform.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ PhysicalResultSink
3838
yy 11.50 11.50 11.50 1
3939

4040
-- !query3_1_before --
41+
mi 56.20 56.20 56.20 1
4142

4243
-- !shape3_1_after --
4344
PhysicalResultSink
4445
--hashAgg[GLOBAL]
4546
----hashAgg[LOCAL]
46-
------filter((cast(o_shippriority as DOUBLE) = cast('a' as DOUBLE)) and (orders.o_orderdate = '2023-12-09') and (orders.o_totalprice = 11.50))
47+
------filter((orders.o_orderdate = '2023-12-12') and (orders.o_shippriority = 2) and (orders.o_totalprice = 56.20))
4748
--------PhysicalOlapScan[orders]
4849

4950
-- !query3_1_after --
51+
mi 56.20 56.20 56.20 1
5052

5153
-- !query4_0_before --
5254
yy 11.50 11.50 11.50 1

regression-test/suites/nereids_rules_p0/mv/agg_optimize_when_uniform/agg_optimize_when_uniform.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ suite("agg_optimize_when_uniform") {
251251
min(o_totalprice),
252252
count(*)
253253
from orders
254-
where o_orderdate = '2023-12-09' and o_shippriority = 'a' and o_totalprice = 11.5
254+
where o_orderdate = '2023-12-12' and o_shippriority = 2 and o_totalprice = 56.2
255255
group by
256256
o_comment;
257257
"""
@@ -290,7 +290,7 @@ suite("agg_optimize_when_uniform") {
290290
"""
291291
order_qt_query4_0_before "${query4_0}"
292292
// query success but add agg
293-
check_mv_rewrite_successs_without_check_chosen(db, mv4_0, query4_0, "mv4_0")
293+
check_mv_rewrite_success_without_check_chosen(db, mv4_0, query4_0, "mv4_0")
294294
qt_shape4_0_after """explain shape plan ${query4_0}"""
295295
order_qt_query4_0_after "${query4_0}"
296296
sql """ DROP MATERIALIZED VIEW IF EXISTS mv4_0"""

regression-test/suites/nereids_rules_p0/mv/agg_without_roll_up/aggregate_without_roll_up.groovy

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ suite("aggregate_without_roll_up") {
155155
min(o_totalprice),
156156
count(*)
157157
from orders
158-
where o_shippriority in (1, 2
158+
where o_shippriority in (1, 2)
159159
group by
160160
o_shippriority,
161161
o_comment;
@@ -247,27 +247,29 @@ suite("aggregate_without_roll_up") {
247247
"group by " +
248248
"O_SHIPPRIORITY, " +
249249
"O_COMMENT "
250-
def query1_2 = "select O_SHIPPRIORITY, O_COMMENT, " +
251-
"count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (1, 3) then O_ORDERSTATUS else null end) as filter_cnt_1, " +
252-
"count(distinct case when O_SHIPPRIORITY > 2 and O_ORDERKEY IN (2) then O_ORDERSTATUS else null end) as filter_cnt_2, " +
253-
"count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (3, 4) then O_ORDERSTATUS else null end) as filter_cnt_3, " +
254-
"count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (2, 3) then O_ORDERSTATUS else null end) as filter_cnt_5, " +
255-
"count(distinct case when O_SHIPPRIORITY > 2 and O_ORDERKEY IN (7, 9) then O_ORDERSTATUS else null end) as filter_cnt_6, " +
256-
"count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (11, 13) then O_ORDERSTATUS else null end) as filter_cnt_8, " +
257-
"count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (12, 11) then O_ORDERSTATUS else null end) as filter_cnt_9, " +
258-
"count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (11, 12) then O_ORDERSTATUS else null end) as filter_cnt_11, " +
259-
"count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (3, 6) then O_ORDERSTATUS else null end) as filter_cnt_12, " +
260-
"count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (16, 19) then O_ORDERSTATUS else null end) as filter_cnt_13, " +
261-
"count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (15, 19) then O_ORDERSTATUS else null end) as filter_cnt_15, " +
262-
"count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (13, 21) then O_ORDERSTATUS else null end) as filter_cnt_16, " +
263-
"count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (16, 25) then O_ORDERSTATUS else null end) as filter_cnt_18, " +
264-
"count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (19, 3) then O_ORDERSTATUS else null end) as filter_cnt_19, " +
265-
"count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (1, 20) then O_ORDERSTATUS else null end) as filter_cnt_20 " +
266-
"from orders " +
267-
"where O_ORDERDATE < '2023-12-30' and O_ORDERDATE > '2023-12-01'" +
268-
"group by " +
269-
"O_SHIPPRIORITY, " +
270-
"O_COMMENT "
250+
def query1_2 = """
251+
select O_SHIPPRIORITY, O_COMMENT,
252+
count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (1, 3) then O_ORDERSTATUS else null end) as filter_cnt_1,
253+
count(distinct case when O_SHIPPRIORITY > 2 and O_ORDERKEY IN (2) then O_ORDERSTATUS else null end) as filter_cnt_2,
254+
count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (3, 4) then O_ORDERSTATUS else null end) as filter_cnt_3,
255+
count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (2, 3) then O_ORDERSTATUS else null end) as filter_cnt_5,
256+
count(distinct case when O_SHIPPRIORITY > 2 and O_ORDERKEY IN (7, 9) then O_ORDERSTATUS else null end) as filter_cnt_6,
257+
count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (11, 13) then O_ORDERSTATUS else null end) as filter_cnt_8,
258+
count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (12, 11) then O_ORDERSTATUS else null end) as filter_cnt_9,
259+
count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (11, 12) then O_ORDERSTATUS else null end) as filter_cnt_11,
260+
count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (3, 6) then O_ORDERSTATUS else null end) as filter_cnt_12,
261+
count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (16, 19) then O_ORDERSTATUS else null end) as filter_cnt_13,
262+
count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (15, 19) then O_ORDERSTATUS else null end) as filter_cnt_15,
263+
count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (13, 21) then O_ORDERSTATUS else null end) as filter_cnt_16,
264+
count(distinct case when O_SHIPPRIORITY > 3 and O_ORDERKEY IN (16, 25) then O_ORDERSTATUS else null end) as filter_cnt_18,
265+
count(distinct case when O_SHIPPRIORITY > 4 and O_ORDERKEY IN (19, 3) then O_ORDERSTATUS else null end) as filter_cnt_19,
266+
count(distinct case when O_SHIPPRIORITY > 1 and O_ORDERKEY IN (1, 20) then O_ORDERSTATUS else null end) as filter_cnt_20
267+
from orders
268+
where O_ORDERDATE < '2023-12-30' and O_ORDERDATE > '2023-12-01'
269+
group by
270+
O_SHIPPRIORITY,
271+
O_COMMENT;
272+
"""
271273
order_qt_query1_2_before "${query1_2}"
272274
check_mv_rewrite_success(db, mv1_2, query1_2, "mv1_2")
273275
order_qt_query1_2_after "${query1_2}"

0 commit comments

Comments
 (0)