[FEAT MERGE] support auto dop

This commit is contained in:
obdev
2023-04-28 15:11:52 +00:00
committed by ob-robot
parent 642f1c7d84
commit b41dc0ebdd
106 changed files with 3815 additions and 2844 deletions

View File

@ -237,9 +237,10 @@ int ObLogGroupBy::est_cost()
if (OB_ISNULL(child)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(child));
} else if (OB_FAIL(get_child_est_info(child_card, child_ndv, selectivity))) {
} else if (OB_FAIL(get_child_est_info(get_parallel(), child_card, child_ndv, selectivity))) {
LOG_WARN("failed to get chidl est info", K(ret));
} else if (OB_FAIL(inner_est_cost(child_card,
} else if (OB_FAIL(inner_est_cost(get_parallel(),
child_card,
child_ndv,
distinct_per_dop_,
group_cost))) {
@ -253,18 +254,18 @@ int ObLogGroupBy::est_cost()
return ret;
}
int ObLogGroupBy::re_est_cost(EstimateCostInfo &param, double &card, double &cost)
int ObLogGroupBy::do_re_est_cost(EstimateCostInfo &param, double &card, double &op_cost, double &cost)
{
int ret = OB_SUCCESS;
double child_card = 0.0;
double child_ndv = 0.0;
double selectivity = 1.0;
double group_cost = 0.0;
ObLogicalOperator *child = get_child(ObLogicalOperator::first_child);
const int64_t parallel = param.need_parallel_;
if (OB_ISNULL(child)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(child));
} else if (OB_FAIL(get_child_est_info(child_card, child_ndv, selectivity))) {
} else if (OB_FAIL(get_child_est_info(parallel, child_card, child_ndv, selectivity))) {
LOG_WARN("failed to get chidl est info", K(ret));
} else {
double child_cost = child->get_cost();
@ -274,7 +275,7 @@ int ObLogGroupBy::re_est_cost(EstimateCostInfo &param, double &card, double &cos
child_ndv > 0 &&
param.need_row_count_ < child_ndv) {
need_ndv = param.need_row_count_;
if (selectivity) {
if (selectivity > OB_DOUBLE_EPSINON) {
need_ndv /= selectivity;
}
if (child_card > 0) {
@ -282,43 +283,40 @@ int ObLogGroupBy::re_est_cost(EstimateCostInfo &param, double &card, double &cos
} else {
param.need_row_count_ = 0;
}
} else {
param.need_row_count_ = -1;
}
if (is_block_op()) {
param.need_row_count_ = -1; //reset need row count
}
if (OB_FAIL(SMART_CALL(child->re_est_cost(param, child_card, child_cost)))) {
LOG_WARN("failed to re est child cost", K(ret));
} else if (OB_FAIL(inner_est_cost(child_card,
} else if (OB_FAIL(inner_est_cost(parallel,
child_card,
need_ndv,
distinct_per_dop_,
group_cost))) {
op_cost))) {
LOG_WARN("failed to est distinct cost", K(ret));
} else {
cost = child_cost + group_cost;
cost = child_cost + op_cost;
card = need_ndv * selectivity;
if (param.override_) {
set_op_cost(group_cost);
set_cost(cost);
set_card(card);
}
}
}
return ret;
}
int ObLogGroupBy::inner_est_cost(double child_card, double &child_ndv, double &per_dop_ndv, double &op_cost)
int ObLogGroupBy::inner_est_cost(const int64_t parallel, double child_card, double &child_ndv, double &per_dop_ndv, double &op_cost)
{
int ret = OB_SUCCESS;
double per_dop_card = 0.0;
per_dop_ndv = 0.0;
int64_t parallel = 0;
common::ObSEArray<ObRawExpr *, 8> group_rollup_exprs;
ObLogicalOperator *child = get_child(ObLogicalOperator::first_child);
if (OB_ISNULL(get_plan()) ||
OB_ISNULL(child)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(child));
} else if (OB_UNLIKELY((parallel = get_parallel()) < 1)) {
} else if (OB_UNLIKELY(parallel < 1)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(child));
} else if (OB_FAIL(get_group_rollup_exprs(group_rollup_exprs))) {
@ -328,7 +326,9 @@ int ObLogGroupBy::inner_est_cost(double child_card, double &child_ndv, double &p
if (is_first_stage()) {
per_dop_card = per_dop_card * three_stage_info_.distinct_aggr_count_;
}
if (parallel > 1) {
if ((get_group_by_exprs().empty() && get_rollup_exprs().empty()) || SCALAR_AGGREGATE == algo_) {
per_dop_ndv = 1.0;
} else if (parallel > 1) {
if (is_push_down()) {
per_dop_ndv = ObOptSelectivity::scale_distinct(per_dop_card, child_card, child_ndv);
} else {
@ -364,21 +364,18 @@ int ObLogGroupBy::inner_est_cost(double child_card, double &child_ndv, double &p
return ret;
}
int ObLogGroupBy::get_child_est_info(double &child_card, double &child_ndv, double &selectivity)
int ObLogGroupBy::get_child_est_info(const int64_t parallel, double &child_card, double &child_ndv, double &selectivity)
{
int ret = OB_SUCCESS;
int64_t parallel = 0;
common::ObSEArray<ObRawExpr *, 8> group_rollup_exprs;
ObLogicalOperator *child = get_child(ObLogicalOperator::first_child);
if (OB_ISNULL(child) || OB_ISNULL(get_plan())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(child));
} else if (OB_UNLIKELY((parallel = get_parallel()) < 1)) {
} else if (OB_UNLIKELY(parallel < 1)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(child));
} else if (OB_FAIL(get_group_rollup_exprs(group_rollup_exprs))) {
LOG_WARN("failed to get group rollup exprs", K(ret));
} else if (group_rollup_exprs.empty() || SCALAR_AGGREGATE == algo_) {
} else if ((get_group_by_exprs().empty() && get_rollup_exprs().empty())
|| SCALAR_AGGREGATE == algo_) {
child_card = child->get_card();
child_ndv = parallel;
} else {