From 4f890f0a8c5859870d3b9bd11efaa87ea82531b3 Mon Sep 17 00:00:00 2001 From: sdc Date: Tue, 30 May 2023 13:47:29 +0000 Subject: [PATCH] fix granule iterator generate T_PDML_PARTITION_ID expr bug --- src/sql/engine/px/ob_granule_iterator_op.cpp | 2 +- src/sql/engine/px/ob_granule_iterator_op.h | 1 + src/sql/engine/table/ob_table_scan_op.cpp | 6 +++++- src/sql/optimizer/ob_log_granule_iterator.cpp | 16 +++++++++++++--- src/sql/optimizer/ob_log_granule_iterator.h | 1 + .../test_suite/px/r/mysql/add_material.result | 4 ++-- .../test_suite/px/r/mysql/dml_use_px.result | 14 +++++++------- .../static_engine/r/mysql/px_basic.result | 2 +- 8 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/sql/engine/px/ob_granule_iterator_op.cpp b/src/sql/engine/px/ob_granule_iterator_op.cpp index 5c25125c5..559868bac 100644 --- a/src/sql/engine/px/ob_granule_iterator_op.cpp +++ b/src/sql/engine/px/ob_granule_iterator_op.cpp @@ -695,7 +695,6 @@ int ObGranuleIteratorOp::do_join_filter_partition_pruning( if (OB_SUCC(ret) && OB_NOT_NULL(rf_msg_) && rf_msg_->check_ready()) { uint64_t hash_val = ObExprJoinFilter::JOIN_FILTER_SEED; - ObDatum &datum = MY_SPEC.tablet_id_expr_->locate_expr_datum(eval_ctx_); if (MY_SPEC.bf_info_.skip_subpart_) { int64_t part_id = OB_INVALID_ID; if (OB_FAIL(try_build_tablet2part_id_map())) { @@ -707,6 +706,7 @@ int ObGranuleIteratorOp::do_join_filter_partition_pruning( } } if (OB_SUCC(ret) && !is_match) { + ObDatum datum; datum.int_ = &tablet_id; datum.len_ = sizeof(tablet_id); ObRFBloomFilterMsg *bf_msg = static_cast(rf_msg_); diff --git a/src/sql/engine/px/ob_granule_iterator_op.h b/src/sql/engine/px/ob_granule_iterator_op.h index 74ebc1691..85c306321 100644 --- a/src/sql/engine/px/ob_granule_iterator_op.h +++ b/src/sql/engine/px/ob_granule_iterator_op.h @@ -127,6 +127,7 @@ public: // for partition join filter ObPxBFStaticInfo bf_info_; ObHashFunc hash_func_; + //TODO: shanting. remove this expr in 4.3 ObExpr *tablet_id_expr_; // end for partition join filter int64_t repart_pruning_tsc_idx_; diff --git a/src/sql/engine/table/ob_table_scan_op.cpp b/src/sql/engine/table/ob_table_scan_op.cpp index 060904248..573ec149c 100644 --- a/src/sql/engine/table/ob_table_scan_op.cpp +++ b/src/sql/engine/table/ob_table_scan_op.cpp @@ -953,7 +953,11 @@ int ObTableScanOp::update_output_tablet_id() } else { data_tablet_loc = scan_result_.get_tablet_loc(); } - if (OB_NOT_NULL(data_tablet_loc)) { + if (OB_ISNULL(data_tablet_loc)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("data tablet loc is null, value of pdml partition id will not be set", K(ret), + K(MY_SPEC.should_scan_index()), K(MY_SPEC.ref_table_id_)); + } else { if (MY_SPEC.partition_id_calc_type_ == 0) { output_id = data_tablet_loc->tablet_id_.id(); } else if (MY_SPEC.partition_id_calc_type_ == 1) { diff --git a/src/sql/optimizer/ob_log_granule_iterator.cpp b/src/sql/optimizer/ob_log_granule_iterator.cpp index 7ad9b8a5a..4a0c9ed41 100644 --- a/src/sql/optimizer/ob_log_granule_iterator.cpp +++ b/src/sql/optimizer/ob_log_granule_iterator.cpp @@ -58,9 +58,7 @@ const char *ObLogGranuleIterator::get_name() const int ObLogGranuleIterator::get_op_exprs(ObIArray &all_exprs) { int ret = OB_SUCCESS; - if (NULL != tablet_id_expr_ && OB_FAIL(all_exprs.push_back(tablet_id_expr_))) { - LOG_WARN("failed to append expr", K(ret)); - } else if (OB_FAIL(ObLogicalOperator::get_op_exprs(all_exprs))) { + if (OB_FAIL(ObLogicalOperator::get_op_exprs(all_exprs))) { LOG_WARN("failed to get exprs", K(ret)); } else { /*do nothing*/ } return ret; @@ -113,6 +111,18 @@ int ObLogGranuleIterator::get_plan_item_info(PlanText &plan_text, return ret; } +int ObLogGranuleIterator::allocate_expr_post(ObAllocExprContext &ctx) +{ + int ret = OB_SUCCESS; + if (OB_FAIL(ObLogicalOperator::allocate_expr_post(ctx))) { + LOG_WARN("failed to allocate expr post", K(ret)); + } else if (NULL != tablet_id_expr_ && + OB_FAIL(get_plan()->get_optimizer_context().get_all_exprs().append(tablet_id_expr_))) { + LOG_WARN("failed to append expr", K(ret)); + } + return ret; +} + int ObLogGranuleIterator::compute_op_ordering() { int ret = OB_SUCCESS; diff --git a/src/sql/optimizer/ob_log_granule_iterator.h b/src/sql/optimizer/ob_log_granule_iterator.h index 6269c0622..659f84ad4 100644 --- a/src/sql/optimizer/ob_log_granule_iterator.h +++ b/src/sql/optimizer/ob_log_granule_iterator.h @@ -80,6 +80,7 @@ public: int64_t get_repartition_ref_table_id() { return repartition_ref_table_id_; } virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; + virtual int allocate_expr_post(ObAllocExprContext &ctx) override; void set_used_by_external_table() { used_by_external_table_ = true; } bool is_used_by_external_table() const { return used_by_external_table_; } diff --git a/tools/deploy/mysql_test/test_suite/px/r/mysql/add_material.result b/tools/deploy/mysql_test/test_suite/px/r/mysql/add_material.result index 3360ba924..fb8a804e0 100644 --- a/tools/deploy/mysql_test/test_suite/px/r/mysql/add_material.result +++ b/tools/deploy/mysql_test/test_suite/px/r/mysql/add_material.result @@ -44,7 +44,7 @@ Outputs & filters: 7 - output([t2.c1]), filter(nil), rowset=256 (#keys=1, [t2.c1]), dop=3 8 - output([t2.c1]), filter(nil), rowset=256 - 9 - output([t2.c1], [PARTITION_ID]), filter(nil), rowset=256 + 9 - output([t2.c1]), filter(nil), rowset=256 access([t2.c1]), partitions(p[0-5]) is_index_back=false, is_global_index=false, range_key([t2.c1]), range(MIN ; MAX)always true @@ -110,7 +110,7 @@ Outputs & filters: range_key([b.c1]), range(MIN ; MAX)always true 12 - output([a.c1], [a.c2]), filter(nil), rowset=256 affinitize - 13 - output([a.c1], [a.c2], [PARTITION_ID]), filter(nil), rowset=256 + 13 - output([a.c1], [a.c2]), filter(nil), rowset=256 access([a.c1], [a.c2]), partitions(p[0-9]) is_index_back=false, is_global_index=false, range_key([a.c1]), range(MIN ; MAX)always true diff --git a/tools/deploy/mysql_test/test_suite/px/r/mysql/dml_use_px.result b/tools/deploy/mysql_test/test_suite/px/r/mysql/dml_use_px.result index 21ab9094e..f06aa7da4 100644 --- a/tools/deploy/mysql_test/test_suite/px/r/mysql/dml_use_px.result +++ b/tools/deploy/mysql_test/test_suite/px/r/mysql/dml_use_px.result @@ -371,7 +371,7 @@ Outputs & filters: range_key([t_p4.c1]), range[5 ; MAX), range_cond([t_p4.c1 >= 5]) 9 - output([t_p.c1], [t_p.c2], [t_p.c3]), filter(nil), rowset=256 - 10 - output([t_p.c1], [t_p.c2], [t_p.c3], [PARTITION_ID]), filter(nil), rowset=256 + 10 - output([t_p.c1], [t_p.c2], [t_p.c3]), filter(nil), rowset=256 access([t_p.c1], [t_p.c2], [t_p.c3]), partitions(p[0-3]) is_index_back=false, is_global_index=false, range_key([t_p.c1]), range[5 ; MAX), @@ -427,7 +427,7 @@ Outputs & filters: is_index_back=false, is_global_index=false, filter_before_indexback[false], range_key([t_p4.c1]), range(MIN ; MAX)always true 9 - output([t_p.c1], [t_p.c2], [t_p.c3]), filter(nil), rowset=256 - 10 - output([t_p.c1], [t_p.c2], [t_p.c3], [PARTITION_ID]), filter(nil), rowset=256 + 10 - output([t_p.c1], [t_p.c2], [t_p.c3]), filter(nil), rowset=256 access([t_p.c1], [t_p.c2], [t_p.c3]), partitions(p[0-3]) is_index_back=false, is_global_index=false, range_key([t_p.c1]), range[5 ; MAX), @@ -469,7 +469,7 @@ Outputs & filters: is_index_back=false, is_global_index=false, filter_before_indexback[false], range_key([t_p4.c1]), range(MIN ; MAX)always true 9 - output([t_p.c1], [t_p.c2], [t_p.c3]), filter(nil), rowset=256 - 10 - output([t_p.c1], [t_p.c2], [t_p.c3], [PARTITION_ID]), filter(nil), rowset=256 + 10 - output([t_p.c1], [t_p.c2], [t_p.c3]), filter(nil), rowset=256 access([t_p.c1], [t_p.c2], [t_p.c3]), partitions(p[0-3]) is_index_back=false, is_global_index=false, range_key([t_p.c1]), range[5 ; MAX), @@ -661,7 +661,7 @@ Outputs & filters: 8 - output([t_p.c1]), filter(nil), rowset=256 dop=10 9 - output([t_p.c1]), filter(nil), rowset=256 - 10 - output([t_p.c1], [PARTITION_ID]), filter(nil), rowset=256 + 10 - output([t_p.c1]), filter(nil), rowset=256 access([t_p.c1]), partitions(p[0-3]) is_index_back=false, is_global_index=false, range_key([t_p.c1]), range(MIN ; MAX)always true @@ -1948,7 +1948,7 @@ Outputs & filters: is_index_back=false, is_global_index=false, range_key([t_temp_p5.__pk_increment]), range(MIN ; MAX)always true 10 - output([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3]), filter(nil), rowset=256 - 11 - output([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3], [PARTITION_ID]), filter(nil), rowset=256 + 11 - output([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3]), filter(nil), rowset=256 access([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3]), partitions(p[0-3]) is_index_back=false, is_global_index=false, range_key([t_temp_p.__pk_increment]), range(MIN ; MAX)always true @@ -1994,7 +1994,7 @@ Outputs & filters: is_index_back=false, is_global_index=false, range_key([t_temp_p5.__pk_increment]), range(MIN ; MAX)always true 10 - output([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3]), filter(nil), rowset=256 - 11 - output([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3], [PARTITION_ID]), filter(nil), rowset=256 + 11 - output([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3]), filter(nil), rowset=256 access([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3]), partitions(p[0-3]) is_index_back=false, is_global_index=false, range_key([t_temp_p.__pk_increment]), range(MIN ; MAX)always true @@ -2114,7 +2114,7 @@ Outputs & filters: is_index_back=false, is_global_index=false, range_key([t_temp_p4.__pk_increment]), range(MIN ; MAX)always true 10 - output([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3]), filter(nil), rowset=256 - 11 - output([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3], [PARTITION_ID]), filter(nil), rowset=256 + 11 - output([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3]), filter(nil), rowset=256 access([t_temp_p.c1], [t_temp_p.c2], [t_temp_p.c3]), partitions(p[0-3]) is_index_back=false, is_global_index=false, range_key([t_temp_p.__pk_increment]), range(MIN ; MAX)always true diff --git a/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/px_basic.result b/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/px_basic.result index d2f275b13..cf5a827b8 100644 --- a/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/px_basic.result +++ b/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/px_basic.result @@ -320,7 +320,7 @@ Outputs & filters: 8 - output([a.c1], [a.c2]), filter(nil), rowset=256 (#keys=1, [a.c1]), dop=2 9 - output([a.c1], [a.c2]), filter(nil), rowset=256 - 10 - output([a.c1], [a.c2], [PARTITION_ID]), filter(nil), rowset=256 + 10 - output([a.c1], [a.c2]), filter(nil), rowset=256 access([a.c1], [a.c2]), partitions(p[0-4]) is_index_back=false, is_global_index=false, range_key([a.__pk_increment]), range(MIN ; MAX)always true