diff --git a/deps/oblib/src/lib/utility/ob_tracepoint.h b/deps/oblib/src/lib/utility/ob_tracepoint.h index 794813a8b3..f426aab9a8 100644 --- a/deps/oblib/src/lib/utility/ob_tracepoint.h +++ b/deps/oblib/src/lib/utility/ob_tracepoint.h @@ -672,6 +672,8 @@ class EventTable EN_FETCH_TABLE_INFO_RPC = 1112, // END OF STORAGE HA - 1101 - 2000 + EN_ENABLE_NEWSORT_FORCE = 1200, + // Transaction // 2001 - 2100 // Transaction free route EN_TX_FREE_ROUTE_UPDATE_STATE_ERROR = 2001, diff --git a/src/sql/optimizer/ob_log_plan.cpp b/src/sql/optimizer/ob_log_plan.cpp index 81dee07256..6783a9a684 100644 --- a/src/sql/optimizer/ob_log_plan.cpp +++ b/src/sql/optimizer/ob_log_plan.cpp @@ -6115,6 +6115,7 @@ int ObLogPlan::create_three_stage_group_plan(const ObIArray &group_b AggregateAlgo second_aggr_algo; AggregateAlgo third_aggr_algo; bool can_sort_opt = true; + ObLogicalOperator *child = NULL; // 1. prepare to allocate the first group by if (OB_ISNULL(top)) { @@ -6186,7 +6187,7 @@ int ObLogPlan::create_three_stage_group_plan(const ObIArray &group_b rd_second_sort_keys))) { LOG_WARN("failed to make sort keys", K(ret)); } else if (OB_FAIL(ObOptimizerUtil::check_can_encode_sortkey(rd_second_sort_keys, - can_sort_opt, *this))) { + can_sort_opt, *this, top->get_card()))) { LOG_WARN("failed to check encode sortkey expr", K(ret)); } else if (false && (OB_FAIL(ObSQLUtils::create_encode_sortkey_expr(get_optimizer_context().get_expr_factory(), diff --git a/src/sql/optimizer/ob_log_sort.cpp b/src/sql/optimizer/ob_log_sort.cpp index 20fadd56e9..9272eaef39 100644 --- a/src/sql/optimizer/ob_log_sort.cpp +++ b/src/sql/optimizer/ob_log_sort.cpp @@ -86,8 +86,10 @@ int ObLogSort::get_sort_exprs(common::ObIArray &sort_exprs) int ObLogSort::get_op_exprs(ObIArray &all_exprs) { int ret = OB_SUCCESS; + ObLogicalOperator *child = NULL; bool can_sort_opt = true; - if (OB_ISNULL(get_plan())) { + if (OB_ISNULL(get_plan()) || + OB_ISNULL(child = get_child(ObLogicalOperator::first_child))) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(ret)); } else if (NULL != topn_expr_ && OB_FAIL(all_exprs.push_back(topn_expr_))) { @@ -97,7 +99,7 @@ int ObLogSort::get_op_exprs(ObIArray &all_exprs) } else if (NULL != topk_offset_expr_ && OB_FAIL(all_exprs.push_back(topk_offset_expr_))) { LOG_WARN("failed to push back expr", K(ret)); } else if (OB_FAIL(ObOptimizerUtil::check_can_encode_sortkey(sort_keys_, - can_sort_opt, *get_plan()))) { + can_sort_opt, *get_plan(), child->get_card()))) { LOG_WARN("failed to check encode sortkey expr", K(ret)); } else if (NULL != topn_expr_ && FALSE_IT(can_sort_opt = false)) { // do nothing @@ -422,4 +424,4 @@ int ObLogSort::compute_op_ordering() is_local_order_ = false; } return ret; -} \ No newline at end of file +} diff --git a/src/sql/optimizer/ob_optimizer_util.cpp b/src/sql/optimizer/ob_optimizer_util.cpp index fbf1345623..1d1fd15abd 100644 --- a/src/sql/optimizer/ob_optimizer_util.cpp +++ b/src/sql/optimizer/ob_optimizer_util.cpp @@ -8088,7 +8088,8 @@ int ObOptimizerUtil::get_minset_of_exprs(const ObIArray &src_exprs, int ObOptimizerUtil::check_can_encode_sortkey(const common::ObIArray &order_keys, bool &can_sort_opt, - ObLogPlan& plan) + ObLogPlan& plan, + double card) { int ret = OB_SUCCESS; ObSEArray sort_keys; @@ -8126,9 +8127,19 @@ int ObOptimizerUtil::check_can_encode_sortkey(const common::ObIArray LOG_WARN("failed to estimate width for output join column exprs", K(ret)); } else if (avg_len > 256) { can_sort_opt = false; + } else if (avg_len < 64 && card < 100000) { + can_sort_opt = false; + } else if (avg_len > 64 && avg_len < 128 && card < 1500000 ) { + can_sort_opt = false; } else { // do nothing } + + int tmp_ret = OB_SUCCESS; + tmp_ret = OB_E(EventTable::EN_ENABLE_NEWSORT_FORCE) OB_SUCCESS; + if (OB_SUCCESS != tmp_ret) { + can_sort_opt = true; + } } return ret; } diff --git a/src/sql/optimizer/ob_optimizer_util.h b/src/sql/optimizer/ob_optimizer_util.h index 97e9a318d3..f2d03d9c92 100644 --- a/src/sql/optimizer/ob_optimizer_util.h +++ b/src/sql/optimizer/ob_optimizer_util.h @@ -1380,7 +1380,8 @@ public: static int check_can_encode_sortkey(const common::ObIArray &order_keys, bool &can_sort_opt, - ObLogPlan& plan); + ObLogPlan& plan, + double card); static int extract_equal_join_conditions(const ObIArray &equal_join_conditions, const ObRelIds &left_tables, diff --git a/src/sql/optimizer/ob_select_log_plan.cpp b/src/sql/optimizer/ob_select_log_plan.cpp index 2c0d67f3dd..0b2008f526 100644 --- a/src/sql/optimizer/ob_select_log_plan.cpp +++ b/src/sql/optimizer/ob_select_log_plan.cpp @@ -586,7 +586,10 @@ int ObSelectLogPlan::create_rollup_pushdown_plan(const ObIArray &gro ObLogGroupBy *rollup_distributor = NULL; ObLogGroupBy *rollup_collector = NULL; bool can_sort_opt = true; - if (OB_FAIL(append(pre_group_exprs, group_by_exprs)) || + if (OB_ISNULL(top)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected null", K(ret)); + } else if (OB_FAIL(append(pre_group_exprs, group_by_exprs)) || OB_FAIL(append(pre_group_exprs, rollup_exprs))) { LOG_WARN("failed to append pre group exprs", K(ret)); } else if (OB_FAIL(allocate_group_by_as_top(top, @@ -624,7 +627,7 @@ int ObSelectLogPlan::create_rollup_pushdown_plan(const ObIArray &gro rd_sort_keys))) { LOG_WARN("failed to make sort keys", K(ret)); } else if (OB_FAIL(ObOptimizerUtil::check_can_encode_sortkey(rd_sort_keys, - can_sort_opt, *this))) { + can_sort_opt, *this, top->get_card()))) { LOG_WARN("failed to check encode sortkey expr", K(ret)); } else if (false && (OB_FAIL(ObSQLUtils::create_encode_sortkey_expr(get_optimizer_context().get_expr_factory(), diff --git a/tools/deploy/mysql_test/test_suite/join/r/mysql/anti_semi_join.result b/tools/deploy/mysql_test/test_suite/join/r/mysql/anti_semi_join.result index 2f833ec90c..5ad901080f 100644 --- a/tools/deploy/mysql_test/test_suite/join/r/mysql/anti_semi_join.result +++ b/tools/deploy/mysql_test/test_suite/join/r/mysql/anti_semi_join.result @@ -708,14 +708,14 @@ select /*+use_merge(xy_x_t xy_y_t)*/ * from xy_x_t where x1 in (select y1 from x +------+------------+ | 0 | yzh | | 2 | think | -| 2 | VZLUW | | 2 | want | +| 2 | VZLUW | | 2 | it's | -| 6 | u | | 6 | uyslpcybda | +| 6 | u | +| 9 | TBMEI | | 9 | QPPLC | | 9 | mdsl | -| 9 | TBMEI | +------+------------+ EXPLAIN select /*+use_nl(xy_x_t xy_y_t)*/ * from xy_x_t where x1 in (select y1 from xy_y_t where y2 < xy_x_t.x2); Query Plan @@ -904,29 +904,29 @@ select /*+use_merge(xy_x_t xy_y_t)*/ * from xy_x_t where x1 not in (select y1 fr | 1 | TQOYB | | 1 | FFHTJ | | 2 | ezcuilyxac | -| 3 | get | | 3 | prsazev | +| 3 | get | | 3 | out | +| 4 | a | | 4 | PVYPZ | | 4 | k | | 4 | bpqswbeyqj | | 4 | isjn | | 4 | that's | | 4 | well | -| 4 | a | -| 5 | with | -| 5 | w | -| 5 | arkyz | -| 5 | just | | 5 | PFBCU | +| 5 | just | +| 5 | with | +| 5 | arkyz | +| 5 | w | | 6 | co | | 6 | j | | 6 | g | | 7 | cybdark | | 7 | BKWPE | -| 8 | lmdsl | | 8 | NNIGT | | 8 | of | +| 8 | lmdsl | | 9 | etu | | 27262976 | n | | 162267136 | to | @@ -1314,6 +1314,10 @@ select /*+ use_merge(xy_t1 xy_t2)*/ * from xy_t1 where exists (select 1 from xy_ | 3 | 3 | | 3 | 3 | | 3 | 3 | +| 5 | 7 | +| 5 | 7 | +| 5 | 5 | +| 5 | 5 | | 5 | 5 | | 5 | 5 | | 5 | 5 | @@ -1322,12 +1326,9 @@ select /*+ use_merge(xy_t1 xy_t2)*/ * from xy_t1 where exists (select 1 from xy_ | 5 | 5 | | 5 | 5 | | 5 | 7 | -| 5 | 5 | -| 5 | 5 | -| 5 | 7 | -| 5 | 7 | | 6 | NULL | | 6 | 7 | +| 6 | NULL | | 6 | 6 | | 6 | 7 | | 6 | 6 | @@ -1335,17 +1336,16 @@ select /*+ use_merge(xy_t1 xy_t2)*/ * from xy_t1 where exists (select 1 from xy_ | 6 | 7 | | 6 | 6 | | 6 | NULL | -| 6 | 7 | | 6 | 6 | -| 6 | NULL | +| 6 | 7 | | 9 | 7 | | 9 | 0 | -| 9 | 7 | | 9 | 0 | | 9 | 7 | -| 9 | 0 | | 9 | 7 | | 9 | 0 | +| 9 | 0 | +| 9 | 7 | +------+------+ EXPLAIN select /*+ no_rewrite */ * from xy_t1 where exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1); Query Plan @@ -2155,33 +2155,33 @@ select /*+ use_merge(xy_t1 xy_t2)*/ * from xy_t1 where not exists (select 1 from | 0 | 0 | | 0 | 0 | | 2 | NULL | +| 2 | NULL | +| 2 | 2 | | 2 | 2 | | 2 | 2 | | 2 | 2 | | 2 | NULL | -| 2 | 2 | | 2 | NULL | -| 2 | NULL | -| 7 | 0 | -| 7 | 0 | -| 7 | 7 | -| 7 | 0 | | 7 | 7 | | 7 | 0 | | 7 | 7 | | 7 | 7 | -| 8 | 8 | +| 7 | 0 | +| 7 | 0 | +| 7 | 7 | +| 7 | 0 | | 8 | 5 | +| 8 | 5 | +| 8 | 5 | +| 8 | 8 | +| 8 | 0 | +| 8 | 0 | +| 8 | 0 | +| 8 | 5 | +| 8 | 8 | +| 8 | 8 | | 8 | 0 | | 8 | 8 | -| 8 | 5 | -| 8 | 0 | -| 8 | 8 | -| 8 | 5 | -| 8 | 0 | -| 8 | 8 | -| 8 | 5 | -| 8 | 0 | | 10 | 10 | | 10 | 10 | | 10 | 10 |