[FEAT MERGE]4_1_sql_feature

Co-authored-by: leslieyuchen <leslieyuchen@gmail.com>
Co-authored-by: Charles0429 <xiezhenjiang@gmail.com>
Co-authored-by: raywill <hustos@gmail.com>
This commit is contained in:
obdev
2023-01-28 16:01:26 +08:00
committed by ob-robot
parent 3080f2b66f
commit 2d19a9d8f5
846 changed files with 161957 additions and 116661 deletions

View File

@ -223,12 +223,15 @@ namespace sql
calc_part_id_expr_(NULL),
ref_table_id_(OB_INVALID_ID),
table_id_(OB_INVALID_ID),
filter_table_id_(OB_INVALID_ID),
row_count_(1.0),
join_filter_selectivity_(1.0),
right_distinct_card_(1.0),
need_partition_join_filter_(false),
can_use_join_filter_(false),
force_filter_(NULL),
force_part_filter_(NULL),
pushdown_filter_table_(),
in_current_dfo_(true),
skip_subpart_(false) {}
@ -239,6 +242,7 @@ namespace sql
K_(calc_part_id_expr),
K_(ref_table_id),
K_(table_id),
K_(filter_table_id),
K_(row_count),
K_(join_filter_selectivity),
K_(need_partition_join_filter),
@ -255,12 +259,15 @@ namespace sql
ObRawExpr *calc_part_id_expr_; //partition join filter计算分区id的表达式
uint64_t ref_table_id_; //join filter use基表的ref table id
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
double join_filter_selectivity_;
double right_distinct_card_;
bool need_partition_join_filter_;
bool can_use_join_filter_;
const ObJoinFilterHint *force_filter_;
const ObJoinFilterHint *force_part_filter_;
ObTableInHint pushdown_filter_table_;
bool in_current_dfo_;
// Indicates that part bf is only generated for the 1-level partition in the 2-level partition
// If the table is a 1-level partition, this value is false.
@ -341,6 +348,7 @@ struct EstimateCostInfo {
contain_das_op_(false),
parallel_(1),
server_cnt_(1),
server_list_(),
is_pipelined_path_(false),
is_nl_style_pipelined_path_(false)
{ }
@ -354,9 +362,10 @@ struct EstimateCostInfo {
bool is_join_path() const;
bool is_subquery_path() const;
int check_is_base_table(bool &is_base_table);
int check_meet_repart(bool &can_repart);
inline const common::ObIArray<OrderItem> &get_ordering() const { return ordering_; }
inline common::ObIArray<OrderItem> &get_ordering() { return ordering_; }
inline const common::ObIArray<ObAddr> &get_server_list() const { return server_list_; }
inline common::ObIArray<ObAddr> &get_server_list() { return server_list_; }
inline int get_interesting_order_info() const { return interesting_order_info_; }
inline void set_interesting_order_info(int64_t info) { interesting_order_info_ = info; }
inline void add_interesting_order_flag(OrderingFlag flag) { interesting_order_info_ |= flag; }
@ -426,8 +435,6 @@ struct EstimateCostInfo {
get_name_internal(buf, buf_len, pos);
common::ObIArray<OrderItem> &ordering = ordering_;
if (OB_FAIL(BUF_PRINTF("("))) { /* Do nothing */
} else {
EXPLAIN_PRINT_SORT_KEYS(ordering, EXPLAIN_UNINITIALIZED);
}
if (OB_FAIL(ret)) { /* Do nothing */
} else if (OB_FAIL(BUF_PRINTF(", "))) { /* Do nothing */
@ -480,6 +487,7 @@ struct EstimateCostInfo {
// weak sharding is used for partition-wise-join check, thus it should have table location, otherwise it is meaningless
common::ObSEArray<ObShardingInfo*, 8, common::ModulePageAllocator, true> weak_sharding_;
common::ObSEArray<ObPCParamEqualInfo, 4, common::ModulePageAllocator, true> equal_param_constraints_;
common::ObSEArray<ObPCConstParamInfo, 4, common::ModulePageAllocator, true> const_param_constraints_;
common::ObSEArray<ObExprConstraint, 4, common::ModulePageAllocator, true> expr_constraints_;
bool exchange_allocated_;
ObPhyPlanType phy_plan_type_;
@ -491,6 +499,7 @@ struct EstimateCostInfo {
// remember the parallel info to get this sharding
int64_t parallel_;
int64_t server_cnt_;
common::ObSEArray<common::ObAddr, 8, common::ModulePageAllocator, true> server_list_;
bool is_pipelined_path_;
bool is_nl_style_pipelined_path_;
@ -645,6 +654,7 @@ struct EstimateCostInfo {
join_algo_(INVALID_JOIN_ALGO),
join_dist_algo_(DistAlgo::DIST_INVALID_METHOD),
is_slave_mapping_(false),
use_hybrid_hash_dm_(false),
join_type_(UNKNOWN_JOIN),
need_mat_(false),
left_dup_table_pos_(OB_INVALID_ID),
@ -681,6 +691,7 @@ struct EstimateCostInfo {
join_algo_(join_algo),
join_dist_algo_(join_dist_algo),
is_slave_mapping_(is_slave_mapping),
use_hybrid_hash_dm_(false),
join_type_(join_type),
need_mat_(need_mat),
left_dup_table_pos_(OB_INVALID_INDEX),
@ -774,23 +785,24 @@ struct EstimateCostInfo {
inline bool is_fully_paratition_wise() const {
return is_partition_wise() && !exchange_allocated_;
}
inline bool is_partial_partition_wise() const {
return is_partition_wise() && exchange_allocated_;
}
inline bool is_partition_wise() const
{
return join_dist_algo_ == DistAlgo::DIST_PARTITION_WISE && !is_slave_mapping_;
return (join_dist_algo_ == DistAlgo::DIST_PARTITION_WISE ||
join_dist_algo_ == DistAlgo::DIST_EXT_PARTITION_WISE) &&
!is_slave_mapping_;
}
inline SlaveMappingType get_slave_mapping_type() const
{
SlaveMappingType sm_type = SlaveMappingType::SM_NONE;
if (!is_slave_mapping_) {
sm_type = SlaveMappingType::SM_NONE;
} else if (join_dist_algo_ == DIST_PARTITION_WISE) {
} else if (join_dist_algo_ == DIST_PARTITION_WISE ||
join_dist_algo_ == DIST_EXT_PARTITION_WISE) {
sm_type = SlaveMappingType::SM_PWJ_HASH_HASH;
} else if (join_dist_algo_ == DIST_PARTITION_NONE || join_dist_algo_ == DIST_NONE_PARTITION) {
} else if (join_dist_algo_ == DIST_PARTITION_NONE ||
join_dist_algo_ == DIST_NONE_PARTITION ||
join_dist_algo_ == DIST_NONE_HASH ||
join_dist_algo_ == DIST_HASH_NONE) {
sm_type = SlaveMappingType::SM_PPWJ_HASH_HASH;
} else if (join_dist_algo_ == DIST_BROADCAST_NONE) {
sm_type = SlaveMappingType::SM_PPWJ_BCAST_NONE;
@ -889,6 +901,7 @@ struct EstimateCostInfo {
JoinAlgo join_algo_; // e.g., merge, hash, nested loop
DistAlgo join_dist_algo_; // e.g, partition_wise_join, repartition, hash-hash
bool is_slave_mapping_; // whether should enable slave mapping
bool use_hybrid_hash_dm_; // if use hybrid hash distribution method for hash-hash dm
ObJoinType join_type_;
bool need_mat_;
// for duplicated table
@ -1137,6 +1150,27 @@ struct NullAwareAntiJoinInfo {
common::ObSEArray<Path*, 8> inner_paths_; //生成的inner path
BaseTableOptInfo *table_opt_info_;
ObSEArray<ObPCParamEqualInfo, 4> equal_param_constraints_;
ObSEArray<ObPCConstParamInfo, 4> const_param_constraints_;
};
struct DeducedExprInfo {
DeducedExprInfo() :
deduced_expr_(NULL),
deduced_from_expr_(NULL),
is_precise_(false),
const_param_constraints_() {}
ObRawExpr * deduced_expr_;
ObRawExpr * deduced_from_expr_;
bool is_precise_;
common::ObSEArray<ObPCConstParamInfo, 2, common::ModulePageAllocator, true> const_param_constraints_;
int assign(const DeducedExprInfo& other);
TO_STRING_KV(
K_(deduced_expr),
K_(deduced_from_expr),
K_(is_precise)
);
};
ObJoinOrder(common::ObIAllocator *allocator,
@ -1236,12 +1270,6 @@ struct NullAwareAntiJoinInfo {
int param_json_table_expr(ObRawExpr* &json_table_expr,
ObExecParamRawExpr*& nl_params,
ObIArray<ObRawExpr*> &subquery_exprs);
int extract_param_for_query_range(const ObIArray<ObRawExpr*> &range_conditions,
common::ObIArray<int64_t> &param_pos);
int extract_param_for_query_range(const ObRawExpr *raw_expr,
common::ObIArray<int64_t> &param_pos);
/**
* 为本节点增加一条路径,代价竞争过程在这里实现
* @param path
@ -1289,35 +1317,24 @@ struct NullAwareAntiJoinInfo {
int compute_const_exprs_for_subquery(uint64_t table_id, ObLogicalOperator *root);
int convert_subplan_scan_order_item(ObRawExprFactory &expr_factory,
const EqualSets &equal_sets,
const ObIArray<ObRawExpr *> &const_exprs,
const uint64_t table_id,
const ObDMLStmt &parent_stmt,
const ObSelectStmt &child_stmt,
const ObIArray<OrderItem> &input_order,
ObIArray<OrderItem> &output_order);
static int convert_subplan_scan_order_item(ObLogPlan &plan,
ObLogicalOperator &subplan_root,
const uint64_t table_id,
ObIArray<OrderItem> &output_order);
static int convert_subplan_scan_sharding_info(common::ObIAllocator &allocator,
ObOptimizerContext &opt_ctx,
const EqualSets &equal_sets,
static int convert_subplan_scan_sharding_info(ObLogPlan &plan,
ObLogicalOperator &subplan_root,
const uint64_t table_id,
const ObDMLStmt &parent_stmt,
const ObSelectStmt &child_stmt,
ObShardingInfo *input_strong_sharding,
const ObIArray<ObShardingInfo*> &input_weak_sharding,
ObShardingInfo *&output_strong_sharding,
ObIArray<ObShardingInfo*> &output_weak_sharding);
static int convert_subplan_scan_sharding_info(common::ObIAllocator &allocator,
ObOptimizerContext &opt_ctx,
const EqualSets &equal_sets,
static int convert_subplan_scan_sharding_info(ObLogPlan &plan,
ObLogicalOperator &subplan_root,
const uint64_t table_id,
const ObDMLStmt &parent_stmt,
const ObSelectStmt &child_stmt,
bool is_strong,
ObShardingInfo *input_sharding,
ObShardingInfo *&output_sharding);
int compute_table_meta_info(const uint64_t table_id, const uint64_t ref_table_id);
int fill_path_index_meta_info(const uint64_t table_id,
@ -1375,6 +1392,7 @@ struct NullAwareAntiJoinInfo {
inline PathType get_type() const { return type_;}
inline ObLogPlan* get_plan(){return plan_;}
inline const ObLogPlan* get_plan() const {return plan_;}
inline uint64_t get_table_id() const {return table_id_;}
@ -1422,7 +1440,8 @@ struct NullAwareAntiJoinInfo {
const uint64_t index_id,
common::ObIArray<ObRawExpr *> &index_keys,
common::ObIArray<ObRawExpr *> &ordering,
ObOrderDirection &direction);
ObOrderDirection &direction,
const bool is_index_back);
int get_index_scan_direction(const ObIArray<ObRawExpr *> &keys,
const ObDMLStmt *stmt,
@ -1769,28 +1788,34 @@ struct NullAwareAntiJoinInfo {
const bool is_left_naaj_na,
ObIArray<JoinFilterInfo> &join_filter_infos);
int find_possible_join_filter_table(const Path &left_path,
int find_possible_join_filter_tables(const Path &left_path,
const Path &right_path,
const DistAlgo join_dist_algo,
const ObIArray<ObRawExpr*> &equal_join_conditions,
ObIArray<JoinFilterInfo> &join_filter_infos);
int find_shuffle_table_scan(const ObLogPlanHint &log_plan_hint,
const Path &right_path,
const ObRelIds &left_tables,
bool config_disable,
bool is_current_dfo,
ObIArray<JoinFilterInfo> &join_filter_infos);
int find_possible_join_filter_tables(const ObLogPlanHint &log_plan_hint,
const Path &right_path,
const ObRelIds &left_tables,
const ObRelIds &right_tables,
bool config_disable,
bool is_current_dfo,
bool is_fully_partition_wise,
const ObIArray<ObRawExpr*> &left_join_conditions,
const ObIArray<ObRawExpr*> &right_join_conditions,
ObIArray<JoinFilterInfo> &join_filter_infos);
int get_join_filter_exprs(const ObIArray<ObRawExpr*> &equal_join_conditions,
ObIArray<JoinFilterInfo> &join_filter_infos);
int get_join_filter_exprs(const ObIArray<ObRawExpr*> &left_join_conditions,
const ObIArray<ObRawExpr*> &right_join_conditions,
JoinFilterInfo &join_filter_info);
int fill_join_filter_info(JoinFilterInfo &join_filter_info);
int check_normal_join_filter_valid(const Path& left_path,
const Path& right_path,
ObIArray<JoinFilterInfo> &join_filter_infos);
int calc_join_filter_selectivity(const Path& left_path,
const Path& right_path,
JoinFilterInfo& info,
double &join_filter_selectivity);
@ -1841,13 +1866,14 @@ struct NullAwareAntiJoinInfo {
bool is_partition_wise_valid(const Path &left_path,
const Path &right_path);
bool is_repart_valid(const Path &left_path, const Path &right_path, const DistAlgo dist_algo, const bool is_nl);
int check_if_match_partition_wise(const EqualSets &equal_sets,
Path &left_path,
Path &right_path,
const ObIArray<ObRawExpr*> &left_join_keys,
const ObIArray<ObRawExpr*> &right_join_keys,
const ObIArray<bool> &null_safe_info,
const ObJoinType join_type,
bool &is_partition_wise);
int extract_hashjoin_conditions(const ObIArray<ObRawExpr*> &join_quals,
@ -1955,7 +1981,8 @@ struct NullAwareAntiJoinInfo {
private:
int add_access_filters(AccessPath *path,
const common::ObIArray<ObRawExpr*> &index_keys,
const ObIArray<ObRawExpr *> &restrict_infos);
const common::ObIArray<ObRawExpr*> &range_exprs,
PathHelper &helper);
int set_nl_filters(JoinPath *join_path,
const Path *right_path,
@ -1987,7 +2014,7 @@ struct NullAwareAntiJoinInfo {
int get_preliminary_prefix_info(ObQueryRange &query_range,QueryRangeInfo &range_info);
void get_prefix_info(ObKeyPart *key_part,
void get_prefix_info(const ObKeyPart *key_part,
int64_t &equal_prefix_count,
int64_t &range_prefix_count,
bool &contain_always_false);
@ -2111,14 +2138,8 @@ struct NullAwareAntiJoinInfo {
const JoinInfo *ljoin_info,
const ObJoinType join_type);
int compute_fd_item_set_for_subquery(ObRawExprFactory &expr_factory,
const EqualSets &equal_sets,
const ObIArray<ObRawExpr*> &const_exprs,
const uint64_t table_id,
const ObDMLStmt &parent_stmt,
const ObSelectStmt &child_stmt,
const ObFdItemSet &input_fd_item_sets,
ObFdItemSet &output_fd_item_sets);
int compute_fd_item_set_for_subquery(const uint64_t table_id,
ObLogicalOperator *subplan_root);
int compute_one_row_info_for_table_scan(ObIArray<AccessPath *> &access_paths);
@ -2177,7 +2198,8 @@ struct NullAwareAntiJoinInfo {
double right_output_rows,
const JoinInfo &join_info,
double &new_rows,
double &selectivity);
double &selectivity,
EqualSets &equal_sets);
inline void set_cnt_rownum(const bool cnt_rownum) { cnt_rownum_ = cnt_rownum; }
inline bool get_cnt_rownum() const { return cnt_rownum_; }
inline void increase_total_path_num() { total_path_num_ ++; }
@ -2260,6 +2282,37 @@ struct NullAwareAntiJoinInfo {
const bool force_inner_nl,
ObIArray<ObRawExpr *> &pushdown_quals);
int get_generated_col_index_qual(const int64_t table_id,
ObIArray<ObRawExpr *> &quals);
int build_prefix_index_compare_expr(ObRawExpr &column_expr,
ObRawExpr *prefix_expr,
ObItemType type,
ObRawExpr &value_expr,
ObRawExpr *escape_expr,
ObRawExpr *&new_op_expr);
int get_prefix_str_idx_exprs(ObRawExpr *expr,
ObColumnRefRawExpr *column_expr,
ObRawExpr *value_expr,
ObRawExpr *escape_expr,
const TableItem *table_item,
ObItemType type,
ObRawExpr *&new_expr);
int deduce_prefix_str_idx_exprs(ObRawExpr *expr,
const TableItem *table_item,
ObRawExpr *&new_expr);
int deduce_common_gen_col_index_expr(ObRawExpr *qual,
const TableItem *table_item,
ObRawExpr *&new_qual);
int try_get_generated_col_index_expr(ObRawExpr *qual,
ObRawExpr *depend_expr,
ObColumnRefRawExpr *col_expr,
ObRawExpr *&new_qual);
int get_range_params(const Path *path,
ObIArray<ObRawExpr*> &range_exprs,
ObIArray<ObRawExpr*> &all_table_filters);
@ -2278,6 +2331,9 @@ struct NullAwareAntiJoinInfo {
ObIArray<ObRawExpr*> &other_join_conditions,
NullAwareAntiJoinInfo &naaj_info);
bool is_main_table_use_das(const common::ObIArray<AccessPath *> &access_paths);
int add_deduced_expr(ObRawExpr *deduced_expr, ObRawExpr *deduce_from, bool is_persistent);
int add_deduced_expr(ObRawExpr *deduced_expr, ObRawExpr *deduce_from,
bool is_persistent, ObExprEqualCheckContext &equal_ctx);
friend class ::test::TestJoinOrder_ob_join_order_param_check_Test;
friend class ::test::TestJoinOrder_ob_join_order_src_Test;
private:
@ -2308,6 +2364,7 @@ struct NullAwareAntiJoinInfo {
ObSEArray<ObRawExpr *, 8, common::ModulePageAllocator, true> not_null_columns_;
// cache for all inner path
InnerPathInfos inner_path_infos_;
common::ObSEArray<DeducedExprInfo, 4, common::ModulePageAllocator, true> deduced_exprs_info_;
bool cnt_rownum_;
uint64_t total_path_num_;
private: