[FEAT MERGE] [CP] Improve the rowcount estimation
Co-authored-by: akaError <lzg020616@163.com>
This commit is contained in:
@ -421,30 +421,52 @@ int ObLogSet::get_re_est_cost_infos(const EstimateCostInfo ¶m,
|
||||
const double need_row_count = (is_recursive_union() || !is_set_distinct())
|
||||
&& param.need_row_count_ >= 0 && param.need_row_count_ < card_
|
||||
? param.need_row_count_ : -1;
|
||||
bool need_scale_ndv = (need_row_count == -1);
|
||||
double cur_child_card = 0.0;
|
||||
double cur_child_cost = 0.0;
|
||||
if (OB_UNLIKELY(is_set_distinct() && get_num_of_child() != child_ndv_.count())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected child ndv count", K(child_ndv_));
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < get_num_of_child(); ++i) {
|
||||
const ObLogicalOperator *child = get_child(i);
|
||||
cur_param.reset();
|
||||
double origin_child_card = 0;
|
||||
if (OB_ISNULL(child)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("set operator i-th child is null", K(ret), K(i));
|
||||
} else if (OB_FAIL(cur_param.assign(param))) {
|
||||
LOG_WARN("failed to assign param", K(ret));
|
||||
} else if (OB_FALSE_IT(cur_param.need_row_count_ = need_row_count)) {
|
||||
} else {
|
||||
cur_param.need_row_count_ = need_row_count;
|
||||
origin_child_card = child->get_card();
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (OB_FAIL(get_child(i)->re_est_cost(cur_param, cur_child_card, cur_child_cost))) {
|
||||
LOG_WARN("failed to re-est child cost", K(ret), K(i));
|
||||
} else if (OB_FAIL(cost_infos.push_back(ObBasicCostInfo(cur_child_card, cur_child_cost,
|
||||
child->get_width())))) {
|
||||
LOG_WARN("push back child's cost info failed", K(ret));
|
||||
} else if (ObSelectStmt::UNION == get_set_op()) {
|
||||
card += cur_child_card;
|
||||
} else if (ObSelectStmt::UNION == get_set_op() && !is_set_distinct()) {
|
||||
ObSelectStmt::SetOperator set_type = is_recursive_union() ? ObSelectStmt::RECURSIVE : ObSelectStmt::UNION;
|
||||
if (0 == i) {
|
||||
card = cur_child_card;
|
||||
} else {
|
||||
card = ObOptSelectivity::get_set_stmt_output_count(card, cur_child_card, set_type);
|
||||
}
|
||||
child_cost += cur_child_cost;
|
||||
} else if (ObSelectStmt::INTERSECT == get_set_op()) {
|
||||
card = (0 == i || cur_child_card < card) ? cur_child_card : card;
|
||||
child_cost += cur_child_cost;
|
||||
} else if (ObSelectStmt::EXCEPT == get_set_op()) {
|
||||
card = 0 == i ? cur_child_card : card;
|
||||
} else {
|
||||
double cur_child_ndv = child_ndv_.at(i);
|
||||
if (need_scale_ndv) {
|
||||
cur_child_ndv = std::min(
|
||||
cur_child_ndv,
|
||||
ObOptSelectivity::scale_distinct(cur_child_card, origin_child_card, cur_child_ndv));
|
||||
}
|
||||
if (0 == i) {
|
||||
card = cur_child_ndv;
|
||||
} else {
|
||||
card = ObOptSelectivity::get_set_stmt_output_count(card, cur_child_ndv, get_set_op());
|
||||
}
|
||||
child_cost += cur_child_cost;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user