diff --git a/src/sql/engine/table/ob_table_scan_op.cpp b/src/sql/engine/table/ob_table_scan_op.cpp index f61ff2adee..4cd30532b2 100644 --- a/src/sql/engine/table/ob_table_scan_op.cpp +++ b/src/sql/engine/table/ob_table_scan_op.cpp @@ -937,26 +937,28 @@ int ObTableScanOp::update_output_tablet_id() const ObDASTabletLoc *data_tablet_loc = MY_SPEC.should_scan_index() ? ObDASUtils::get_related_tablet_loc(*scan_result_.get_tablet_loc(), MY_SPEC.ref_table_id_) : scan_result_.get_tablet_loc(); - if (is_vectorized()) { - const int64_t batch_size = MY_SPEC.max_batch_size_; - if (NULL != MY_SPEC.pdml_partition_id_) { - ObExpr *expr = MY_SPEC.pdml_partition_id_; - ObDatum *datums = expr->locate_datums_for_update(eval_ctx_, batch_size); - for (int64_t i = 0; i < batch_size; i++) { - datums[i].set_int(data_tablet_loc->tablet_id_.id()); + if (OB_NOT_NULL(data_tablet_loc)) { + if (is_vectorized()) { + const int64_t batch_size = MY_SPEC.max_batch_size_; + if (NULL != MY_SPEC.pdml_partition_id_) { + ObExpr *expr = MY_SPEC.pdml_partition_id_; + ObDatum *datums = expr->locate_datums_for_update(eval_ctx_, batch_size); + for (int64_t i = 0; i < batch_size; i++) { + datums[i].set_int(data_tablet_loc->tablet_id_.id()); + } + expr->set_evaluated_projected(eval_ctx_); + LOG_TRACE("find the partition id expr in pdml table scan", K(ret), KPC(expr), KPC(data_tablet_loc)); + } + } else { + // handle PDML partition id: + // if partition id expr in TSC output_exprs, + // set the TSC partition id to the corresponding expr frame + if (NULL != MY_SPEC.pdml_partition_id_) { + ObExpr *expr = MY_SPEC.pdml_partition_id_; + expr->locate_datum_for_write(eval_ctx_).set_int(data_tablet_loc->tablet_id_.id()); + expr->set_evaluated_projected(eval_ctx_); + LOG_TRACE("find the partition id expr in pdml table scan", K(ret), KPC(data_tablet_loc)); } - expr->set_evaluated_projected(eval_ctx_); - LOG_TRACE("find the partition id expr in pdml table scan", K(ret), KPC(expr), KPC(data_tablet_loc)); - } - } else { - // handle PDML partition id: - // if partition id expr in TSC output_exprs, - // set the TSC partition id to the corresponding expr frame - if (NULL != MY_SPEC.pdml_partition_id_) { - ObExpr *expr = MY_SPEC.pdml_partition_id_; - expr->locate_datum_for_write(eval_ctx_).set_int(data_tablet_loc->tablet_id_.id()); - expr->set_evaluated_projected(eval_ctx_); - LOG_TRACE("find the partition id expr in pdml table scan", K(ret), KPC(data_tablet_loc)); } } return ret; diff --git a/src/sql/optimizer/ob_join_order.cpp b/src/sql/optimizer/ob_join_order.cpp index fee3259001..180d0c95c9 100644 --- a/src/sql/optimizer/ob_join_order.cpp +++ b/src/sql/optimizer/ob_join_order.cpp @@ -299,7 +299,7 @@ int ObJoinOrder::compute_sharding_info_for_base_paths(ObIArray &ac path->index_id_ == cur_path->index_id_ && path->use_das_ == cur_path->use_das_) { if (path->use_das_) { - path->strong_sharding_ = opt_ctx->get_match_all_sharding(); + path->strong_sharding_ = opt_ctx->get_match_all_sharding(); } else { path->strong_sharding_ = cur_path->strong_sharding_; } @@ -312,7 +312,7 @@ int ObJoinOrder::compute_sharding_info_for_base_paths(ObIArray &ac path->strong_sharding_))) { LOG_WARN("failed to calc sharding info", K(ret)); } else if (!path->use_das_ && (1 < access_paths.count() || path->is_inner_path_) && - (path->is_inner_path_ || get_tables().is_subset(get_plan()->get_subq_pdfilter_tset())) && + (path->is_inner_path_ || get_tables().is_subset(get_plan()->get_subq_pdfilter_tset())) && !is_virtual_table(path->ref_table_id_) && !ObSqlSchemaGuard::is_link_table(get_plan()->get_stmt(), path->ref_table_id_) && opt_ctx->get_parallel() > path->strong_sharding_->get_part_cnt()) { @@ -869,7 +869,7 @@ int ObJoinOrder::add_table_by_heuristics(const uint64_t table_id, bool is_create_basic_path = false; AccessPath *das_access_path = NULL; AccessPath *basic_access_path = NULL; // the path does not use DAS, maybe optimal sometime. - if (OB_FAIL(will_use_das(table_id, + if (OB_FAIL(will_use_das(table_id, ref_table_id, index_to_use, index_info_cache, @@ -877,7 +877,7 @@ int ObJoinOrder::add_table_by_heuristics(const uint64_t table_id, is_create_das_path, is_create_basic_path))) { LOG_WARN("failed to check will use das", K(ret)); - } else if (is_create_das_path && + } else if (is_create_das_path && OB_FAIL(create_one_access_path(table_id, ref_table_id, index_to_use, @@ -1236,7 +1236,7 @@ int ObJoinOrder::will_use_das(const uint64_t table_id, const ObIndexInfoCache &index_info_cache, PathHelper &helper, bool &create_das_path, - bool &create_basic_path) + bool &create_basic_path) { int ret = OB_SUCCESS; create_das_path = false; @@ -1291,7 +1291,7 @@ int ObJoinOrder::will_use_das(const uint64_t table_id, get_plan()->get_optimizer_context().get_parallel() < 2) { create_das_path = true; create_basic_path = false; - } else if ((helper.is_inner_path_ || get_tables().is_subset(get_plan()->get_subq_pdfilter_tset())) && + } else if ((helper.is_inner_path_ || get_tables().is_subset(get_plan()->get_subq_pdfilter_tset())) && !is_virtual_table(ref_id) && !ObSqlSchemaGuard::is_link_table(get_plan()->get_stmt(), ref_id)) { create_das_path = true; @@ -2095,7 +2095,7 @@ int ObJoinOrder::create_access_paths(const uint64_t table_id, AccessPath *das_access_path = NULL; AccessPath *basic_access_path = NULL; // the path does not use DAS, maybe optimal sometime. OptSkipScanState use_skip_scan = OptSkipScanState::SS_UNSET; - if (OB_FAIL(will_use_das(table_id, + if (OB_FAIL(will_use_das(table_id, ref_table_id, skyline_index_ids.at(i), index_info_cache, @@ -3680,7 +3680,7 @@ int ObJoinOrder::add_path(Path* path) K(*cur_path), K(*path), K(ret)); } else if (DominateRelation::OBJ_LEFT_DOMINATE == plan_rel || DominateRelation::OBJ_EQUAL == plan_rel) { - should_add = false; + should_add = false; LOG_TRACE("current path has been dominated, no need to add", K(*cur_path), K(*path), K(ret)); OPT_TRACE("current path has been dominated by path:", cur_path); @@ -4608,9 +4608,9 @@ int JoinPath::compute_join_path_sharding() } else if (DistAlgo::DIST_BROADCAST_NONE == join_dist_algo_ || (DistAlgo::DIST_BC2HOST_NONE == join_dist_algo_ && JoinAlgo::HASH_JOIN == join_algo_)) { if (right_path_->parallel_more_than_part_cnt()) { - //If the degree of parallelism is greater than the number of partitions, - //sharding will not be inherited to avoid thread waste. - strong_sharding_ = opt_ctx.get_distributed_sharding(); + //If the degree of parallelism is greater than the number of partitions, + //sharding will not be inherited to avoid thread waste. + strong_sharding_ = opt_ctx.get_distributed_sharding(); } else { strong_sharding_ = right_path_->strong_sharding_; inherit_sharding_index_ = 1; @@ -4635,10 +4635,10 @@ int JoinPath::compute_join_path_sharding() } else { /*do nothing*/ } } } else if (DistAlgo::DIST_NONE_BROADCAST == join_dist_algo_) { - if (left_path_->parallel_more_than_part_cnt()) { - //If the degree of parallelism is greater than the number of partitions, - //sharding will not be inherited to avoid thread waste. - strong_sharding_ = opt_ctx.get_distributed_sharding(); + if (left_path_->parallel_more_than_part_cnt()) { + //If the degree of parallelism is greater than the number of partitions, + //sharding will not be inherited to avoid thread waste. + strong_sharding_ = opt_ctx.get_distributed_sharding(); } else { strong_sharding_ = left_path_->strong_sharding_; inherit_sharding_index_ = 0; @@ -6353,7 +6353,7 @@ int ObJoinOrder::try_pruning_base_table_access_path(ObIArray &acces ap->est_cost_info_.index_meta_info_.is_geo_index_; } } - + if (OB_SUCC(ret) && need_prune) { for (int64_t i = base_path_positions.count() - 1; OB_SUCC(ret) && i >= 0; --i) { int64_t base_path_pos = base_path_positions.at(i); @@ -6372,7 +6372,7 @@ int ObJoinOrder::try_pruning_base_table_access_path(ObIArray &acces } } } - + return ret; } @@ -7614,7 +7614,7 @@ int ObJoinOrder::get_distributed_join_method(Path &left_path, distributed_methods = path_info.distributed_methods_; bool use_shared_hash_join = get_plan()->get_optimizer_context().get_parallel() > 1; ObSQLSessionInfo *session = NULL; - const ObLogPlanHint *log_hint = NULL; + const ObLogPlanHint *log_hint = NULL; const LogJoinHint *log_join_hint = NULL; if (OB_ISNULL(get_plan()) || OB_ISNULL(left_sharding = left_path.get_sharding()) || OB_ISNULL(session = get_plan()->get_optimizer_context().get_session_info()) || @@ -7655,7 +7655,7 @@ int ObJoinOrder::get_distributed_join_method(Path &left_path, } if (OB_SUCC(ret)) { - log_hint = &get_plan()->get_log_plan_hint(); + log_hint = &get_plan()->get_log_plan_hint(); log_join_hint = log_hint->get_join_hint(right_path.parent_->get_tables()); if (HASH_JOIN == join_algo) { if (use_shared_hash_join) { @@ -8710,6 +8710,7 @@ int ObJoinOrder::find_possible_join_filter_tables(const ObLogPlanHint &log_plan_ JoinFilterInfo info; info.table_id_ = access.table_id_; info.filter_table_id_ = access.table_id_; + info.index_id_ = access.index_id_; info.ref_table_id_ = access.ref_table_id_; info.sharding_ = access.strong_sharding_; info.row_count_ = access.get_output_row_count(); @@ -9046,7 +9047,7 @@ int ObJoinOrder::check_partition_join_filter_valid(const DistAlgo join_dist_algo } else if (!match) { info.need_partition_join_filter_ = false; OPT_TRACE("hash join will not use partition join filter"); - } else if (OB_FAIL(build_join_filter_part_expr(info.ref_table_id_, + } else if (OB_FAIL(build_join_filter_part_expr(info.index_id_, info.lexprs_, info.rexprs_, info.sharding_, @@ -10473,8 +10474,8 @@ int ObJoinOrder::fill_path_index_meta_info(const uint64_t table_id, } else if (OB_ISNULL(table_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("index schema should not be null", K(ret), K(index_id)); - } else if (OB_FAIL(init_est_info_for_index(index_id, - index_meta_info, + } else if (OB_FAIL(init_est_info_for_index(index_id, + index_meta_info, ap->table_partition_info_, ap->is_global_index_ ? *index_schema : *table_schema, has_opt_stat))) { @@ -10488,7 +10489,7 @@ int ObJoinOrder::fill_path_index_meta_info(const uint64_t table_id, static_cast(table_meta_info_.table_column_count_)); index_meta_info.index_micro_block_count_ = table_meta_info_.has_opt_stat_ ? table_meta_info_.micro_block_count_ - * (static_cast(index_meta_info.index_column_count_) / + * (static_cast(index_meta_info.index_column_count_) / static_cast(table_meta_info_.table_column_count_)) : -1; } } @@ -11348,7 +11349,7 @@ int ObJoinOrder::compute_fd_item_set_for_table_scan(const uint64_t table_id, LOG_WARN("failed to try add fd item", K(ret)); } } - if (OB_SUCC(ret) && stmt->is_select_stmt()) { + if (OB_SUCC(ret) && stmt->is_select_stmt()) { ObSqlBitSet<> table_set; if (OB_FAIL(stmt->get_table_rel_ids(table_id, table_set))) { LOG_WARN("fail to get table relids", K(ret)); diff --git a/src/sql/optimizer/ob_join_order.h b/src/sql/optimizer/ob_join_order.h index e01ff32c64..c8e3f60954 100644 --- a/src/sql/optimizer/ob_join_order.h +++ b/src/sql/optimizer/ob_join_order.h @@ -222,6 +222,7 @@ namespace sql sharding_(NULL), calc_part_id_expr_(NULL), ref_table_id_(OB_INVALID_ID), + index_id_(OB_INVALID_ID), table_id_(OB_INVALID_ID), filter_table_id_(OB_INVALID_ID), row_count_(1.0), @@ -241,6 +242,7 @@ namespace sql K_(sharding), K_(calc_part_id_expr), K_(ref_table_id), + K_(index_id), K_(table_id), K_(filter_table_id), K_(row_count), @@ -258,6 +260,7 @@ namespace sql ObShardingInfo *sharding_; //join filter use基表的sharding ObRawExpr *calc_part_id_expr_; //partition join filter计算分区id的表达式 uint64_t ref_table_id_; //join filter use基表的ref table id + uint64_t index_id_; //index id for join filter use uint64_t table_id_; //join filter use基表的table id uint64_t filter_table_id_; //join filter use实际受hint控制的table id double row_count_; //join filter use基表的output rows @@ -444,9 +447,9 @@ struct EstimateCostInfo { } return ret; } - inline bool parallel_more_than_part_cnt() const - { - return NULL != strong_sharding_ && parallel_ > strong_sharding_->get_part_cnt(); + inline bool parallel_more_than_part_cnt() const + { + return NULL != strong_sharding_ && parallel_ > strong_sharding_->get_part_cnt(); } int compute_path_property_from_log_op(); TO_STRING_KV(K_(is_local_order), @@ -502,7 +505,7 @@ struct EstimateCostInfo { common::ObSEArray server_list_; bool is_pipelined_path_; bool is_nl_style_pipelined_path_; - + private: DISALLOW_COPY_AND_ASSIGN(Path); }; @@ -1424,7 +1427,7 @@ struct NullAwareAntiJoinInfo { AccessPath *&ap, bool use_das, OptSkipScanState use_skip_scan); - + int will_use_das(const uint64_t table_id, const uint64_t ref_id, const uint64_t index_id, @@ -2128,7 +2131,7 @@ struct NullAwareAntiJoinInfo { const ObJoinOrder *right_tree, const JoinInfo *join_info, const ObJoinType join_type); - + int compute_fd_item_set_for_inner_join(const ObJoinOrder *left_tree, const ObJoinOrder *right_tree, const JoinInfo *join_info); @@ -2255,7 +2258,7 @@ struct NullAwareAntiJoinInfo { ObIArray &equal_param_constraints); int check_filter_is_redundant(ObJoinOrder &left_tree, - ObRawExpr *expr, + ObRawExpr *expr, ObExprParamCheckContext &context, bool &is_redunant); diff --git a/src/sql/optimizer/ob_logical_operator.cpp b/src/sql/optimizer/ob_logical_operator.cpp index 85d47be917..588f33f514 100644 --- a/src/sql/optimizer/ob_logical_operator.cpp +++ b/src/sql/optimizer/ob_logical_operator.cpp @@ -3702,7 +3702,6 @@ int ObLogicalOperator::allocate_granule_nodes_above(AllocGIContext &ctx) gi_op->set_tablet_id_expr(tablet_id_expr); gi_op->set_join_filter_info(table_scan->get_join_filter_info()); gi_op->add_flag(GI_USE_PARTITION_FILTER); - table_scan->set_tablet_id_expr(tablet_id_expr); } } else if (LOG_GROUP_BY == get_type()) { if (static_cast(this)->force_partition_gi()) {