fix hashgroupby 3stage implicit aggr bug

This commit is contained in:
lucky-sinx 2024-11-29 15:45:36 +00:00 committed by ob-robot
parent 5036be657b
commit 57ecb8a20e
5 changed files with 66 additions and 6 deletions

View File

@ -56,7 +56,8 @@ public:
int finish_adding_one_row();
inline int add_one_row(const int32_t start_agg_id, const int32_t end_agg_id, AggrRowPtr row,
const int64_t batch_idx, const int64_t batch_size, ObIVector **aggr_vectors)
const int64_t batch_idx, const int64_t batch_size, ObIVector **aggr_vectors,
ObFixedArray<int64_t, common::ObIAllocator> implicit_aggr_in_3stage_indexes)
{
int ret = OB_SUCCESS;
ObIVector *data_vec = nullptr;
@ -68,6 +69,15 @@ public:
SQL_LOG(WARN, "add one row failed", K(ret));
}
}
for (int i = 0; OB_SUCC(ret) && i < implicit_aggr_in_3stage_indexes.count(); i++) {
int col_id = implicit_aggr_in_3stage_indexes.at(i);
add_one_row_fn fn = add_one_row_fns_.at(col_id);
if (OB_FAIL(
fn(aggregates_.at(col_id), agg_ctx_, col_id, row, aggr_vectors[col_id], batch_idx, batch_size))) {
SQL_LOG(WARN, "add one row failed", K(ret));
}
}
return ret;
}

View File

@ -7623,6 +7623,49 @@ int ObStaticEngineCG::fill_aggr_infos(ObLogGroupBy &op,
aggr_info.expr_ = expr;
LOG_TRACE("trace all non aggr exprs", K(*expr), K(all_non_aggr_exprs.count()));
}
//6.calc for implicit_aggr, if aggr_info.expr_ only in third stage, not in second stage,
// must be calc in third stage.Normally caused by implicit aggr in filter.
if (spec.aggr_stage_ == ObThreeStageAggrStage::THIRD_STAGE) {
ObOpSpec *child_spec = &spec;
bool find_second_spec = false;
while (!find_second_spec && child_spec->get_children() != NULL
&& child_spec->get_child_cnt() > 0) {
if ((child_spec->type_ == PHY_VEC_HASH_GROUP_BY ||
child_spec->type_ == PHY_HASH_GROUP_BY ||
child_spec->type_ == PHY_VEC_MERGE_GROUP_BY ||
child_spec->type_ == PHY_MERGE_GROUP_BY) &&
((ObGroupBySpec*)child_spec)->aggr_stage_ == ObThreeStageAggrStage::SECOND_STAGE) {
find_second_spec = true;
} else {
child_spec = child_spec->get_children()[0];
}
}
if (find_second_spec) {
if (OB_FAIL(spec.implicit_aggr_in_3stage_indexes_.prepare_allocate_and_keep_count(
spec.aggr_infos_.count()))) {
OB_LOG(WARN, "fail to prepare_allocate implicit_aggr_in_3stage_indexes_", K(ret));
} else {
ObGroupBySpec *second_stage_spec = (ObGroupBySpec*)child_spec;
for (int i = 0; i < spec.aggr_infos_.count(); i++) {
if (spec.aggr_infos_.at(i).is_implicit_first_aggr()) {
bool exist_in_second_stage = false;
for (int j = 0; !exist_in_second_stage && j < second_stage_spec->aggr_infos_.count(); j++) {
if (spec.aggr_infos_.at(i).expr_ == second_stage_spec->aggr_infos_.at(j).expr_) {
exist_in_second_stage = true;
}
}
if (!exist_in_second_stage) {
spec.implicit_aggr_in_3stage_indexes_.push_back(i);
LOG_TRACE("find implicit aggr need calc in 3stage", K(i));
}
}
}
}
} else {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("cannot find second stage hashgroupby op", K(ret), K(find_second_spec));
}
}
return ret;
}

View File

@ -35,7 +35,8 @@ OB_SERIALIZE_MEMBER((ObGroupBySpec, ObOpSpec),
by_pass_enabled_,
support_fast_single_row_agg_,
skew_detection_enabled_, // FARM COMPAT WHITELIST
llc_ndv_est_enabled_);
llc_ndv_est_enabled_,
implicit_aggr_in_3stage_indexes_);
DEF_TO_STRING(ObGroupBySpec)
{

View File

@ -37,7 +37,8 @@ public:
by_pass_enabled_(false),
support_fast_single_row_agg_(false),
skew_detection_enabled_(false),
llc_ndv_est_enabled_(false)
llc_ndv_est_enabled_(false),
implicit_aggr_in_3stage_indexes_(alloc)
{
}
DECLARE_VIRTUAL_TO_STRING;
@ -62,6 +63,7 @@ public:
bool support_fast_single_row_agg_;
bool skew_detection_enabled_;
bool llc_ndv_est_enabled_;
ObFixedArray<int64_t, common::ObIAllocator> implicit_aggr_in_3stage_indexes_;
};
//modifiable

View File

@ -1398,7 +1398,9 @@ int ObHashGroupByVecOp::load_data_batch(int64_t max_row_cnt)
if (OB_FAIL(ret)) {
} else if (OB_FAIL(aggr_processor_.add_one_row(start_agg_id, end_agg_id,
batch_new_rows_[i], i,
child_brs->size_, aggr_vectors_))) {
child_brs->size_, aggr_vectors_,
MY_SPEC.implicit_aggr_in_3stage_indexes_))) {
LOG_WARN("fail to process row", K(ret));
}
}
@ -1433,7 +1435,8 @@ int ObHashGroupByVecOp::load_data_batch(int64_t max_row_cnt)
if (OB_SUCC(ret)) {
if (OB_FAIL(aggr_processor_.add_one_row(start_agg_id, end_agg_id,
batch_old_rows_[i], i,
child_brs->size_, aggr_vectors_))) {
child_brs->size_, aggr_vectors_,
MY_SPEC.implicit_aggr_in_3stage_indexes_))) {
LOG_WARN("fail to process row", K(ret));
}
}
@ -2356,7 +2359,8 @@ int ObHashGroupByVecOp::by_pass_prepare_one_batch(const int64_t batch_size)
if (OB_FAIL(ret)) {
} else if (OB_FAIL(aggr_processor_.add_one_row(start_agg_id, end_agg_id,
batch_old_rows_[i], i,
brs_.size_, aggr_vectors_))) {
brs_.size_, aggr_vectors_,
MY_SPEC.implicit_aggr_in_3stage_indexes_))) {
LOG_WARN("fail to process row", K(ret));
} else {
brs_.set_skip(i);