Skip to content

Commit

Permalink
[fix](mtmv) Fix get mv statistics plan wrong and optimize code usage (a…
Browse files Browse the repository at this point in the history
…pache#35623)

1. get mv statistics, the relation id should be getted from scan plan,
fix it.
2. optimize the `isGroupEquals` method, add `MaterializationContext`
param which maybe used to control the decide group by equals logic.
3. remove `set enable_nereids_timeout = false;` setting in mv rewrite
regression test.
  • Loading branch information
seawinde authored and Doris-Extras committed May 30, 2024
1 parent 8f264a7 commit 34d27dd
Show file tree
Hide file tree
Showing 61 changed files with 6 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
// Firstly,if group by expression between query and view is equals, try to rewrite expression directly
Plan queryTopPlan = queryTopPlanAndAggPair.key();
if (isGroupByEquals(queryTopPlanAndAggPair, viewTopPlanAndAggPair, viewToQuerySlotMapping, queryStructInfo,
viewStructInfo)) {
viewStructInfo, materializationContext)) {
List<Expression> rewrittenQueryExpressions = rewriteExpression(queryTopPlan.getOutput(),
queryTopPlan,
materializationContext.getExprToScanExprMapping(),
Expand Down Expand Up @@ -253,7 +253,8 @@ private boolean isGroupByEquals(Pair<Plan, LogicalAggregate<Plan>> queryTopPlanA
Pair<Plan, LogicalAggregate<Plan>> viewTopPlanAndAggPair,
SlotMapping viewToQuerySlotMapping,
StructInfo queryStructInfo,
StructInfo viewStructInfo) {
StructInfo viewStructInfo,
MaterializationContext materializationContext) {
Plan queryTopPlan = queryTopPlanAndAggPair.key();
Plan viewTopPlan = viewTopPlanAndAggPair.key();
LogicalAggregate<Plan> queryAggregate = queryTopPlanAndAggPair.value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public Optional<Pair<Id, Statistics>> getPlanStatistics(CascadesContext cascades
return Optional.empty();
}
RelationId relationId = null;
List<Object> scanObjs = this.getPlan().collectFirst(plan -> plan instanceof LogicalOlapScan);
if (scanObjs != null && !scanObjs.isEmpty()) {
relationId = ((LogicalOlapScan) scanObjs.get(0)).getRelationId();
List<LogicalOlapScan> logicalOlapScan = this.getScanPlan().collectFirst(LogicalOlapScan.class::isInstance);
if (!logicalOlapScan.isEmpty()) {
relationId = logicalOlapScan.get(0).getRelationId();
}
return Optional.of(Pair.of(relationId, mtmvCache.getStatistics()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ suite("aggregate_with_roll_up") {
sql "SET ignore_shape_nodes='PhysicalDistribute,PhysicalProject'"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ suite("grace_period") {
sql "set runtime_filter_mode=OFF"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_partition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ suite("partition_mv_rewrite_dimension_1") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_3") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_4") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_5") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_6") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_full_join") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_full_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_2") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_left_anti_join") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_left_anti_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_1") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_left_semi_join") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_left_semi_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_right_anti_join") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_right_anti_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_right_join") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_right_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ suite("partition_mv_rewrite_dimension_2_right_semi_join") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_2_right_semi_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ suite("partition_mv_rewrite_dimension_self_conn") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_self_conn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ suite("dimension_2_join_agg_replenish") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ suite("filter_equal_or_notequal_case") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ suite("mv_contain_external_table", "p0,external,hive,external_docker,external_do
sql "SET ignore_shape_nodes='PhysicalDistribute,PhysicalProject'"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=true"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists lineitem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("cross_join_list_str_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_cross_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("cross_join_range_date_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_cross_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("cross_join_range_number_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_cross_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("full_join_list_str_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_full_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("full_join_range_date_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_full_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("full_join_range_number_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_full_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("inner_join_list_str_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_inner_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("inner_join_range_date_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_inner_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("inner_join_range_number_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_inner_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("left_anti_join_list_str_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_left_anti_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("left_anti_join_range_date_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_left_anti_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("left_anti_join_range_number_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_left_anti_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("left_join_list_str_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_left_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("left_join_range_date_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_left_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("left_join_range_number_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_left_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("left_semi_join_list_str_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_left_semi_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("left_semi_join_range_date_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_left_semi_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("left_semi_join_range_number_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_left_semi_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("right_anti_join_list_str_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_right_anti_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("right_anti_join_range_date_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_right_anti_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("right_anti_join_range_number_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_right_anti_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("right_join_list_str_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_right_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("right_join_range_date_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_right_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("right_join_range_number_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_right_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("right_semi_join_list_str_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_right_semi_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("right_semi_join_range_date_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_right_semi_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ suite("right_semi_join_range_number_increment_create") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql "SET enable_materialized_view_rewrite=false"
sql "SET enable_nereids_timeout = false"

sql """
drop table if exists orders_right_semi_3
Expand Down
Loading

0 comments on commit 34d27dd

Please sign in to comment.