[FEAT MERGE] sql execution improvements
Co-authored-by: DengzhiLiu <dengzhiliu@gmail.com> Co-authored-by: Zach41 <zach_41@163.com> Co-authored-by: tushicheng <18829573815@163.com>
This commit is contained in:
@ -35,6 +35,25 @@
|
||||
} \
|
||||
}
|
||||
|
||||
#define ADD_OR_SUB_NMB(fmt) \
|
||||
do { \
|
||||
fmt *columns = static_cast<fmt *>(input_vec); \
|
||||
if (row_sel.is_empty()) { \
|
||||
for (int i = bound.start(); OB_SUCC(ret) && i < bound.end(); i++) { \
|
||||
if (skip.at(i)) { \
|
||||
} else { \
|
||||
ret = add_or_sub_row<fmt>(agg_ctx, *columns, i, agg_col_id, agg_cell, nullptr, \
|
||||
mock_calc_info); \
|
||||
} \
|
||||
} \
|
||||
} else { \
|
||||
for (int i = 0; OB_SUCC(ret) && i < row_sel.size(); i++) { \
|
||||
ret = add_or_sub_row<fmt>(agg_ctx, *columns, row_sel.index(i), agg_col_id, agg_cell, \
|
||||
nullptr, mock_calc_info); \
|
||||
} \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
@ -87,8 +106,8 @@ public:
|
||||
return ret;
|
||||
}
|
||||
inline int add_batch_rows(RuntimeContext &agg_ctx, const int32_t agg_col_id,
|
||||
const sql::ObBitVector &skip, const sql::EvalBound &bound, char *agg_cell,
|
||||
const RowSelector row_sel = RowSelector{}) override
|
||||
const sql::ObBitVector &skip, const sql::EvalBound &bound,
|
||||
char *agg_cell, const RowSelector row_sel = RowSelector{}) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
#ifndef NDEBUG
|
||||
@ -100,45 +119,70 @@ public:
|
||||
OB_ASSERT(param_expr != NULL);
|
||||
ObIVector *input_vec = param_expr->get_vector(agg_ctx.eval_ctx_);
|
||||
VectorFormat in_fmt = param_expr->get_format(agg_ctx.eval_ctx_);
|
||||
uint32_t sum_digits[number::ObNumber::OB_CALC_BUFFER_SIZE] = {0};
|
||||
char buf_alloc1[number::ObNumber::MAX_CALC_BYTE_LEN] = {0};
|
||||
char buf_alloc2[number::ObNumber::MAX_CALC_BYTE_LEN] = {0};
|
||||
ObDataBuffer allocator1(buf_alloc1, number::ObNumber::MAX_CALC_BYTE_LEN);
|
||||
ObDataBuffer allocator2(buf_alloc2, number::ObNumber::MAX_CALC_BYTE_LEN);
|
||||
number::ObNumber result(*reinterpret_cast<number::ObCompactNumber *>(agg_cell));
|
||||
bool all_skip = true;
|
||||
switch (in_fmt) {
|
||||
case common::VEC_UNIFORM: {
|
||||
ACCUMULATE_NMB(ObUniformFormat<false>);
|
||||
break;
|
||||
if (OB_LIKELY(!agg_ctx.removal_info_.enable_removal_opt_)) {
|
||||
uint32_t sum_digits[number::ObNumber::OB_CALC_BUFFER_SIZE] = {0};
|
||||
char buf_alloc1[number::ObNumber::MAX_CALC_BYTE_LEN] = {0};
|
||||
char buf_alloc2[number::ObNumber::MAX_CALC_BYTE_LEN] = {0};
|
||||
ObDataBuffer allocator1(buf_alloc1, number::ObNumber::MAX_CALC_BYTE_LEN);
|
||||
ObDataBuffer allocator2(buf_alloc2, number::ObNumber::MAX_CALC_BYTE_LEN);
|
||||
number::ObNumber result(*reinterpret_cast<number::ObCompactNumber *>(agg_cell));
|
||||
bool all_skip = true;
|
||||
switch (in_fmt) {
|
||||
case common::VEC_UNIFORM: {
|
||||
ACCUMULATE_NMB(ObUniformFormat<false>);
|
||||
break;
|
||||
}
|
||||
case common::VEC_UNIFORM_CONST: {
|
||||
ACCUMULATE_NMB(ObUniformFormat<true>);
|
||||
break;
|
||||
}
|
||||
case common::VEC_DISCRETE: {
|
||||
ACCUMULATE_NMB(ObDiscreteFormat);
|
||||
break;
|
||||
}
|
||||
case common::VEC_CONTINUOUS: {
|
||||
ACCUMULATE_NMB(ObContinuousFormat);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SQL_LOG(WARN, "unexpected format for sum aggregate", K(ret), K(*this), K(in_fmt));
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
SQL_LOG(WARN, "accumulate number failed", K(ret));
|
||||
} else if (OB_LIKELY(!all_skip)) {
|
||||
NotNullBitVector ¬_nulls = agg_ctx.locate_notnulls_bitmap(agg_col_id, agg_cell);
|
||||
not_nulls.set(agg_col_id);
|
||||
number::ObCompactNumber *cnum = reinterpret_cast<number::ObCompactNumber *>(agg_cell);
|
||||
cnum->desc_ = result.d_;
|
||||
MEMCPY(&(cnum->digits_[0]), result.get_digits(), result.d_.len_ * sizeof(uint32_t));
|
||||
}
|
||||
SQL_LOG(DEBUG, "number result", K(result), K(all_skip), K(ret));
|
||||
} else {
|
||||
int64_t mock_calc_info = 0;
|
||||
switch(in_fmt) {
|
||||
case common::VEC_UNIFORM: {
|
||||
ADD_OR_SUB_NMB(ObUniformFormat<false>);
|
||||
break;
|
||||
}
|
||||
case common::VEC_DISCRETE: {
|
||||
ADD_OR_SUB_NMB(ObDiscreteFormat);
|
||||
break;
|
||||
}
|
||||
case common::VEC_UNIFORM_CONST: {
|
||||
ADD_OR_SUB_NMB(ObUniformFormat<true>);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SQL_LOG(WARN, "invalid input format", K(ret), K(in_fmt));
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
SQL_LOG(WARN, "add or sub rows failed", K(ret));
|
||||
}
|
||||
}
|
||||
case common::VEC_UNIFORM_CONST: {
|
||||
ACCUMULATE_NMB(ObUniformFormat<true>);
|
||||
break;
|
||||
}
|
||||
case common::VEC_DISCRETE: {
|
||||
ACCUMULATE_NMB(ObDiscreteFormat);
|
||||
break;
|
||||
}
|
||||
case common::VEC_CONTINUOUS: {
|
||||
ACCUMULATE_NMB(ObContinuousFormat);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SQL_LOG(WARN, "unexpected format for sum aggregate", K(ret), K(*this), K(in_fmt));
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
SQL_LOG(WARN, "accumulate number failed", K(ret));
|
||||
} else if (OB_LIKELY(!all_skip)) {
|
||||
NotNullBitVector ¬_nulls = agg_ctx.locate_notnulls_bitmap(agg_col_id, agg_cell);
|
||||
not_nulls.set(agg_col_id);
|
||||
number::ObCompactNumber *cnum = reinterpret_cast<number::ObCompactNumber *>(agg_cell);
|
||||
cnum->desc_ = result.d_;
|
||||
MEMCPY(&(cnum->digits_[0]), result.get_digits(), result.d_.len_ * sizeof(uint32_t));
|
||||
}
|
||||
SQL_LOG(DEBUG, "number result", K(result), K(all_skip), K(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -182,6 +226,40 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename ColumnFmt>
|
||||
int add_or_sub_row(RuntimeContext &agg_ctx, ColumnFmt &columns, const int32_t row_num,
|
||||
const int32_t agg_col_id, char *agg_cell, void *tmp_res, int64_t &calc_info)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSEDx(tmp_res, calc_info);
|
||||
bool is_trans = !agg_ctx.removal_info_.is_inverse_agg_;
|
||||
if (!columns.is_null(row_num)) {
|
||||
const number::ObCompactNumber *param_cnum =
|
||||
reinterpret_cast<const number::ObCompactNumber *>(columns.get_payload(row_num));
|
||||
number::ObCompactNumber *res_cnum = reinterpret_cast<number::ObCompactNumber *>(agg_cell);
|
||||
number::ObNumber param1(*param_cnum);
|
||||
number::ObNumber param2(*reinterpret_cast<number::ObCompactNumber *>(agg_cell));
|
||||
number::ObNumber res_nmb;
|
||||
ObNumStackOnceAlloc tmp_alloc;
|
||||
if (is_trans) {
|
||||
if (OB_FAIL(param2.add_v3(param1, res_nmb, tmp_alloc))) {
|
||||
SQL_LOG(WARN, "add number failed", K(ret));
|
||||
}
|
||||
} else if (OB_FAIL(param2.sub_v3(param1, res_nmb, tmp_alloc))){
|
||||
SQL_LOG(WARN, "sub number failed", K(ret));
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
res_cnum->desc_ = res_nmb.d_;
|
||||
MEMCPY(&(res_cnum->digits_[0]), res_nmb.get_digits(), res_nmb.d_.len_ * sizeof(uint32_t));
|
||||
}
|
||||
} else if (is_trans){
|
||||
agg_ctx.removal_info_.null_cnt_++;
|
||||
} else {
|
||||
agg_ctx.removal_info_.null_cnt_--;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
TO_STRING_KV("aggregate", "sum_nmb", K_(is_ora_count_sum));
|
||||
private:
|
||||
template<typename ColumnFmt, bool has_null>
|
||||
@ -275,4 +353,5 @@ private:
|
||||
} // end share
|
||||
} // end oceanbase
|
||||
#undef ACCUMULATE_NMB
|
||||
#undef ADD_OR_SUB_NMB
|
||||
#endif // OCEANBASE_SHARE_AGGREGATE_SUM_NMB_H_
|
||||
Reference in New Issue
Block a user