[CP] reorder the order of complex filters

This commit is contained in:
obdev
2024-02-21 09:19:05 +00:00
committed by ob-robot
parent 0c3b7d08c4
commit fea19bc54e
31 changed files with 335 additions and 21 deletions

View File

@ -179,6 +179,7 @@ double ObIndexMetaInfo::get_micro_block_numbers() const
*/
int ObOptEstCostModel::cost_nestloop(const ObCostNLJoinInfo &est_cost_info,
double &cost,
double &filter_selectivity,
ObIArray<ObExprSelPair> &all_predicate_sel)
{
int ret = OB_SUCCESS;
@ -191,7 +192,7 @@ int ObOptEstCostModel::cost_nestloop(const ObCostNLJoinInfo &est_cost_info,
double right_rows = est_cost_info.right_rows_;
double cart_tuples = left_rows * right_rows; // tuples of Cartesian product
double out_tuples = 0.0;
double filter_selectivity = 0.0;
filter_selectivity = 0.0;
double material_cost = 0.0;
//selectivity for equal conds
if (OB_FAIL(ObOptSelectivity::calculate_selectivity(*est_cost_info.table_metas_,
@ -2285,3 +2286,61 @@ int ObOptEstCostModel::calc_range_cost(const ObTableMetaInfo& table_meta_info,
cost = io_cost + cpu_cost;
return ret;
}
int ObOptEstCostModel::calc_pred_cost_per_row(const ObRawExpr *expr,
double card,
double &cost)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null", K(ret));
} else {
double rows = expr->is_const_expr() && card > 0 ? card : 1;
bool need_calc_child_cost = true;
if (IS_SPATIAL_OP(expr->get_expr_type())
|| IS_GEO_OP(expr->get_expr_type())
|| expr->is_json_expr()
|| expr->is_xml_expr()) {
cost += cost_params_.get_cmp_spatial_cost(sys_stat_) / rows;
} else if (expr->is_udf_expr()) {
cost += cost_params_.get_cmp_udf_cost(sys_stat_) / rows;
} else if (ob_is_lob_locator(expr->get_result_type().get_type())) {
cost += cost_params_.get_cmp_lob_cost(sys_stat_) / rows;
} else if (T_OP_DIV == expr->get_expr_type()) {
cost += cost_params_.get_cmp_err_handle_expr_cost(sys_stat_) / rows;
} else if (T_FUN_SYS_CAST == expr->get_expr_type()) {
if (OB_ISNULL(expr->get_param_expr(0))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null", K(ret));
} else {
ObObjType src = expr->get_param_expr(0)->get_result_type().get_type();
ObObjType dst = expr->get_result_type().get_type();
if (ob_is_string_type(src) &&
(ob_is_numeric_type(dst) || ob_is_temporal_type(dst))) {
cost += cost_params_.get_cmp_err_handle_expr_cost(sys_stat_) / rows;
} else {
cost += cost_params_.get_comparison_cost(sys_stat_,ObIntTC) / rows;
}
}
} else if (T_OP_IN == expr->get_expr_type()) {
if (expr->get_param_count() != 2 || OB_ISNULL(expr->get_param_expr(1))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid in params", K(ret));
} else {
cost += (expr->get_param_expr(1)->get_param_count() + 1) * cost_params_.get_comparison_cost(sys_stat_,ObIntTC) / rows;
}
need_calc_child_cost = false;
} else {
cost += cost_params_.get_comparison_cost(sys_stat_,ObIntTC) / rows;
}
if (need_calc_child_cost) {
for (int64_t i = 0; OB_SUCC(ret) && i < expr->get_param_count(); ++i) {
if (OB_FAIL(SMART_CALL(calc_pred_cost_per_row(expr->get_param_expr(i), card, cost)))) {
LOG_WARN("calc cost per tuple failed", K(ret), KPC(expr));
}
}
}
}
return ret;
}