[FEAT MERGE] impl vectorization 2.0
Co-authored-by: Naynahs <cfzy002@126.com> Co-authored-by: hwx65 <1780011298@qq.com> Co-authored-by: oceanoverflow <oceanoverflow@gmail.com>
This commit is contained in:
@ -158,13 +158,14 @@ void ObChunkDatumStore::StoredRow::swizzling(char *base/*= NULL*/)
|
||||
}
|
||||
}
|
||||
|
||||
template <bool UNSWIZZLING>
|
||||
template <bool UNSWIZZLING, bool IS_VECTOR_ROW>
|
||||
int ObChunkDatumStore::StoredRow::do_build(StoredRow *&sr,
|
||||
const ObExprPtrIArray &exprs,
|
||||
ObEvalCtx &ctx,
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
const uint32_t extra_size)
|
||||
const uint32_t extra_size,
|
||||
int64_t vector_row_idx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
sr = reinterpret_cast<StoredRow *>(buf);
|
||||
@ -176,16 +177,33 @@ int ObChunkDatumStore::StoredRow::do_build(StoredRow *&sr,
|
||||
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 if (IS_VECTOR_ROW) {
|
||||
// TODO: shanting2.0 remove later.
|
||||
if (OB_UNLIKELY(VEC_INVALID == expr->get_format(ctx))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("expr not evaluated before", K(ret), KPC(expr));
|
||||
} else {
|
||||
ObIVector *vec = expr->get_vector(ctx);
|
||||
const char *payload = NULL;
|
||||
ObLength len = 0;
|
||||
vec->get_payload(vector_row_idx, payload, len);
|
||||
ObDatum in_datum(payload, len, vec->is_null(vector_row_idx));
|
||||
ret = UNSWIZZLING
|
||||
? deep_copy_unswizzling(in_datum, &datums[i], buf, buf_len, pos)
|
||||
: datums[i].deep_copy(in_datum, buf, buf_len, pos);
|
||||
}
|
||||
} else {
|
||||
ret = UNSWIZZLING
|
||||
? deep_copy_unswizzling(*in_datum, &datums[i], buf, buf_len, pos)
|
||||
: datums[i].deep_copy(*in_datum, buf, buf_len, pos);
|
||||
ObDatum *in_datum = NULL;
|
||||
if (OB_FAIL(expr->eval(ctx, in_datum))) {
|
||||
LOG_WARN("expression evaluate failed", K(ret));
|
||||
} else {
|
||||
ret = UNSWIZZLING
|
||||
? deep_copy_unswizzling(*in_datum, &datums[i], buf, buf_len, pos)
|
||||
: datums[i].deep_copy(*in_datum, buf, buf_len, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
@ -202,11 +220,17 @@ int ObChunkDatumStore::StoredRow::build(StoredRow *&sr,
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
const uint32_t extra_size, /* = 0 */
|
||||
const bool unswizzling /* = false */)
|
||||
const bool unswizzling /* = false */,
|
||||
int64_t vector_row_idx /* OB_INVALID_ID */)
|
||||
{
|
||||
bool is_vector_row = OB_INVALID_ID != vector_row_idx;
|
||||
return unswizzling
|
||||
? do_build<true>(sr, exprs, ctx, buf, buf_len, extra_size)
|
||||
: do_build<false>(sr, exprs, ctx, buf, buf_len, extra_size);
|
||||
? (is_vector_row
|
||||
? do_build<true, true>(sr, exprs, ctx, buf, buf_len, extra_size, vector_row_idx)
|
||||
: do_build<true, false>(sr, exprs, ctx, buf, buf_len, extra_size, vector_row_idx))
|
||||
: (is_vector_row
|
||||
? do_build<false, true>(sr, exprs, ctx, buf, buf_len, extra_size, vector_row_idx)
|
||||
: do_build<false, false>(sr, exprs, ctx, buf, buf_len, extra_size, vector_row_idx));
|
||||
}
|
||||
|
||||
int ObChunkDatumStore::StoredRow::build(StoredRow *&sr,
|
||||
@ -257,7 +281,8 @@ int ObChunkDatumStore::Block::add_row(const common::ObIArray<ObExpr*> &exprs, Ob
|
||||
}
|
||||
|
||||
int ObChunkDatumStore::BlockBufferWrap::append_row(
|
||||
const common::ObIArray<ObExpr*> &exprs, ObEvalCtx *ctx, int64_t row_extend_size)
|
||||
const common::ObIArray<ObExpr*> &exprs, ObEvalCtx *ctx, int64_t row_extend_size,
|
||||
int64_t vector_row_idx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
OB_ASSERT(is_inited());
|
||||
@ -269,16 +294,26 @@ int ObChunkDatumStore::BlockBufferWrap::append_row(
|
||||
StoredRow *sr = (StoredRow*)head();
|
||||
sr->cnt_ = static_cast<uint32_t>(exprs.count());
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < sr->cnt_; ++i) {
|
||||
ObDatum &in_datum = static_cast<ObDatum&>(exprs.at(i)->locate_expr_datum(*ctx));
|
||||
ObDatum *datum = new (&sr->cells()[i])ObDatum();
|
||||
// Attension : can't print dst datum after deep_copy_unswizzling
|
||||
if (OB_FAIL(deep_copy_unswizzling(in_datum, datum, head(), max_size, pos))) {
|
||||
if (OB_INVALID_ID == vector_row_idx) {
|
||||
ret = deep_copy_unswizzling(static_cast<ObDatum&>(exprs.at(i)->locate_expr_datum(*ctx)),
|
||||
datum, head(), max_size, pos);
|
||||
} else {
|
||||
const ObIVector *vec = exprs.at(i)->get_vector(*ctx);
|
||||
const char *payload = NULL;
|
||||
ObLength len = 0;
|
||||
vec->get_payload(vector_row_idx, payload, len);
|
||||
ObDatum in_datum(payload, len, vec->is_null(vector_row_idx));
|
||||
ret = deep_copy_unswizzling(in_datum, datum, head(), max_size, pos);
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
if (OB_BUF_NOT_ENOUGH != ret) {
|
||||
LOG_WARN("failed to copy datum", K(ret), K(i), K(pos),
|
||||
K(max_size), K(in_datum));
|
||||
K(max_size));
|
||||
}
|
||||
} else {
|
||||
LOG_DEBUG("succ to copy_datums", K(sr->cnt_), K(i), K(max_size), K(pos), K(in_datum));
|
||||
LOG_DEBUG("succ to copy_datums", K(sr->cnt_), K(i), K(max_size), K(pos));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
@ -293,7 +328,8 @@ int ObChunkDatumStore::BlockBufferWrap::append_row(
|
||||
|
||||
int ObChunkDatumStore::Block::append_row(
|
||||
const common::ObIArray<ObExpr*> &exprs, ObEvalCtx *ctx,
|
||||
BlockBuffer *buf, int64_t row_extend_size, StoredRow **stored_row, const bool unswizzling)
|
||||
BlockBuffer *buf, int64_t row_extend_size, StoredRow **stored_row, const bool unswizzling,
|
||||
int64_t vector_row_idx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!buf->is_inited()) {
|
||||
@ -302,7 +338,7 @@ int ObChunkDatumStore::Block::append_row(
|
||||
} else {
|
||||
StoredRow *sr = NULL;
|
||||
if (OB_FAIL(StoredRow::build(sr, exprs, *ctx, buf->head(), buf->remain(),
|
||||
row_extend_size, unswizzling))) {
|
||||
row_extend_size, unswizzling, vector_row_idx))) {
|
||||
if (OB_BUF_NOT_ENOUGH != ret) {
|
||||
LOG_WARN("build stored row failed", K(ret));
|
||||
}
|
||||
@ -2235,7 +2271,7 @@ int ObChunkDatumStore::assign(const ObChunkDatumStore &other_store)
|
||||
OB_DEF_SERIALIZE(ObChunkDatumStore)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (enable_dump_) {
|
||||
if (inited_ && enable_dump_) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("chunk datum store not support serialize if enable dump", K(ret));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user