[CP] [CP] [CP] Fix rollup SIGSEGV when building stored row
This commit is contained in:
@ -394,7 +394,7 @@ int64_t ObAggregateProcessor::ExtraResult::to_string(char* buf, const int64_t bu
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObAggrInfo::eval_aggr(ObChunkDatumStore::ShadowStoredRow<>& curr_row_results, ObEvalCtx& ctx) const
|
int ObAggrInfo::eval_aggr(ObChunkDatumStore::ShadowStoredRow& curr_row_results, ObEvalCtx& ctx) const
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
if (param_exprs_.empty() && T_FUN_COUNT == get_expr_type()) {
|
if (param_exprs_.empty() && T_FUN_COUNT == get_expr_type()) {
|
||||||
@ -1908,7 +1908,7 @@ int ObAggregateProcessor::collect_aggr_result(AggrCell& aggr_cell, const ObExpr*
|
|||||||
const ObChunkDatumStore::StoredRow* storted_row = NULL;
|
const ObChunkDatumStore::StoredRow* storted_row = NULL;
|
||||||
int64_t rank_num = 0;
|
int64_t rank_num = 0;
|
||||||
bool need_check_order_equal = T_FUN_GROUP_DENSE_RANK == aggr_fun;
|
bool need_check_order_equal = T_FUN_GROUP_DENSE_RANK == aggr_fun;
|
||||||
ObChunkDatumStore::LastStoredRow<> prev_row(aggr_alloc_);
|
ObChunkDatumStore::LastStoredRow prev_row(aggr_alloc_);
|
||||||
int64_t total_sort_row_cnt = extra->get_row_count();
|
int64_t total_sort_row_cnt = extra->get_row_count();
|
||||||
bool is_first = true;
|
bool is_first = true;
|
||||||
while (OB_SUCC(ret) && OB_SUCC(extra->get_next_row(storted_row))) {
|
while (OB_SUCC(ret) && OB_SUCC(extra->get_next_row(storted_row))) {
|
||||||
@ -2044,7 +2044,7 @@ int ObAggregateProcessor::collect_aggr_result(AggrCell& aggr_cell, const ObExpr*
|
|||||||
const int64_t total_row_count = extra->get_row_count();
|
const int64_t total_row_count = extra->get_row_count();
|
||||||
char buf_alloc[number::ObNumber::MAX_CALC_BYTE_LEN];
|
char buf_alloc[number::ObNumber::MAX_CALC_BYTE_LEN];
|
||||||
ObDataBuffer allocator(buf_alloc, number::ObNumber::MAX_CALC_BYTE_LEN);
|
ObDataBuffer allocator(buf_alloc, number::ObNumber::MAX_CALC_BYTE_LEN);
|
||||||
ObChunkDatumStore::LastStoredRow<> prev_row(aggr_alloc_);
|
ObChunkDatumStore::LastStoredRow prev_row(aggr_alloc_);
|
||||||
number::ObNumber factor;
|
number::ObNumber factor;
|
||||||
bool need_linear_inter = false;
|
bool need_linear_inter = false;
|
||||||
int64_t not_null_start_loc = 0;
|
int64_t not_null_start_loc = 0;
|
||||||
@ -2163,7 +2163,7 @@ int ObAggregateProcessor::collect_aggr_result(AggrCell& aggr_cell, const ObExpr*
|
|||||||
LOG_WARN("finish_add_row failed", KPC(extra), K(ret));
|
LOG_WARN("finish_add_row failed", KPC(extra), K(ret));
|
||||||
} else {
|
} else {
|
||||||
const ObChunkDatumStore::StoredRow* storted_row = NULL;
|
const ObChunkDatumStore::StoredRow* storted_row = NULL;
|
||||||
ObChunkDatumStore::LastStoredRow<> first_row(aggr_alloc_);
|
ObChunkDatumStore::LastStoredRow first_row(aggr_alloc_);
|
||||||
bool is_first = true;
|
bool is_first = true;
|
||||||
while (OB_SUCC(ret) && OB_SUCC(extra->get_next_row(storted_row))) {
|
while (OB_SUCC(ret) && OB_SUCC(extra->get_next_row(storted_row))) {
|
||||||
bool is_equal = false;
|
bool is_equal = false;
|
||||||
@ -2925,7 +2925,7 @@ int ObAggregateProcessor::compare_calc(const ObDatum& left_value, const ObDatum&
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObAggregateProcessor::check_rows_equal(const ObChunkDatumStore::LastStoredRow<>& prev_row,
|
int ObAggregateProcessor::check_rows_equal(const ObChunkDatumStore::LastStoredRow& prev_row,
|
||||||
const ObChunkDatumStore::StoredRow& cur_row, const ObAggrInfo& aggr_info, bool& is_equal)
|
const ObChunkDatumStore::StoredRow& cur_row, const ObAggrInfo& aggr_info, bool& is_equal)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
@ -3190,7 +3190,7 @@ int ObAggregateProcessor::get_wm_concat_result(
|
|||||||
LOG_WARN("finish_add_row failed", KPC(extra), K(ret));
|
LOG_WARN("finish_add_row failed", KPC(extra), K(ret));
|
||||||
} else {
|
} else {
|
||||||
ObString sep_str = ObCharsetUtils::get_const_str(aggr_info.expr_->datum_meta_.cs_type_, ',');
|
ObString sep_str = ObCharsetUtils::get_const_str(aggr_info.expr_->datum_meta_.cs_type_, ',');
|
||||||
ObChunkDatumStore::LastStoredRow<> first_row(aggr_alloc_);
|
ObChunkDatumStore::LastStoredRow first_row(aggr_alloc_);
|
||||||
const ObChunkDatumStore::StoredRow* storted_row = NULL;
|
const ObChunkDatumStore::StoredRow* storted_row = NULL;
|
||||||
bool is_first = true;
|
bool is_first = true;
|
||||||
bool need_continue = true;
|
bool need_continue = true;
|
||||||
|
|||||||
@ -62,7 +62,7 @@ public:
|
|||||||
? 1
|
? 1
|
||||||
: ((T_FUN_COUNT == get_expr_type() && param_exprs_.empty()) ? 0 : param_exprs_.count());
|
: ((T_FUN_COUNT == get_expr_type() && param_exprs_.empty()) ? 0 : param_exprs_.count());
|
||||||
}
|
}
|
||||||
int eval_aggr(ObChunkDatumStore::ShadowStoredRow<>& curr_row_results, ObEvalCtx& ctx) const;
|
int eval_aggr(ObChunkDatumStore::ShadowStoredRow& curr_row_results, ObEvalCtx& ctx) const;
|
||||||
inline void set_implicit_first_aggr()
|
inline void set_implicit_first_aggr()
|
||||||
{
|
{
|
||||||
is_implicit_first_aggr_ = true;
|
is_implicit_first_aggr_ = true;
|
||||||
@ -326,7 +326,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ObChunkDatumStore::ShadowStoredRow<> curr_row_results_;
|
ObChunkDatumStore::ShadowStoredRow curr_row_results_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// for avg/count
|
// for avg/count
|
||||||
@ -466,7 +466,7 @@ private:
|
|||||||
int rollup_distinct(AggrCell& aggr_cell, AggrCell& rollup_cell);
|
int rollup_distinct(AggrCell& aggr_cell, AggrCell& rollup_cell);
|
||||||
int compare_calc(const ObDatum& left_value, const ObDatum& right_value, const ObAggrInfo& aggr_info, int64_t index,
|
int compare_calc(const ObDatum& left_value, const ObDatum& right_value, const ObAggrInfo& aggr_info, int64_t index,
|
||||||
int& compare_result, bool& is_asc);
|
int& compare_result, bool& is_asc);
|
||||||
int check_rows_equal(const ObChunkDatumStore::LastStoredRow<>& prev_row, const ObChunkDatumStore::StoredRow& cur_row,
|
int check_rows_equal(const ObChunkDatumStore::LastStoredRow& prev_row, const ObChunkDatumStore::StoredRow& cur_row,
|
||||||
const ObAggrInfo& aggr_info, bool& is_equal);
|
const ObAggrInfo& aggr_info, bool& is_equal);
|
||||||
int get_wm_concat_result(
|
int get_wm_concat_result(
|
||||||
const ObAggrInfo& aggr_info, GroupConcatExtraResult*& extra, bool is_keep_group_concat, ObDatum& concat_result);
|
const ObAggrInfo& aggr_info, GroupConcatExtraResult*& extra, bool is_keep_group_concat, ObDatum& concat_result);
|
||||||
|
|||||||
@ -50,7 +50,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef ObChunkDatumStore::LastStoredRow<ObChunkDatumStore::StoredRow> LastStoreRow;
|
typedef ObChunkDatumStore::LastStoredRow LastStoreRow;
|
||||||
bool first_got_row_;
|
bool first_got_row_;
|
||||||
common::ObArenaAllocator alloc_;
|
common::ObArenaAllocator alloc_;
|
||||||
LastStoreRow last_row_;
|
LastStoreRow last_row_;
|
||||||
@ -60,4 +60,4 @@ private:
|
|||||||
} // end namespace sql
|
} // end namespace sql
|
||||||
} // end namespace oceanbase
|
} // end namespace oceanbase
|
||||||
|
|
||||||
#endif /* OCEANBASE_SRC_SQL_ENGINE_AGGREGATE_OB_MERGE_DISTINCT_OP_H_ */
|
#endif /* OCEANBASE_SRC_SQL_ENGINE_AGGREGATE_OB_MERGE_DISTINCT_OP_H_ */
|
||||||
|
|||||||
@ -97,7 +97,7 @@ private:
|
|||||||
// added to support groupby with rollup
|
// added to support groupby with rollup
|
||||||
int64_t cur_output_group_id_;
|
int64_t cur_output_group_id_;
|
||||||
int64_t first_output_group_id_;
|
int64_t first_output_group_id_;
|
||||||
ObChunkDatumStore::LastStoredRow<> last_child_output_;
|
ObChunkDatumStore::LastStoredRow last_child_output_;
|
||||||
DatumFixedArray curr_groupby_datums_;
|
DatumFixedArray curr_groupby_datums_;
|
||||||
int64_t dir_id_;
|
int64_t dir_id_;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -57,113 +57,6 @@ void point2pointer(T*& dst_pointer, B* dst_base, T* src_pointer, const B* src_ba
|
|||||||
dst_pointer = reinterpret_cast<T*>(reinterpret_cast<char*>(dst_base) + reinterpret_cast<intptr_t>(src_pointer) -
|
dst_pointer = reinterpret_cast<T*>(reinterpret_cast<char*>(dst_base) + reinterpret_cast<intptr_t>(src_pointer) -
|
||||||
reinterpret_cast<const char*>(src_base));
|
reinterpret_cast<const char*>(src_base));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chunk_datum_store
|
|
||||||
|
|
||||||
int ObChunkDatumStore::StoredRow::copy_datums(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx, char* buf,
|
|
||||||
const int64_t size, const int64_t row_size, const uint32_t row_extend_size)
|
|
||||||
{
|
|
||||||
int ret = OB_SUCCESS;
|
|
||||||
if (payload_ != buf || size < 0) {
|
|
||||||
ret = OB_INVALID_ARGUMENT;
|
|
||||||
LOG_WARN("invalid argument", K(ret), KP(payload_), KP(buf), K(size));
|
|
||||||
} else {
|
|
||||||
cnt_ = static_cast<uint32_t>(exprs.count());
|
|
||||||
int64_t pos = sizeof(ObDatum) * cnt_ + row_extend_size;
|
|
||||||
row_size_ = static_cast<int32_t>(row_size);
|
|
||||||
for (int64_t i = 0; OB_SUCC(ret) && i < cnt_; ++i) {
|
|
||||||
ObDatum& in_datum = static_cast<ObDatum&>(exprs.at(i)->locate_expr_datum(ctx));
|
|
||||||
ObDatum* datum = new (&cells()[i]) ObDatum();
|
|
||||||
if (OB_FAIL(datum->deep_copy(in_datum, buf, size, pos))) {
|
|
||||||
LOG_WARN("failed to copy datum", K(ret), K(i), K(pos), K(size), K(row_size), K(in_datum), K(*datum));
|
|
||||||
} else {
|
|
||||||
LOG_DEBUG("succ to copy_datums", K(cnt_), K(i), K(size), K(row_size), K(in_datum), K(*datum));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ObChunkDatumStore::StoredRow::copy_datums(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx, int64_t& row_size,
|
|
||||||
char* buf, const int64_t max_buf_size, const uint32_t row_extend_size)
|
|
||||||
{
|
|
||||||
int ret = OB_SUCCESS;
|
|
||||||
if (max_buf_size < 0) {
|
|
||||||
ret = OB_INVALID_ARGUMENT;
|
|
||||||
LOG_WARN("invalid argument", K(ret), KP(payload_), KP(buf), K(max_buf_size));
|
|
||||||
} else {
|
|
||||||
cnt_ = static_cast<uint32_t>(exprs.count());
|
|
||||||
int64_t pos = sizeof(ObDatum) * cnt_ + row_extend_size + sizeof(StoredRow);
|
|
||||||
ObDatum* datums = cells();
|
|
||||||
if (pos > max_buf_size) {
|
|
||||||
ret = OB_BUF_NOT_ENOUGH;
|
|
||||||
} else {
|
|
||||||
for (int64_t i = 0; OB_SUCC(ret) && i < cnt_; ++i) {
|
|
||||||
ObDatum* in_datum = nullptr;
|
|
||||||
ObDatum* datum = (ObDatum*)datums;
|
|
||||||
if (OB_FAIL(exprs.at(i)->eval(ctx, in_datum))) {
|
|
||||||
LOG_WARN("failed to eval datum", K(ret));
|
|
||||||
} else if (OB_FAIL(datum->deep_copy(*in_datum, buf, max_buf_size, pos))) {
|
|
||||||
if (OB_BUF_NOT_ENOUGH != ret) {
|
|
||||||
LOG_WARN("failed to copy datum", K(ret), K(i), K(pos), K(max_buf_size), KP(in_datum), K(*datum));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOG_DEBUG("succ to copy_datums", K(cnt_), K(i), K(max_buf_size), KP(in_datum), K(*datum));
|
|
||||||
}
|
|
||||||
++datums;
|
|
||||||
}
|
|
||||||
row_size_ = static_cast<int32_t>(pos);
|
|
||||||
row_size = row_size_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ObChunkDatumStore::StoredRow::copy_datums(common::ObDatum** datums, const int64_t cnt, char* buf,
|
|
||||||
const int64_t size, const int64_t row_size, const uint32_t row_extend_size)
|
|
||||||
{
|
|
||||||
int ret = OB_SUCCESS;
|
|
||||||
if (payload_ != buf || size < 0 || nullptr == datums) {
|
|
||||||
ret = OB_INVALID_ARGUMENT;
|
|
||||||
LOG_WARN("invalid argument", K(ret), KP(payload_), KP(buf), K(size), K(datums));
|
|
||||||
} else {
|
|
||||||
cnt_ = static_cast<uint32_t>(cnt);
|
|
||||||
int64_t pos = sizeof(ObDatum) * cnt_ + row_extend_size;
|
|
||||||
row_size_ = static_cast<int32_t>(row_size);
|
|
||||||
for (int64_t i = 0; OB_SUCC(ret) && i < cnt_; ++i) {
|
|
||||||
if (nullptr == datums[i]) {
|
|
||||||
ret = OB_INVALID_ARGUMENT;
|
|
||||||
LOG_WARN("invalid argument", K(ret), KP(payload_), KP(buf), K(size), K(datums));
|
|
||||||
} else {
|
|
||||||
ObDatum* datum = new (&cells()[i]) ObDatum();
|
|
||||||
if (OB_FAIL(datum->deep_copy(*datums[i], buf, size, pos))) {
|
|
||||||
LOG_WARN(
|
|
||||||
"failed to copy datum", K(ret), K(i), K(pos), K(size), K(row_size), K(*datums[i]), K(datums[i]->len_));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ObChunkDatumStore::StoredRow::copy_datums(common::ObDatum* datums, const int64_t cnt, char* buf, const int64_t size,
|
|
||||||
const int64_t row_size, const uint32_t row_extend_size)
|
|
||||||
{
|
|
||||||
int ret = OB_SUCCESS;
|
|
||||||
if (payload_ != buf || size < 0 || nullptr == datums) {
|
|
||||||
ret = OB_INVALID_ARGUMENT;
|
|
||||||
LOG_WARN("invalid argument", K(ret), KP(payload_), KP(buf), K(size), K(datums));
|
|
||||||
} else {
|
|
||||||
cnt_ = static_cast<uint32_t>(cnt);
|
|
||||||
row_size_ = static_cast<int32_t>(row_size);
|
|
||||||
MEMCPY(buf, static_cast<const void*>(datums), size);
|
|
||||||
int64_t pos = sizeof(ObDatum) * cnt_ + row_extend_size;
|
|
||||||
for (int64_t i = 0; i < cnt_; ++i) {
|
|
||||||
cells()[i].ptr_ = buf + pos;
|
|
||||||
pos += cells()[i].len_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObChunkDatumStore::StoredRow::to_expr(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx) const
|
int ObChunkDatumStore::StoredRow::to_expr(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx) const
|
||||||
@ -230,6 +123,54 @@ void ObChunkDatumStore::StoredRow::swizzling(char* base /*= NULL*/)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ObChunkDatumStore::StoredRow::build(StoredRow *&sr, const ObExprPtrIArray &exprs, ObEvalCtx &ctx, char *buf,
|
||||||
|
const int64_t buf_len, const uint32_t extra_size /* = 0 */)
|
||||||
|
{
|
||||||
|
int ret = OB_SUCCESS;
|
||||||
|
sr = reinterpret_cast<StoredRow *>(buf);
|
||||||
|
int64_t pos = sizeof(*sr) + sizeof(ObDatum) * exprs.count() + extra_size;
|
||||||
|
if (pos > buf_len) {
|
||||||
|
ret = OB_BUF_NOT_ENOUGH;
|
||||||
|
} else {
|
||||||
|
sr->cnt_ = exprs.count();
|
||||||
|
ObDatum *datums = sr->cells();
|
||||||
|
for (int64_t i = 0; i < exprs.count() && OB_SUCC(ret); i++) {
|
||||||
|
ObExpr *expr = exprs.at(i);
|
||||||
|
ObDatum *in_datum = NULL;
|
||||||
|
if (OB_UNLIKELY(NULL == expr)) {
|
||||||
|
// Set datum to NULL for NULL expr
|
||||||
|
datums[i].set_null();
|
||||||
|
} else if (OB_FAIL(expr->eval(ctx, in_datum))) {
|
||||||
|
LOG_WARN("expression evaluate failed", K(ret));
|
||||||
|
} else {
|
||||||
|
ret = datums[i].deep_copy(*in_datum, buf, buf_len, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (OB_SUCC(ret)) {
|
||||||
|
sr->row_size_ = static_cast<int32_t>(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ObChunkDatumStore::StoredRow::build(StoredRow *&sr, const ObExprPtrIArray &exprs, ObEvalCtx &ctx,
|
||||||
|
common::ObIAllocator &alloc, const uint32_t extra_size /* = 0 */)
|
||||||
|
{
|
||||||
|
int ret = OB_SUCCESS;
|
||||||
|
int64_t size = 0;
|
||||||
|
char *buf = NULL;
|
||||||
|
if (OB_FAIL(Block::row_store_size(exprs, ctx, size, extra_size))) {
|
||||||
|
LOG_WARN("get row store size failed", K(ret));
|
||||||
|
} else if (NULL == (buf = static_cast<char *>(alloc.alloc(size)))) {
|
||||||
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
|
LOG_WARN("allocate memory failed", K(ret), K(size));
|
||||||
|
} else if (OB_FAIL(build(sr, exprs, ctx, buf, size, extra_size))) {
|
||||||
|
LOG_WARN("build stored row failed", K(ret));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int ObChunkDatumStore::Block::add_row(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx, const int64_t row_size,
|
int ObChunkDatumStore::Block::add_row(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx, const int64_t row_size,
|
||||||
uint32_t row_extend_size, StoredRow** stored_row)
|
uint32_t row_extend_size, StoredRow** stored_row)
|
||||||
{
|
{
|
||||||
@ -242,18 +183,15 @@ int ObChunkDatumStore::Block::add_row(const common::ObIArray<ObExpr*>& exprs, Ob
|
|||||||
ret = OB_BUF_NOT_ENOUGH;
|
ret = OB_BUF_NOT_ENOUGH;
|
||||||
LOG_WARN("buffer not enough", K(row_size), "remain", buf->remain());
|
LOG_WARN("buffer not enough", K(row_size), "remain", buf->remain());
|
||||||
} else {
|
} else {
|
||||||
StoredRow* sr = (StoredRow*)buf->head();
|
StoredRow *sr = NULL;
|
||||||
if (OB_FAIL(sr->copy_datums(
|
if (OB_FAIL(StoredRow::build(sr, exprs, ctx, buf->head(), row_size, row_extend_size))) {
|
||||||
exprs, ctx, buf->head() + ROW_HEAD_SIZE, row_size - ROW_HEAD_SIZE, row_size, row_extend_size))) {
|
LOG_WARN("build stored row failed", K(ret));
|
||||||
LOG_WARN("copy row failed", K(ret), K(row_size));
|
} else if (OB_FAIL(buf->advance(row_size))) {
|
||||||
|
LOG_WARN("fill buffer head failed", K(ret), K(buf), K(row_size));
|
||||||
} else {
|
} else {
|
||||||
if (OB_FAIL(buf->advance(row_size))) {
|
rows_++;
|
||||||
LOG_WARN("fill buffer head failed", K(ret), K(buf), K(row_size));
|
if (NULL != stored_row) {
|
||||||
} else {
|
*stored_row = sr;
|
||||||
rows_++;
|
|
||||||
if (NULL != stored_row) {
|
|
||||||
*stored_row = sr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,25 +206,17 @@ int ObChunkDatumStore::Block::append_row(const common::ObIArray<ObExpr*>& exprs,
|
|||||||
ret = OB_INVALID_ARGUMENT;
|
ret = OB_INVALID_ARGUMENT;
|
||||||
LOG_WARN("invalid argument", K(ret), K(buf));
|
LOG_WARN("invalid argument", K(ret), K(buf));
|
||||||
} else {
|
} else {
|
||||||
int64_t max_size = buf->remain();
|
StoredRow *sr = NULL;
|
||||||
if (ROW_HEAD_SIZE > max_size) {
|
if (OB_FAIL(StoredRow::build(sr, exprs, *ctx, buf->head(), buf->remain(), row_extend_size))) {
|
||||||
ret = OB_BUF_NOT_ENOUGH;
|
if (OB_BUF_NOT_ENOUGH != ret) {
|
||||||
|
LOG_WARN("build stored row failed", K(ret));
|
||||||
|
}
|
||||||
|
} else if (OB_FAIL(buf->advance(sr->row_size_))) {
|
||||||
|
LOG_WARN("buffer advance failed", K(ret));
|
||||||
} else {
|
} else {
|
||||||
StoredRow* sr = (StoredRow*)buf->head();
|
++rows_;
|
||||||
int64_t row_size = 0;
|
if (NULL != stored_row) {
|
||||||
if (OB_FAIL(sr->copy_datums(exprs, *ctx, row_size, buf->head(), max_size, row_extend_size))) {
|
*stored_row = sr;
|
||||||
if (OB_BUF_NOT_ENOUGH != ret) {
|
|
||||||
LOG_WARN("copy row failed", K(ret), K(max_size));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (OB_FAIL(buf->advance(row_size))) {
|
|
||||||
LOG_WARN("fill buffer head failed", K(ret), K(buf));
|
|
||||||
} else {
|
|
||||||
++rows_;
|
|
||||||
if (NULL != stored_row) {
|
|
||||||
*stored_row = sr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,36 +34,6 @@ class ObChunkDatumStore {
|
|||||||
OB_UNIS_VERSION_V(1);
|
OB_UNIS_VERSION_V(1);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static inline int row_copy_size(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx, int64_t& size)
|
|
||||||
{
|
|
||||||
int ret = OB_SUCCESS;
|
|
||||||
common::ObDatum* datum = nullptr;
|
|
||||||
size = DATUM_SIZE * exprs.count();
|
|
||||||
for (int64_t i = 0; i < exprs.count() && OB_SUCC(ret); ++i) {
|
|
||||||
if (OB_FAIL(exprs.at(i)->eval(ctx, datum))) {
|
|
||||||
SQL_ENG_LOG(WARN, "failed to eval expr datum", KPC(exprs.at(i)), K(ret));
|
|
||||||
} else {
|
|
||||||
size += datum->len_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
static inline int64_t row_copy_size(common::ObDatum** datums, const int64_t cnt)
|
|
||||||
{
|
|
||||||
int64_t size = DATUM_SIZE * cnt;
|
|
||||||
for (int64_t i = 0; i < cnt; ++i) {
|
|
||||||
size += datums[i]->len_;
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
static inline int64_t row_copy_size(common::ObDatum* datums, const int64_t cnt)
|
|
||||||
{
|
|
||||||
int64_t size = DATUM_SIZE * cnt;
|
|
||||||
for (int64_t i = 0; i < cnt; ++i) {
|
|
||||||
size += datums[i].len_;
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* StoredRow memory layout
|
* StoredRow memory layout
|
||||||
* N Datum + extend_size(can be 0) + real data
|
* N Datum + extend_size(can be 0) + real data
|
||||||
@ -75,16 +45,22 @@ public:
|
|||||||
struct StoredRow {
|
struct StoredRow {
|
||||||
StoredRow() : cnt_(0), row_size_(0)
|
StoredRow() : cnt_(0), row_size_(0)
|
||||||
{}
|
{}
|
||||||
int copy_datums(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx, char* buf, const int64_t size,
|
|
||||||
const int64_t row_size, const uint32_t row_extend_size);
|
|
||||||
int copy_datums(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx, int64_t& row_size, char* buf,
|
|
||||||
const int64_t max_buf_size, const uint32_t row_extend_size);
|
|
||||||
int copy_datums(common::ObDatum** datums, const int64_t cnt, char* buf, const int64_t size, const int64_t row_size,
|
|
||||||
const uint32_t row_extend_size);
|
|
||||||
int copy_datums(common::ObDatum* datums, const int64_t cnt, char* buf, const int64_t size, const int64_t row_size,
|
|
||||||
const uint32_t row_extend_size);
|
|
||||||
int to_expr(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx) const;
|
int to_expr(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx) const;
|
||||||
int to_expr(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx, int64_t count) const;
|
int to_expr(const common::ObIArray<ObExpr*>& exprs, ObEvalCtx& ctx, int64_t count) const;
|
||||||
|
// Build a stored row by exprs.
|
||||||
|
// @param [out] sr, result stored row
|
||||||
|
// @param epxrs,
|
||||||
|
// @param ctx
|
||||||
|
// @param buf
|
||||||
|
// @param buf_len, use Block::row_store_size() to detect the needed buffer size.
|
||||||
|
// @param extra_size, extra store size
|
||||||
|
// @param unswizzling
|
||||||
|
// @return OB_SUCCESS or OB_BUF_NOT_ENOUGH if buf not enough
|
||||||
|
static int build(StoredRow *&sr, const ObExprPtrIArray &exprs, ObEvalCtx &ctx, char *buf, const int64_t buf_len,
|
||||||
|
const uint32_t extra_size = 0);
|
||||||
|
static int build(StoredRow *&sr, const ObExprPtrIArray &exprs, ObEvalCtx &ctx, common::ObIAllocator &alloc,
|
||||||
|
const uint32_t extra_size = 0);
|
||||||
|
|
||||||
|
|
||||||
inline common::ObDatum* cells()
|
inline common::ObDatum* cells()
|
||||||
{
|
{
|
||||||
@ -117,7 +93,6 @@ public:
|
|||||||
* 2) Provide reuse mode, memory can be reused
|
* 2) Provide reuse mode, memory can be reused
|
||||||
* 3) Provide conversion from StoredRow to ObIArray<ObExpr*>
|
* 3) Provide conversion from StoredRow to ObIArray<ObExpr*>
|
||||||
*/
|
*/
|
||||||
template <typename T = ObChunkDatumStore::StoredRow>
|
|
||||||
class LastStoredRow {
|
class LastStoredRow {
|
||||||
public:
|
public:
|
||||||
LastStoredRow(ObIAllocator& alloc)
|
LastStoredRow(ObIAllocator& alloc)
|
||||||
@ -138,13 +113,13 @@ public:
|
|||||||
char* buf = NULL;
|
char* buf = NULL;
|
||||||
int64_t row_size = 0;
|
int64_t row_size = 0;
|
||||||
int64_t buffer_len = 0;
|
int64_t buffer_len = 0;
|
||||||
T* new_row = NULL;
|
StoredRow* new_row = NULL;
|
||||||
if (0 == exprs.count()) {
|
if (0 == exprs.count()) {
|
||||||
// no column. scenario like distinct 1
|
// no column. scenario like distinct 1
|
||||||
} else if (OB_FAIL(ObChunkDatumStore::row_copy_size(exprs, ctx, row_size))) {
|
} else if (OB_FAIL(ObChunkDatumStore::row_copy_size(exprs, ctx, row_size))) {
|
||||||
SQL_ENG_LOG(WARN, "failed to calc copy size", K(ret));
|
SQL_ENG_LOG(WARN, "failed to calc copy size", K(ret));
|
||||||
} else {
|
} else {
|
||||||
int64_t head_size = sizeof(T);
|
int64_t head_size = sizeof(StoredRow);
|
||||||
reuse = OB_ISNULL(store_row_) ? false : reuse && (max_size_ >= row_size + head_size + extra_size);
|
reuse = OB_ISNULL(store_row_) ? false : reuse && (max_size_ >= row_size + head_size + extra_size);
|
||||||
if (reuse && OB_NOT_NULL(store_row_)) {
|
if (reuse && OB_NOT_NULL(store_row_)) {
|
||||||
// switch buffer for write
|
// switch buffer for write
|
||||||
@ -163,24 +138,21 @@ public:
|
|||||||
} else if (OB_ISNULL(buf2 = reinterpret_cast<char*>(alloc_.alloc(buffer_len)))) {
|
} else if (OB_ISNULL(buf2 = reinterpret_cast<char*>(alloc_.alloc(buffer_len)))) {
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
SQL_ENG_LOG(ERROR, "alloc buf failed", K(ret));
|
SQL_ENG_LOG(ERROR, "alloc buf failed", K(ret));
|
||||||
} else if (OB_ISNULL(pre_alloc_row1_ = new (buf1) T())) {
|
} else if (OB_ISNULL(pre_alloc_row1_ = new (buf1) StoredRow())) {
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
SQL_ENG_LOG(ERROR, "failed to new row", K(ret));
|
SQL_ENG_LOG(ERROR, "failed to new row", K(ret));
|
||||||
} else if (OB_ISNULL(pre_alloc_row2_ = new (buf2) T())) {
|
} else if (OB_ISNULL(pre_alloc_row2_ = new (buf2) StoredRow())) {
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
SQL_ENG_LOG(ERROR, "failed to new row", K(ret));
|
SQL_ENG_LOG(ERROR, "failed to new row", K(ret));
|
||||||
} else {
|
} else {
|
||||||
buf = buf1;
|
buf = buf1;
|
||||||
new_row = pre_alloc_row1_;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (OB_SUCC(ret)) {
|
if (OB_SUCC(ret)) {
|
||||||
int64_t pos = head_size;
|
if (OB_FAIL(StoredRow::build(store_row_, exprs, ctx, buf, buffer_len, extra_size))) {
|
||||||
if (OB_FAIL(new_row->copy_datums(exprs, ctx, buf + pos, buffer_len - head_size, row_size, extra_size))) {
|
SQL_ENG_LOG(WARN, "failed to build stored row", K(ret), K(buffer_len), K(row_size));
|
||||||
SQL_ENG_LOG(WARN, "failed to deep copy row", K(ret), K(buffer_len), K(row_size));
|
|
||||||
} else {
|
} else {
|
||||||
max_size_ = buffer_len;
|
max_size_ = buffer_len;
|
||||||
store_row_ = new_row;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,9 +164,9 @@ public:
|
|||||||
bool reuse = reuse_;
|
bool reuse = reuse_;
|
||||||
char* buf = NULL;
|
char* buf = NULL;
|
||||||
int64_t buffer_len = 0;
|
int64_t buffer_len = 0;
|
||||||
T* new_row = NULL;
|
StoredRow* new_row = NULL;
|
||||||
int64_t row_size = row.row_size_;
|
int64_t row_size = row.row_size_;
|
||||||
int64_t head_size = sizeof(T);
|
int64_t head_size = sizeof(StoredRow);
|
||||||
reuse = OB_ISNULL(store_row_) ? false : reuse && (max_size_ >= row_size + head_size + extra_size);
|
reuse = OB_ISNULL(store_row_) ? false : reuse && (max_size_ >= row_size + head_size + extra_size);
|
||||||
if (reuse && OB_NOT_NULL(store_row_)) {
|
if (reuse && OB_NOT_NULL(store_row_)) {
|
||||||
buf = reinterpret_cast<char*>(store_row_);
|
buf = reinterpret_cast<char*>(store_row_);
|
||||||
@ -205,20 +177,15 @@ public:
|
|||||||
if (OB_ISNULL(buf = reinterpret_cast<char*>(alloc_.alloc(buffer_len)))) {
|
if (OB_ISNULL(buf = reinterpret_cast<char*>(alloc_.alloc(buffer_len)))) {
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
SQL_ENG_LOG(ERROR, "alloc buf failed", K(ret));
|
SQL_ENG_LOG(ERROR, "alloc buf failed", K(ret));
|
||||||
} else if (OB_ISNULL(new_row = new (buf) T())) {
|
} else if (OB_ISNULL(new_row = new (buf) StoredRow())) {
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
SQL_ENG_LOG(ERROR, "failed to new row", K(ret));
|
SQL_ENG_LOG(ERROR, "failed to new row", K(ret));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (OB_SUCC(ret)) {
|
if (OB_SUCC(ret)) {
|
||||||
int64_t pos = head_size;
|
int64_t pos = head_size;
|
||||||
if (OB_FAIL(new_row->copy_datums(const_cast<common::ObDatum*>(row.cells()),
|
if (OB_FAIL(new_row->assign(&row))) {
|
||||||
row.cnt_,
|
SQL_ENG_LOG(WARN, "stored row assign failed", K(ret));
|
||||||
buf + pos,
|
|
||||||
buffer_len - head_size,
|
|
||||||
row_size,
|
|
||||||
extra_size))) {
|
|
||||||
SQL_ENG_LOG(WARN, "failed to deep copy row", K(ret), K(buffer_len), K(row_size));
|
|
||||||
} else {
|
} else {
|
||||||
max_size_ = buffer_len;
|
max_size_ = buffer_len;
|
||||||
store_row_ = new_row;
|
store_row_ = new_row;
|
||||||
@ -226,7 +193,7 @@ public:
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
void set_store_row(T* in_store_row)
|
void set_store_row(StoredRow* in_store_row)
|
||||||
{
|
{
|
||||||
store_row_ = in_store_row;
|
store_row_ = in_store_row;
|
||||||
}
|
}
|
||||||
@ -237,18 +204,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
TO_STRING_KV(K_(max_size), K_(reuse), KPC_(store_row));
|
TO_STRING_KV(K_(max_size), K_(reuse), KPC_(store_row));
|
||||||
T* store_row_;
|
StoredRow* store_row_;
|
||||||
ObIAllocator& alloc_;
|
ObIAllocator& alloc_;
|
||||||
int64_t max_size_;
|
int64_t max_size_;
|
||||||
bool reuse_;
|
bool reuse_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// To avoid writing memory overwrite, alloc 2 row for alternate writing
|
// To avoid writing memory overwrite, alloc 2 row for alternate writing
|
||||||
T* pre_alloc_row1_;
|
StoredRow* pre_alloc_row1_;
|
||||||
T* pre_alloc_row2_;
|
StoredRow* pre_alloc_row2_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T = ObChunkDatumStore::StoredRow>
|
|
||||||
class ShadowStoredRow {
|
class ShadowStoredRow {
|
||||||
public:
|
public:
|
||||||
ShadowStoredRow() : alloc_(nullptr), store_row_(nullptr), saved_(false)
|
ShadowStoredRow() : alloc_(nullptr), store_row_(nullptr), saved_(false)
|
||||||
@ -261,7 +227,7 @@ public:
|
|||||||
int init(common::ObIAllocator& allocator, int64_t datum_cnt)
|
int init(common::ObIAllocator& allocator, int64_t datum_cnt)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
int64_t buffer_len = datum_cnt * sizeof(ObDatum) + sizeof(T);
|
int64_t buffer_len = datum_cnt * sizeof(ObDatum) + sizeof(StoredRow);
|
||||||
char* buf = nullptr;
|
char* buf = nullptr;
|
||||||
if (NULL != alloc_) {
|
if (NULL != alloc_) {
|
||||||
ret = common::OB_INIT_TWICE;
|
ret = common::OB_INIT_TWICE;
|
||||||
@ -271,9 +237,9 @@ public:
|
|||||||
SQL_ENG_LOG(ERROR, "alloc buf failed", K(ret));
|
SQL_ENG_LOG(ERROR, "alloc buf failed", K(ret));
|
||||||
} else {
|
} else {
|
||||||
alloc_ = &allocator;
|
alloc_ = &allocator;
|
||||||
store_row_ = new (buf) T();
|
store_row_ = new (buf) StoredRow();
|
||||||
store_row_->cnt_ = datum_cnt;
|
store_row_->cnt_ = datum_cnt;
|
||||||
store_row_->row_size_ = datum_cnt * sizeof(ObDatum);
|
store_row_->row_size_ = datum_cnt * sizeof(ObDatum) + sizeof(StoredRow);
|
||||||
saved_ = false;
|
saved_ = false;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -322,7 +288,7 @@ public:
|
|||||||
saved_ = false;
|
saved_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* get_store_row() const
|
StoredRow* get_store_row() const
|
||||||
{
|
{
|
||||||
return store_row_;
|
return store_row_;
|
||||||
}
|
}
|
||||||
@ -330,7 +296,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
common::ObIAllocator* alloc_;
|
common::ObIAllocator* alloc_;
|
||||||
T* store_row_;
|
StoredRow* store_row_;
|
||||||
bool saved_;
|
bool saved_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -370,18 +336,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// following interface for ObDatum only,unused for now
|
// following interface for ObDatum only,unused for now
|
||||||
static int64_t inline min_buf_size(common::ObDatum** datums, const int64_t cnt)
|
|
||||||
{
|
|
||||||
return BlockBuffer::HEAD_SIZE + sizeof(BlockBuffer) + row_store_size(datums, cnt);
|
|
||||||
}
|
|
||||||
static int64_t inline min_buf_size(common::ObDatum* datums, const int64_t cnt)
|
static int64_t inline min_buf_size(common::ObDatum* datums, const int64_t cnt)
|
||||||
{
|
{
|
||||||
return BlockBuffer::HEAD_SIZE + sizeof(BlockBuffer) + row_store_size(datums, cnt);
|
return BlockBuffer::HEAD_SIZE + sizeof(BlockBuffer) + row_store_size(datums, cnt);
|
||||||
}
|
}
|
||||||
static int64_t inline row_store_size(common::ObDatum** datums, const int64_t cnt, uint32_t row_extend_size = 0)
|
|
||||||
{
|
|
||||||
return ROW_HEAD_SIZE + row_extend_size + ObChunkDatumStore::row_copy_size(datums, cnt);
|
|
||||||
}
|
|
||||||
static int64_t inline row_store_size(common::ObDatum* datums, const int64_t cnt, uint32_t row_extend_size = 0)
|
static int64_t inline row_store_size(common::ObDatum* datums, const int64_t cnt, uint32_t row_extend_size = 0)
|
||||||
{
|
{
|
||||||
return ROW_HEAD_SIZE + row_extend_size + ObChunkDatumStore::row_copy_size(datums, cnt);
|
return ROW_HEAD_SIZE + row_extend_size + ObChunkDatumStore::row_copy_size(datums, cnt);
|
||||||
@ -970,6 +928,30 @@ private:
|
|||||||
callback_->free(size);
|
callback_->free(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int row_copy_size(const common::ObIArray<ObExpr *> &exprs, ObEvalCtx &ctx, int64_t &size)
|
||||||
|
{
|
||||||
|
int ret = OB_SUCCESS;
|
||||||
|
common::ObDatum *datum = nullptr;
|
||||||
|
size = DATUM_SIZE * exprs.count();
|
||||||
|
for (int64_t i = 0; i < exprs.count() && OB_SUCC(ret); ++i) {
|
||||||
|
if (OB_FAIL(exprs.at(i)->eval(ctx, datum))) {
|
||||||
|
SQL_ENG_LOG(WARN, "failed to eval expr datum", KPC(exprs.at(i)), K(ret));
|
||||||
|
} else {
|
||||||
|
size += datum->len_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int64_t row_copy_size(common::ObDatum *datums, const int64_t cnt)
|
||||||
|
{
|
||||||
|
int64_t size = DATUM_SIZE * cnt;
|
||||||
|
for (int64_t i = 0; i < cnt; ++i) {
|
||||||
|
size += datums[i].len_;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool inited_;
|
bool inited_;
|
||||||
uint64_t tenant_id_;
|
uint64_t tenant_id_;
|
||||||
@ -1011,6 +993,8 @@ private:
|
|||||||
DISALLOW_COPY_AND_ASSIGN(ObChunkDatumStore);
|
DISALLOW_COPY_AND_ASSIGN(ObChunkDatumStore);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef ObChunkDatumStore::StoredRow ObStoredDatumRow;
|
||||||
|
|
||||||
inline int ObChunkDatumStore::BlockBuffer::advance(int64_t size)
|
inline int ObChunkDatumStore::BlockBuffer::advance(int64_t size)
|
||||||
{
|
{
|
||||||
int ret = common::OB_SUCCESS;
|
int ret = common::OB_SUCCESS;
|
||||||
@ -1026,7 +1010,6 @@ inline int ObChunkDatumStore::BlockBuffer::advance(int64_t size)
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace sql
|
} // end namespace sql
|
||||||
} // end namespace oceanbase
|
} // end namespace oceanbase
|
||||||
|
|
||||||
|
|||||||
@ -68,7 +68,7 @@ private:
|
|||||||
int64_t total_cnt_;
|
int64_t total_cnt_;
|
||||||
bool is_percent_first_;
|
bool is_percent_first_;
|
||||||
|
|
||||||
ObChunkDatumStore::LastStoredRow<> pre_sort_columns_;
|
ObChunkDatumStore::LastStoredRow pre_sort_columns_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace sql
|
} // end namespace sql
|
||||||
|
|||||||
@ -21,32 +21,9 @@ using namespace oceanbase::common;
|
|||||||
|
|
||||||
int ObConnectByOpPumpBase::deep_copy_row(const ObIArray<ObExpr*>& exprs, const ObChunkDatumStore::StoredRow*& dst_row)
|
int ObConnectByOpPumpBase::deep_copy_row(const ObIArray<ObExpr*>& exprs, const ObChunkDatumStore::StoredRow*& dst_row)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
ObChunkDatumStore::StoredRow* sr = NULL;
|
||||||
char* buf = NULL;
|
int ret = ObChunkDatumStore::StoredRow::build(sr, exprs, *eval_ctx_, allocator_);
|
||||||
int64_t row_size = 0;
|
dst_row = sr;
|
||||||
int64_t buffer_len = 0;
|
|
||||||
int64_t extra_size = 0;
|
|
||||||
int64_t head_size = sizeof(ObChunkDatumStore::StoredRow);
|
|
||||||
int64_t pos = head_size;
|
|
||||||
ObChunkDatumStore::StoredRow* new_row = nullptr;
|
|
||||||
if (OB_FAIL(ObChunkDatumStore::row_copy_size(exprs, *eval_ctx_, row_size))) {
|
|
||||||
SQL_ENG_LOG(WARN, "failed to calc copy size", K(ret));
|
|
||||||
} else {
|
|
||||||
row_size += head_size;
|
|
||||||
buffer_len = row_size + extra_size;
|
|
||||||
if (OB_ISNULL(buf = reinterpret_cast<char*>(allocator_.alloc(buffer_len)))) {
|
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
|
||||||
SQL_ENG_LOG(ERROR, "alloc buf failed", K(ret));
|
|
||||||
} else if (OB_ISNULL(new_row = new (buf) ObChunkDatumStore::StoredRow())) {
|
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
|
||||||
SQL_ENG_LOG(ERROR, "failed to new row", K(ret));
|
|
||||||
} else if (OB_FAIL(
|
|
||||||
new_row->copy_datums(exprs, *eval_ctx_, buf + pos, buffer_len - head_size, row_size, extra_size))) {
|
|
||||||
SQL_ENG_LOG(WARN, "failed to deep copy row", K(ret), K(buffer_len), K(row_size));
|
|
||||||
} else {
|
|
||||||
dst_row = new_row;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -326,31 +326,7 @@ int ObMultiTableInsertUpOp::shuffle_update_row(const ObChunkDatumStore::StoredRo
|
|||||||
int ObMultiTableInsertUpOp::convert_exprs_to_stored_row(
|
int ObMultiTableInsertUpOp::convert_exprs_to_stored_row(
|
||||||
ObIAllocator& allocator, ObEvalCtx& eval_ctx, const ObExprPtrIArray& exprs, ObChunkDatumStore::StoredRow*& new_row)
|
ObIAllocator& allocator, ObEvalCtx& eval_ctx, const ObExprPtrIArray& exprs, ObChunkDatumStore::StoredRow*& new_row)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
return ObChunkDatumStore::StoredRow::build(new_row, exprs, eval_ctx, allocator);
|
||||||
new_row = NULL;
|
|
||||||
char* buf = NULL;
|
|
||||||
int64_t row_size = 0;
|
|
||||||
if (OB_FAIL(ObChunkDatumStore::row_copy_size(exprs, eval_ctx, row_size))) {
|
|
||||||
LOG_WARN("failed to calc copy size", K(ret));
|
|
||||||
} else {
|
|
||||||
const int64_t STORE_ROW_HEADER_SIZE = sizeof(ObChunkDatumStore::StoredRow);
|
|
||||||
int64_t buffer_len = STORE_ROW_HEADER_SIZE + row_size;
|
|
||||||
if (OB_ISNULL(buf = reinterpret_cast<char*>(allocator.alloc(buffer_len)))) {
|
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
|
||||||
LOG_ERROR("alloc buf failed", K(ret));
|
|
||||||
} else if (OB_ISNULL(new_row = new (buf) ObChunkDatumStore::StoredRow())) {
|
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
|
||||||
LOG_ERROR("failed to new row", K(ret));
|
|
||||||
} else {
|
|
||||||
int64_t pos = STORE_ROW_HEADER_SIZE;
|
|
||||||
if (OB_FAIL(new_row->copy_datums(
|
|
||||||
exprs, eval_ctx, buf + pos, buffer_len - STORE_ROW_HEADER_SIZE, row_size, 0 /*extra_size*/))) {
|
|
||||||
LOG_WARN("failed to deep copy row", K(ret), K(buffer_len));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sql
|
} // namespace sql
|
||||||
|
|||||||
@ -689,7 +689,7 @@ private:
|
|||||||
bool postprocessed_left_;
|
bool postprocessed_left_;
|
||||||
bool has_fill_right_row_;
|
bool has_fill_right_row_;
|
||||||
bool has_fill_left_row_;
|
bool has_fill_left_row_;
|
||||||
ObChunkDatumStore::ShadowStoredRow<ObHashJoinStoredJoinRow> right_last_row_;
|
ObChunkDatumStore::ShadowStoredRow right_last_row_;
|
||||||
bool need_return_;
|
bool need_return_;
|
||||||
bool iter_end_;
|
bool iter_end_;
|
||||||
bool opt_cache_aware_;
|
bool opt_cache_aware_;
|
||||||
|
|||||||
@ -192,7 +192,7 @@ private:
|
|||||||
bool has_backup_row_;
|
bool has_backup_row_;
|
||||||
bool reach_end_; // child iterator end
|
bool reach_end_; // child iterator end
|
||||||
bool* left_row_joined_;
|
bool* left_row_joined_;
|
||||||
ObChunkDatumStore::ShadowStoredRow<> store_row_;
|
ObChunkDatumStore::ShadowStoredRow store_row_;
|
||||||
ObOperator* child_;
|
ObOperator* child_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -102,7 +102,7 @@ public:
|
|||||||
ObChunkDatumStore left_store_;
|
ObChunkDatumStore left_store_;
|
||||||
ObChunkDatumStore::Iterator left_store_iter_;
|
ObChunkDatumStore::Iterator left_store_iter_;
|
||||||
bool is_left_end_;
|
bool is_left_end_;
|
||||||
ObChunkDatumStore::ShadowStoredRow<> last_store_row_;
|
ObChunkDatumStore::ShadowStoredRow last_store_row_;
|
||||||
bool save_last_row_;
|
bool save_last_row_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -132,7 +132,7 @@ private:
|
|||||||
DriverState state_; // Driver current state
|
DriverState state_; // Driver current state
|
||||||
|
|
||||||
ObEvalCtx* eval_ctx_;
|
ObEvalCtx* eval_ctx_;
|
||||||
ObChunkDatumStore::LastStoredRow<> last_row_;
|
ObChunkDatumStore::LastStoredRow last_row_;
|
||||||
int64_t last_row_part_id_;
|
int64_t last_row_part_id_;
|
||||||
const ObExprPtrIArray* last_row_expr_;
|
const ObExprPtrIArray* last_row_expr_;
|
||||||
int64_t op_id_;
|
int64_t op_id_;
|
||||||
|
|||||||
@ -129,12 +129,12 @@ int ObPxMSCoordOp::init_store_rows(int64_t n_ways)
|
|||||||
LOG_WARN("unexpected status: store rows is not empty", K(ret), K(n_ways));
|
LOG_WARN("unexpected status: store rows is not empty", K(ret), K(n_ways));
|
||||||
}
|
}
|
||||||
for (int64_t i = 0; i < n_ways && OB_SUCC(ret); ++i) {
|
for (int64_t i = 0; i < n_ways && OB_SUCC(ret); ++i) {
|
||||||
void* buf = alloc_.alloc(sizeof(ObChunkDatumStore::LastStoredRow<>));
|
void* buf = alloc_.alloc(sizeof(ObChunkDatumStore::LastStoredRow));
|
||||||
if (OB_ISNULL(buf)) {
|
if (OB_ISNULL(buf)) {
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
LOG_WARN("failed to alloca memory", K(ret));
|
LOG_WARN("failed to alloca memory", K(ret));
|
||||||
} else {
|
} else {
|
||||||
ObChunkDatumStore::LastStoredRow<>* store_row = new (buf) ObChunkDatumStore::LastStoredRow<>(alloc_);
|
ObChunkDatumStore::LastStoredRow* store_row = new (buf) ObChunkDatumStore::LastStoredRow(alloc_);
|
||||||
if (OB_FAIL(store_rows_.push_back(store_row))) {
|
if (OB_FAIL(store_rows_.push_back(store_row))) {
|
||||||
LOG_WARN("failed to push back", K(ret));
|
LOG_WARN("failed to push back", K(ret));
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ int ObPxMSCoordOp::free_allocator()
|
|||||||
last_pop_row_ = nullptr;
|
last_pop_row_ = nullptr;
|
||||||
// the heap shoud be empty before store_rows_.reset();
|
// the heap shoud be empty before store_rows_.reset();
|
||||||
while (OB_SUCC(ret) && row_heap_.count() > 0) {
|
while (OB_SUCC(ret) && row_heap_.count() > 0) {
|
||||||
const ObChunkDatumStore::LastStoredRow<>* pop_row = nullptr;
|
const ObChunkDatumStore::LastStoredRow* pop_row = nullptr;
|
||||||
if (OB_SUCC(row_heap_.raw_pop(pop_row))) {
|
if (OB_SUCC(row_heap_.raw_pop(pop_row))) {
|
||||||
row_heap_.shrink();
|
row_heap_.shrink();
|
||||||
} else {
|
} else {
|
||||||
@ -324,7 +324,7 @@ int ObPxMSCoordOp::next_row(bool& wait_next_msg)
|
|||||||
LOG_WARN("fail push row to heap", K(ret));
|
LOG_WARN("fail push row to heap", K(ret));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ObChunkDatumStore::LastStoredRow<>* cur_row = nullptr;
|
ObChunkDatumStore::LastStoredRow* cur_row = nullptr;
|
||||||
if (OB_FAIL(store_rows_.at(row_heap_.writable_channel_idx(), cur_row))) {
|
if (OB_FAIL(store_rows_.at(row_heap_.writable_channel_idx(), cur_row))) {
|
||||||
LOG_WARN("failed to get store row", K(ret), K(row_heap_.writable_channel_idx()));
|
LOG_WARN("failed to get store row", K(ret), K(row_heap_.writable_channel_idx()));
|
||||||
} else if (OB_FAIL(cur_row->save_store_row(MY_SPEC.all_exprs_, eval_ctx_, 0))) {
|
} else if (OB_FAIL(cur_row->save_store_row(MY_SPEC.all_exprs_, eval_ctx_, 0))) {
|
||||||
@ -346,14 +346,14 @@ int ObPxMSCoordOp::next_row(bool& wait_next_msg)
|
|||||||
all_rows_finish_ = true;
|
all_rows_finish_ = true;
|
||||||
metric_.mark_last_out();
|
metric_.mark_last_out();
|
||||||
} else if (row_heap_.capacity() == row_heap_.count()) {
|
} else if (row_heap_.capacity() == row_heap_.count()) {
|
||||||
const ObChunkDatumStore::LastStoredRow<>* pop_row = nullptr;
|
const ObChunkDatumStore::LastStoredRow* pop_row = nullptr;
|
||||||
if (OB_FAIL(row_heap_.pop(pop_row))) {
|
if (OB_FAIL(row_heap_.pop(pop_row))) {
|
||||||
LOG_WARN("failed to pop row", K(ret));
|
LOG_WARN("failed to pop row", K(ret));
|
||||||
} else if (OB_FAIL(pop_row->store_row_->to_expr(MY_SPEC.all_exprs_, eval_ctx_))) {
|
} else if (OB_FAIL(pop_row->store_row_->to_expr(MY_SPEC.all_exprs_, eval_ctx_))) {
|
||||||
LOG_WARN("failed to to exprs", K(ret));
|
LOG_WARN("failed to to exprs", K(ret));
|
||||||
} else {
|
} else {
|
||||||
wait_next_msg = false;
|
wait_next_msg = false;
|
||||||
last_pop_row_ = const_cast<ObChunkDatumStore::LastStoredRow<>*>(pop_row);
|
last_pop_row_ = const_cast<ObChunkDatumStore::LastStoredRow*>(pop_row);
|
||||||
}
|
}
|
||||||
metric_.count();
|
metric_.count();
|
||||||
metric_.mark_first_out();
|
metric_.mark_first_out();
|
||||||
|
|||||||
@ -72,7 +72,7 @@ public:
|
|||||||
};
|
};
|
||||||
class ObMsgReceiveFilter : public dtl::ObIDltChannelLoopPred {
|
class ObMsgReceiveFilter : public dtl::ObIDltChannelLoopPred {
|
||||||
public:
|
public:
|
||||||
ObMsgReceiveFilter(ObRowHeap<ObMaxDatumRowCompare, ObChunkDatumStore::LastStoredRow<>>& heap)
|
ObMsgReceiveFilter(ObRowHeap<ObMaxDatumRowCompare, ObChunkDatumStore::LastStoredRow>& heap)
|
||||||
: data_ch_idx_start_(-1), data_ch_idx_end_(-1), heap_(heap)
|
: data_ch_idx_start_(-1), data_ch_idx_end_(-1), heap_(heap)
|
||||||
{}
|
{}
|
||||||
~ObMsgReceiveFilter() = default;
|
~ObMsgReceiveFilter() = default;
|
||||||
@ -96,7 +96,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
int64_t data_ch_idx_start_;
|
int64_t data_ch_idx_start_;
|
||||||
int64_t data_ch_idx_end_;
|
int64_t data_ch_idx_end_;
|
||||||
ObRowHeap<ObMaxDatumRowCompare, ObChunkDatumStore::LastStoredRow<>>& heap_;
|
ObRowHeap<ObMaxDatumRowCompare, ObChunkDatumStore::LastStoredRow>& heap_;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -127,9 +127,9 @@ private:
|
|||||||
ObBarrierPieceMsgP barrier_piece_msg_proc_;
|
ObBarrierPieceMsgP barrier_piece_msg_proc_;
|
||||||
ObWinbufPieceMsgP winbuf_piece_msg_proc_;
|
ObWinbufPieceMsgP winbuf_piece_msg_proc_;
|
||||||
ObPxQcInterruptedP interrupt_proc_;
|
ObPxQcInterruptedP interrupt_proc_;
|
||||||
ObArray<ObChunkDatumStore::LastStoredRow<>*> store_rows_;
|
ObArray<ObChunkDatumStore::LastStoredRow*> store_rows_;
|
||||||
ObChunkDatumStore::LastStoredRow<>* last_pop_row_;
|
ObChunkDatumStore::LastStoredRow* last_pop_row_;
|
||||||
ObRowHeap<ObMaxDatumRowCompare, ObChunkDatumStore::LastStoredRow<>> row_heap_;
|
ObRowHeap<ObMaxDatumRowCompare, ObChunkDatumStore::LastStoredRow> row_heap_;
|
||||||
ObMsgReceiveFilter receive_order_;
|
ObMsgReceiveFilter receive_order_;
|
||||||
common::ObArenaAllocator alloc_;
|
common::ObArenaAllocator alloc_;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -135,7 +135,7 @@ protected:
|
|||||||
common::ObArenaAllocator px_row_allocator_;
|
common::ObArenaAllocator px_row_allocator_;
|
||||||
ObPxTaskChSet task_ch_set_;
|
ObPxTaskChSet task_ch_set_;
|
||||||
bool transmited_;
|
bool transmited_;
|
||||||
// const ObChunkDatum::LastStoredRow<> first_row_;
|
// const ObChunkDatum::LastStoredRow first_row_;
|
||||||
bool iter_end_;
|
bool iter_end_;
|
||||||
bool consume_first_row_;
|
bool consume_first_row_;
|
||||||
dtl::ObDtlUnblockingMsgP dfc_unblock_msg_proc_;
|
dtl::ObDtlUnblockingMsgP dfc_unblock_msg_proc_;
|
||||||
|
|||||||
@ -129,7 +129,7 @@ ObMaxDatumRowCompare::ObMaxDatumRowCompare()
|
|||||||
|
|
||||||
int ObMaxDatumRowCompare::init(const ObIArray<ObSortFieldCollation>* sort_collations,
|
int ObMaxDatumRowCompare::init(const ObIArray<ObSortFieldCollation>* sort_collations,
|
||||||
const ObIArray<ObSortCmpFunc>* sort_cmp_funs,
|
const ObIArray<ObSortCmpFunc>* sort_cmp_funs,
|
||||||
const common::ObIArray<const ObChunkDatumStore::LastStoredRow<>*>& rows)
|
const common::ObIArray<const ObChunkDatumStore::LastStoredRow*>& rows)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
bool is_static_cmp = false;
|
bool is_static_cmp = false;
|
||||||
|
|||||||
@ -84,7 +84,7 @@ class ObMaxDatumRowCompare {
|
|||||||
public:
|
public:
|
||||||
ObMaxDatumRowCompare();
|
ObMaxDatumRowCompare();
|
||||||
int init(const ObIArray<ObSortFieldCollation>* sort_collations, const ObIArray<ObSortCmpFunc>* sort_cmp_funs,
|
int init(const ObIArray<ObSortFieldCollation>* sort_collations, const ObIArray<ObSortCmpFunc>* sort_cmp_funs,
|
||||||
const common::ObIArray<const ObChunkDatumStore::LastStoredRow<>*>& rows);
|
const common::ObIArray<const ObChunkDatumStore::LastStoredRow*>& rows);
|
||||||
|
|
||||||
// compare function for quick sort.
|
// compare function for quick sort.
|
||||||
bool operator()(int64_t row_idx1, int64_t row_idx2);
|
bool operator()(int64_t row_idx1, int64_t row_idx2);
|
||||||
@ -113,7 +113,7 @@ public:
|
|||||||
int ret_;
|
int ret_;
|
||||||
const ObIArray<ObSortFieldCollation>* sort_collations_;
|
const ObIArray<ObSortFieldCollation>* sort_collations_;
|
||||||
const ObIArray<ObSortCmpFunc>* sort_cmp_funs_;
|
const ObIArray<ObSortCmpFunc>* sort_cmp_funs_;
|
||||||
const common::ObIArray<const ObChunkDatumStore::LastStoredRow<>*>* rows_;
|
const common::ObIArray<const ObChunkDatumStore::LastStoredRow*>* rows_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -70,7 +70,7 @@ bool ObSearchMethodOp::ObCycleHash::operator==(const ObCycleHash& other) const
|
|||||||
int ObSearchMethodOp::add_row(const ObIArray<ObExpr*>& exprs, ObEvalCtx& eval_ctx)
|
int ObSearchMethodOp::add_row(const ObIArray<ObExpr*>& exprs, ObEvalCtx& eval_ctx)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
ObChunkDatumStore::LastStoredRow<> last_row(allocator_);
|
ObChunkDatumStore::LastStoredRow last_row(allocator_);
|
||||||
if (input_rows_.empty() && 0 == input_rows_.get_capacity() && OB_FAIL(input_rows_.reserve(INIT_ROW_COUNT))) {
|
if (input_rows_.empty() && 0 == input_rows_.get_capacity() && OB_FAIL(input_rows_.reserve(INIT_ROW_COUNT))) {
|
||||||
LOG_WARN("Failed to pre allocate array", K(ret));
|
LOG_WARN("Failed to pre allocate array", K(ret));
|
||||||
} else if (OB_UNLIKELY(exprs.empty())) {
|
} else if (OB_UNLIKELY(exprs.empty())) {
|
||||||
|
|||||||
@ -70,7 +70,7 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
common::ObArenaAllocator alloc_;
|
common::ObArenaAllocator alloc_;
|
||||||
ObChunkDatumStore::LastStoredRow<> last_row_;
|
ObChunkDatumStore::LastStoredRow last_row_;
|
||||||
Compare cmp_;
|
Compare cmp_;
|
||||||
bool need_skip_init_row_;
|
bool need_skip_init_row_;
|
||||||
bool iter_end_;
|
bool iter_end_;
|
||||||
|
|||||||
@ -1425,21 +1425,19 @@ int ObInMemoryTopnSortImpl::add_row(const common::ObIArray<ObExpr*>& exprs, bool
|
|||||||
// optimize for hit-rate: enlarge first Limit-Count row's space,
|
// optimize for hit-rate: enlarge first Limit-Count row's space,
|
||||||
// so following rows are more likely to fit in.
|
// so following rows are more likely to fit in.
|
||||||
int64_t row_size = 0;
|
int64_t row_size = 0;
|
||||||
if (OB_FAIL(ObChunkDatumStore::row_copy_size(exprs, *eval_ctx_, row_size))) {
|
if (OB_FAIL(ObChunkDatumStore::Block::row_store_size(exprs, *eval_ctx_, row_size, STORE_ROW_EXTRA_SIZE))) {
|
||||||
LOG_WARN("failed to calc copy size", K(ret));
|
LOG_WARN("failed to calc copy size", K(ret));
|
||||||
} else {
|
} else {
|
||||||
int64_t buffer_len = STORE_ROW_HEADER_SIZE + 2 * row_size + STORE_ROW_EXTRA_SIZE;
|
int64_t buffer_len = 2 * row_size;
|
||||||
if (OB_ISNULL(buf = reinterpret_cast<char*>(cur_alloc_.alloc(buffer_len)))) {
|
if (OB_ISNULL(buf = reinterpret_cast<char *>(cur_alloc_.alloc(buffer_len)))) {
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
LOG_ERROR("alloc buf failed", K(ret));
|
LOG_ERROR("alloc buf failed", K(ret));
|
||||||
} else if (OB_ISNULL(new_row = new (buf) SortStoredRow())) {
|
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
|
||||||
LOG_ERROR("failed to new row", K(ret));
|
|
||||||
} else {
|
} else {
|
||||||
int64_t pos = STORE_ROW_HEADER_SIZE;
|
ObChunkDatumStore::StoredRow *sr = NULL;
|
||||||
if (OB_FAIL(new_row->copy_datums(
|
if (OB_FAIL(
|
||||||
exprs, *eval_ctx_, buf + pos, buffer_len - STORE_ROW_HEADER_SIZE, row_size, STORE_ROW_EXTRA_SIZE))) {
|
ObChunkDatumStore::StoredRow::build(sr, exprs, *eval_ctx_, buf, buffer_len, STORE_ROW_EXTRA_SIZE))) {
|
||||||
LOG_WARN("failed to deep copy row", K(ret), K(buffer_len));
|
LOG_WARN("build stored row failed", K(ret));
|
||||||
|
} else if (FALSE_IT(new_row = static_cast<SortStoredRow *>(sr))) {
|
||||||
} else if (OB_FAIL(heap_.push(new_row))) {
|
} else if (OB_FAIL(heap_.push(new_row))) {
|
||||||
LOG_WARN("failed to push back row", K(ret), K(buffer_len));
|
LOG_WARN("failed to push back row", K(ret), K(buffer_len));
|
||||||
} else {
|
} else {
|
||||||
@ -1469,37 +1467,33 @@ int ObInMemoryTopnSortImpl::adjust_topn_heap(const common::ObIArray<ObExpr*>& ex
|
|||||||
char* buf = NULL;
|
char* buf = NULL;
|
||||||
int64_t row_size = 0;
|
int64_t row_size = 0;
|
||||||
int64_t buffer_len = 0;
|
int64_t buffer_len = 0;
|
||||||
if (OB_FAIL(ObChunkDatumStore::row_copy_size(exprs, *eval_ctx_, row_size))) {
|
if (OB_FAIL(ObChunkDatumStore::Block::row_store_size(exprs, *eval_ctx_, row_size, STORE_ROW_EXTRA_SIZE))) {
|
||||||
LOG_WARN("failed to calc copy size", K(ret));
|
LOG_WARN("failed to calc copy size", K(ret));
|
||||||
} else {
|
} else {
|
||||||
// check to see whether this old row's space is adequate for new one
|
// check to see whether this old row's space is adequate for new one
|
||||||
if (dt_row->get_max_size() >= row_size + STORE_ROW_HEADER_SIZE + STORE_ROW_EXTRA_SIZE) {
|
if (dt_row->get_max_size() >= row_size) {
|
||||||
buf = reinterpret_cast<char*>(dt_row);
|
buf = reinterpret_cast<char*>(dt_row);
|
||||||
new_row = dt_row;
|
new_row = dt_row;
|
||||||
buffer_len = dt_row->get_max_size();
|
buffer_len = dt_row->get_max_size();
|
||||||
} else {
|
} else {
|
||||||
buffer_len = row_size * 2 + STORE_ROW_HEADER_SIZE + STORE_ROW_EXTRA_SIZE;
|
buffer_len = row_size * 2;
|
||||||
if (OB_ISNULL(buf = reinterpret_cast<char*>(cur_alloc_.alloc(buffer_len)))) {
|
if (OB_ISNULL(buf = reinterpret_cast<char*>(cur_alloc_.alloc(buffer_len)))) {
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
LOG_ERROR("alloc buf failed", K(ret));
|
LOG_ERROR("alloc buf failed", K(ret));
|
||||||
} else if (OB_ISNULL(new_row = new (buf) SortStoredRow())) {
|
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
|
||||||
LOG_ERROR("failed to new row", K(ret));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (OB_SUCC(ret)) {
|
if (OB_SUCC(ret)) {
|
||||||
int64_t pos = STORE_ROW_HEADER_SIZE;
|
ObChunkDatumStore::StoredRow *sr = NULL;
|
||||||
if (OB_FAIL(new_row->copy_datums(
|
if (OB_FAIL(
|
||||||
exprs, *eval_ctx_, buf + pos, buffer_len - STORE_ROW_HEADER_SIZE, row_size, STORE_ROW_EXTRA_SIZE))) {
|
ObChunkDatumStore::StoredRow::build(sr, exprs, *eval_ctx_, buf, buffer_len, STORE_ROW_EXTRA_SIZE))) {
|
||||||
LOG_WARN("failed to deep copy row", K(ret), K(buffer_len), K(row_size));
|
LOG_WARN("build stored row failed", K(ret));
|
||||||
|
} else if (FALSE_IT(new_row = static_cast<SortStoredRow *>(sr))) {
|
||||||
} else if (OB_FAIL(heap_.replace_top(new_row))) {
|
} else if (OB_FAIL(heap_.replace_top(new_row))) {
|
||||||
LOG_WARN("failed to replace top", K(ret));
|
LOG_WARN("failed to replace top", K(ret));
|
||||||
} else {
|
} else {
|
||||||
new_row->set_max_size(buffer_len);
|
new_row->set_max_size(buffer_len);
|
||||||
last_row_ = new_row;
|
last_row_ = new_row;
|
||||||
// LOG_TRACE("in memory topn sort check replace row", KPC(new_row),
|
|
||||||
// K(buffer_len), K(row_size), K(new_row->get_max_size()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -340,7 +340,7 @@ private:
|
|||||||
|
|
||||||
const ObChunkDatumStore::StoredRow* prev_row_;
|
const ObChunkDatumStore::StoredRow* prev_row_;
|
||||||
// when got new prefix, save the row to to %next_prefix_row_
|
// when got new prefix, save the row to to %next_prefix_row_
|
||||||
ObChunkDatumStore::ShadowStoredRow<> next_prefix_row_store_;
|
ObChunkDatumStore::ShadowStoredRow next_prefix_row_store_;
|
||||||
ObChunkDatumStore::StoredRow* next_prefix_row_;
|
ObChunkDatumStore::StoredRow* next_prefix_row_;
|
||||||
|
|
||||||
ObOperator* child_;
|
ObOperator* child_;
|
||||||
|
|||||||
@ -470,7 +470,7 @@ int ObSubPlanFilterOp::handle_update_set()
|
|||||||
ret = OB_ERR_UNEXPECTED;
|
ret = OB_ERR_UNEXPECTED;
|
||||||
LOG_WARN("too many subplan unexpected", K(ret), K(subplan_iters_.count()));
|
LOG_WARN("too many subplan unexpected", K(ret), K(subplan_iters_.count()));
|
||||||
} else {
|
} else {
|
||||||
ObChunkDatumStore::LastStoredRow<> row_val(update_set_mem_->get_arena_allocator());
|
ObChunkDatumStore::LastStoredRow row_val(update_set_mem_->get_arena_allocator());
|
||||||
Iterator* iter = subplan_iters_.at(0);
|
Iterator* iter = subplan_iters_.at(0);
|
||||||
if (OB_ISNULL(iter)) {
|
if (OB_ISNULL(iter)) {
|
||||||
ret = OB_ERR_UNEXPECTED;
|
ret = OB_ERR_UNEXPECTED;
|
||||||
|
|||||||
@ -272,7 +272,7 @@ public:
|
|||||||
|
|
||||||
int64_t wf_idx_;
|
int64_t wf_idx_;
|
||||||
int64_t part_first_row_idx_;
|
int64_t part_first_row_idx_;
|
||||||
ObChunkDatumStore::LastStoredRow<> part_values_;
|
ObChunkDatumStore::LastStoredRow part_values_;
|
||||||
RowsStore part_rows_store_;
|
RowsStore part_rows_store_;
|
||||||
|
|
||||||
Frame last_valid_frame_;
|
Frame last_valid_frame_;
|
||||||
@ -494,7 +494,7 @@ private:
|
|||||||
RowsStore rows_store_;
|
RowsStore rows_store_;
|
||||||
WinFuncCellList wf_list_;
|
WinFuncCellList wf_list_;
|
||||||
// shadow copy the next and restore it before get next row from child.
|
// shadow copy the next and restore it before get next row from child.
|
||||||
ObChunkDatumStore::ShadowStoredRow<> next_row_;
|
ObChunkDatumStore::ShadowStoredRow next_row_;
|
||||||
bool next_row_valid_; // TODO
|
bool next_row_valid_; // TODO
|
||||||
DatumFixedArray curr_row_collect_values_;
|
DatumFixedArray curr_row_collect_values_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user