From a3fa322bc92e5d7d4f490d231b6ffbeb95eaf294 Mon Sep 17 00:00:00 2001 From: yb0 Date: Wed, 16 Feb 2022 19:22:12 +0800 Subject: [PATCH] modify large stack variable to heap variable for pwj compare --- src/sql/plan_cache/ob_dist_plans.cpp | 90 +++++++++++++++------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/src/sql/plan_cache/ob_dist_plans.cpp b/src/sql/plan_cache/ob_dist_plans.cpp index 4702293de..d128cda89 100644 --- a/src/sql/plan_cache/ob_dist_plans.cpp +++ b/src/sql/plan_cache/ob_dist_plans.cpp @@ -593,51 +593,55 @@ int ObDistPlans::check_inner_constraints(const ObIArray& st if (strict_cons.count() > 0 || non_strict_cons.count() > 0) { const int64_t tbl_count = phy_tbl_infos.count(); ObSEArray pwj_tables; - ObPwjComparer strict_pwj_comparer(true); - ObPwjComparer non_strict_pwj_comparer(false); - if (OB_FAIL(pwj_tables.prepare_allocate(tbl_count))) { - LOG_WARN("failed to prepare allocate pwj tables", K(ret)); - } - - /* Traverse strict pwj constraints and non-strict pwj constraints, and generate a partition id - * mapping that can do partition wise join. - * Because there may be constraints in the following forms - * strict_pwj_cons = [0,1], [2,3] - * non_strict_pwj_cons = [0,2] - * If you traverse strict_pwj_cons first, and then traverse non_strict_pwj_cons, there may be a situation: - * After traversing strict_pwj_cons, the mapping of [part_array0, part_array1, part_array2, part_array3] is set in - * pwj_map, But when traversing non_strict_pwj_cons, it is found that partition_array2 needs to be adjusted, then - * all the arrays related to it must be adjusted recursively, The adjustment is very complicated. Traverse in - * strict_pwj_cons and non_strict_pwj_cons separately in the order of the base table to avoid this situation: - * Traverse all constraints starting with 0, and set the mapping of [part_array0, part_array1, part_array2] in - * pwj_map; Traverse all the constraints starting with 1, and find that there are no related constraints; To - * traverse all constraints starting with 2, you need to set part_array3 in pwj_map, because part_array2 has been - * set, so The mapping of part_array3 generated by part_array2 does not need to be adjusted Traverse all the - * constraints starting with 3 and find that there are no related constraints - */ - for (int64_t i = 0; OB_SUCC(ret) && i < tbl_count; ++i) { - for (int64_t j = 0; OB_SUCC(ret) && j < strict_cons.count(); ++j) { - const ObPlanPwjConstraint& pwj_cons = strict_cons.at(j); - if (OB_UNLIKELY(pwj_cons.count() <= 1)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("get unexpected pwj constraint", K(ret), K(pwj_cons)); - } else if (pwj_cons.at(0) == i) { - if (OB_FAIL( - check_pwj_cons(pc_ctx, pwj_cons, phy_tbl_infos, pwj_tables, strict_pwj_comparer, pwj_map, is_same))) { - LOG_WARN("failed to check pwj cons", K(ret)); - } + HEAP_VAR(ObPwjComparer, strict_pwj_comparer, true) + { + HEAP_VAR(ObPwjComparer, non_strict_pwj_comparer, false) + { + if (OB_FAIL(pwj_tables.prepare_allocate(tbl_count))) { + LOG_WARN("failed to prepare allocate pwj tables", K(ret)); } - } - for (int64_t j = 0; OB_SUCC(ret) && j < non_strict_cons.count(); ++j) { - const ObPlanPwjConstraint& pwj_cons = non_strict_cons.at(j); - if (OB_UNLIKELY(pwj_cons.count() <= 1)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("get unexpected pwj constraint", K(ret), K(pwj_cons)); - } else if (pwj_cons.at(0) == i) { - if (OB_FAIL(check_pwj_cons( - pc_ctx, pwj_cons, phy_tbl_infos, pwj_tables, non_strict_pwj_comparer, pwj_map, is_same))) { - LOG_WARN("failed to check pwj cons", K(ret)); + /* Traverse strict pwj constraints and non-strict pwj constraints, and generate a partition id + * mapping that can do partition wise join. + * Because there may be constraints in the following forms + * strict_pwj_cons = [0,1], [2,3] + * non_strict_pwj_cons = [0,2] + * If you traverse strict_pwj_cons first, and then traverse non_strict_pwj_cons, there may be a situation: + * After traversing strict_pwj_cons, the mapping of [part_array0, part_array1, part_array2, part_array3] is set in + * pwj_map, But when traversing non_strict_pwj_cons, it is found that partition_array2 needs to be adjusted, then + * all the arrays related to it must be adjusted recursively, The adjustment is very complicated. Traverse in + * strict_pwj_cons and non_strict_pwj_cons separately in the order of the base table to avoid this situation: + * Traverse all constraints starting with 0, and set the mapping of [part_array0, part_array1, part_array2] in + * pwj_map; Traverse all the constraints starting with 1, and find that there are no related constraints; To + * traverse all constraints starting with 2, you need to set part_array3 in pwj_map, because part_array2 has been + * set, so The mapping of part_array3 generated by part_array2 does not need to be adjusted Traverse all the + * constraints starting with 3 and find that there are no related constraints + */ + for (int64_t i = 0; OB_SUCC(ret) && i < tbl_count; ++i) { + for (int64_t j = 0; OB_SUCC(ret) && j < strict_cons.count(); ++j) { + const ObPlanPwjConstraint& pwj_cons = strict_cons.at(j); + if (OB_UNLIKELY(pwj_cons.count() <= 1)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected pwj constraint", K(ret), K(pwj_cons)); + } else if (pwj_cons.at(0) == i) { + if (OB_FAIL(check_pwj_cons( + pc_ctx, pwj_cons, phy_tbl_infos, pwj_tables, strict_pwj_comparer, pwj_map, is_same))) { + LOG_WARN("failed to check pwj cons", K(ret)); + } + } + } + + for (int64_t j = 0; OB_SUCC(ret) && j < non_strict_cons.count(); ++j) { + const ObPlanPwjConstraint& pwj_cons = non_strict_cons.at(j); + if (OB_UNLIKELY(pwj_cons.count() <= 1)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected pwj constraint", K(ret), K(pwj_cons)); + } else if (pwj_cons.at(0) == i) { + if (OB_FAIL(check_pwj_cons( + pc_ctx, pwj_cons, phy_tbl_infos, pwj_tables, non_strict_pwj_comparer, pwj_map, is_same))) { + LOG_WARN("failed to check pwj cons", K(ret)); + } + } } } }