Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

branch-2.1: [Fix](partial update) Fix incorrect result when partial update include delete sign columns #46194 #46543

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions be/src/olap/rowset/segment_v2/segment_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,15 +657,21 @@ Status SegmentWriter::fill_missing_columns(vectorized::MutableColumns& mutable_f
bool has_default_or_nullable,
const size_t& segment_start_pos,
const vectorized::Block* block) {
if constexpr (!std::is_same_v<ExecEnv::Engine, StorageEngine>) {
// TODO(plat1ko): cloud mode
return Status::NotSupported("fill_missing_columns");
}
auto tablet = static_cast<Tablet*>(_tablet.get());
// create old value columns
const auto& cids_missing = _opts.rowset_ctx->partial_update_info->missing_cids;
auto cids_to_read = cids_missing;
auto old_value_block = _tablet_schema->create_block_by_cids(cids_missing);
CHECK_EQ(cids_missing.size(), old_value_block.columns());
// always read delete sign column from historical data
if (const vectorized::ColumnWithTypeAndName* old_delete_sign_column =
old_value_block.try_get_by_name(DELETE_SIGN);
old_delete_sign_column == nullptr) {
auto del_col_cid = _tablet_schema->field_index(DELETE_SIGN);
cids_to_read.emplace_back(del_col_cid);
old_value_block.swap(_tablet_schema->create_block_by_cids(cids_to_read));
}

bool has_row_column = _tablet_schema->store_row_column();
// record real pos, key is input line num, value is old_block line num
std::map<uint32_t, uint32_t> read_index;
Expand All @@ -681,7 +687,7 @@ Status SegmentWriter::fill_missing_columns(vectorized::MutableColumns& mutable_f
}
if (has_row_column) {
auto st = tablet->fetch_value_through_row_column(
rowset, *_tablet_schema, seg_it.first, rids, cids_missing, old_value_block);
rowset, *_tablet_schema, seg_it.first, rids, cids_to_read, old_value_block);
if (!st.ok()) {
LOG(WARNING) << "failed to fetch value through row column";
return st;
Expand All @@ -690,7 +696,7 @@ Status SegmentWriter::fill_missing_columns(vectorized::MutableColumns& mutable_f
}
auto mutable_old_columns = old_value_block.mutate_columns();
for (size_t cid = 0; cid < mutable_old_columns.size(); ++cid) {
TabletColumn tablet_column = _tablet_schema->column(cids_missing[cid]);
TabletColumn tablet_column = _tablet_schema->column(cids_to_read[cid]);
auto st = tablet->fetch_value_by_rowids(rowset, seg_it.first, rids, tablet_column,
mutable_old_columns[cid]);
// set read value to output block
Expand All @@ -715,17 +721,14 @@ Status SegmentWriter::fill_missing_columns(vectorized::MutableColumns& mutable_f
delete_sign_column_data = delete_sign_col.get_data().data();
}

if (has_default_or_nullable || delete_sign_column_data != nullptr) {
for (auto i = 0; i < cids_missing.size(); ++i) {
const auto& column = _tablet_schema->column(cids_missing[i]);
if (column.has_default_value()) {
const auto& default_value =
_opts.rowset_ctx->partial_update_info->default_values[i];
vectorized::ReadBuffer rb(const_cast<char*>(default_value.c_str()),
default_value.size());
RETURN_IF_ERROR(old_value_block.get_by_position(i).type->from_string(
rb, mutable_default_value_columns[i].get()));
}
for (auto i = 0; i < cids_missing.size(); ++i) {
const auto& column = _tablet_schema->column(cids_missing[i]);
if (column.has_default_value()) {
const auto& default_value = _opts.rowset_ctx->partial_update_info->default_values[i];
vectorized::ReadBuffer rb(const_cast<char*>(default_value.c_str()),
default_value.size());
RETURN_IF_ERROR(old_value_block.get_by_position(i).type->from_string(
rb, mutable_default_value_columns[i].get()));
}
}

Expand Down
41 changes: 19 additions & 22 deletions be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,6 @@ Status VerticalSegmentWriter::_partial_update_preconditions_check(size_t row_pos
// 3. set columns to data convertor and then write all columns
Status VerticalSegmentWriter::_append_block_with_partial_content(RowsInBlock& data,
vectorized::Block& full_block) {
if constexpr (!std::is_same_v<ExecEnv::Engine, StorageEngine>) {
// TODO(plat1ko): CloudStorageEngine
return Status::NotSupported("append_block_with_partial_content");
}

RETURN_IF_ERROR(_partial_update_preconditions_check(data.row_pos));

auto tablet = static_cast<Tablet*>(_tablet.get());
Expand Down Expand Up @@ -600,15 +595,20 @@ Status VerticalSegmentWriter::_fill_missing_columns(
vectorized::MutableColumns& mutable_full_columns,
const std::vector<bool>& use_default_or_null_flag, bool has_default_or_nullable,
const size_t& segment_start_pos, const vectorized::Block* block) {
if constexpr (!std::is_same_v<ExecEnv::Engine, StorageEngine>) {
// TODO(plat1ko): CloudStorageEngine
return Status::NotSupported("fill_missing_columns");
}
auto tablet = static_cast<Tablet*>(_tablet.get());
// create old value columns
const auto& missing_cids = _opts.rowset_ctx->partial_update_info->missing_cids;
auto cids_to_read = missing_cids;
auto old_value_block = _tablet_schema->create_block_by_cids(missing_cids);
CHECK_EQ(missing_cids.size(), old_value_block.columns());
// always read delete sign column from historical data
if (const vectorized::ColumnWithTypeAndName* old_delete_sign_column =
old_value_block.try_get_by_name(DELETE_SIGN);
old_delete_sign_column == nullptr) {
auto del_col_cid = _tablet_schema->field_index(DELETE_SIGN);
cids_to_read.emplace_back(del_col_cid);
old_value_block.swap(_tablet_schema->create_block_by_cids(cids_to_read));
}
auto mutable_old_columns = old_value_block.mutate_columns();
bool has_row_column = _tablet_schema->store_row_column();
// record real pos, key is input line num, value is old_block line num
Expand All @@ -625,15 +625,15 @@ Status VerticalSegmentWriter::_fill_missing_columns(
}
if (has_row_column) {
auto st = tablet->fetch_value_through_row_column(
rowset, *_tablet_schema, seg_it.first, rids, missing_cids, old_value_block);
rowset, *_tablet_schema, seg_it.first, rids, cids_to_read, old_value_block);
if (!st.ok()) {
LOG(WARNING) << "failed to fetch value through row column";
return st;
}
continue;
}
for (size_t cid = 0; cid < mutable_old_columns.size(); ++cid) {
TabletColumn tablet_column = _tablet_schema->column(missing_cids[cid]);
TabletColumn tablet_column = _tablet_schema->column(cids_to_read[cid]);
auto st = tablet->fetch_value_by_rowids(rowset, seg_it.first, rids, tablet_column,
mutable_old_columns[cid]);
// set read value to output block
Expand All @@ -657,17 +657,14 @@ Status VerticalSegmentWriter::_fill_missing_columns(
delete_sign_column_data = delete_sign_col.get_data().data();
}

if (has_default_or_nullable || delete_sign_column_data != nullptr) {
for (auto i = 0; i < missing_cids.size(); ++i) {
const auto& column = _tablet_schema->column(missing_cids[i]);
if (column.has_default_value()) {
const auto& default_value =
_opts.rowset_ctx->partial_update_info->default_values[i];
vectorized::ReadBuffer rb(const_cast<char*>(default_value.c_str()),
default_value.size());
RETURN_IF_ERROR(old_value_block.get_by_position(i).type->from_string(
rb, mutable_default_value_columns[i].get()));
}
for (auto i = 0; i < missing_cids.size(); ++i) {
const auto& column = _tablet_schema->column(missing_cids[i]);
if (column.has_default_value()) {
const auto& default_value = _opts.rowset_ctx->partial_update_info->default_values[i];
vectorized::ReadBuffer rb(const_cast<char*>(default_value.c_str()),
default_value.size());
RETURN_IF_ERROR(old_value_block.get_by_position(i).type->from_string(
rb, mutable_default_value_columns[i].get()));
}
}

Expand Down
17 changes: 14 additions & 3 deletions be/src/olap/tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3290,7 +3290,7 @@ Status Tablet::generate_new_block_for_partial_update(
// read current rowset first, if a row in the current rowset has delete sign mark
// we don't need to read values from old block
RETURN_IF_ERROR(read_columns_by_plan(rowset_schema, update_cids, read_plan_update,
rsid_to_rowset, update_block, &read_index_update));
rsid_to_rowset, update_block, &read_index_update, false));

size_t update_rows = read_index_update.size();
for (auto i = 0; i < update_cids.size(); ++i) {
Expand All @@ -3311,7 +3311,7 @@ Status Tablet::generate_new_block_for_partial_update(
// rowid in the final block(start from 0, increase, may not continuous becasue we skip to read some rows) -> rowid to read in old_block
std::map<uint32_t, uint32_t> read_index_old;
RETURN_IF_ERROR(read_columns_by_plan(rowset_schema, missing_cids, read_plan_ori, rsid_to_rowset,
old_block, &read_index_old, new_block_delete_signs));
old_block, &read_index_old, true, new_block_delete_signs));
size_t old_rows = read_index_old.size();
const auto* __restrict old_block_delete_signs =
get_delete_sign_column_data(old_block, old_rows);
Expand Down Expand Up @@ -3375,12 +3375,23 @@ Status Tablet::generate_new_block_for_partial_update(
// read columns by read plan
// read_index: ori_pos-> block_idx
Status Tablet::read_columns_by_plan(TabletSchemaSPtr tablet_schema,
const std::vector<uint32_t> cids_to_read,
std::vector<uint32_t> cids_to_read,
const PartialUpdateReadPlan& read_plan,
const std::map<RowsetId, RowsetSharedPtr>& rsid_to_rowset,
vectorized::Block& block,
std::map<uint32_t, uint32_t>* read_index,
bool force_read_old_delete_signs,
const signed char* __restrict skip_map) {
if (force_read_old_delete_signs) {
// always read delete sign column from historical data
if (const vectorized::ColumnWithTypeAndName* old_delete_sign_column =
block.try_get_by_name(DELETE_SIGN);
old_delete_sign_column == nullptr) {
auto del_col_cid = tablet_schema->field_index(DELETE_SIGN);
cids_to_read.emplace_back(del_col_cid);
block.swap(tablet_schema->create_block_by_cids(cids_to_read));
}
}
bool has_row_column = tablet_schema->store_row_column();
auto mutable_columns = block.mutate_columns();
size_t read_idx = 0;
Expand Down
4 changes: 2 additions & 2 deletions be/src/olap/tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,11 @@ class Tablet final : public BaseTablet {
Status calc_delete_bitmap_between_segments(
RowsetSharedPtr rowset, const std::vector<segment_v2::SegmentSharedPtr>& segments,
DeleteBitmapPtr delete_bitmap);
Status read_columns_by_plan(TabletSchemaSPtr tablet_schema,
const std::vector<uint32_t> cids_to_read,
Status read_columns_by_plan(TabletSchemaSPtr tablet_schema, std::vector<uint32_t> cids_to_read,
const PartialUpdateReadPlan& read_plan,
const std::map<RowsetId, RowsetSharedPtr>& rsid_to_rowset,
vectorized::Block& block, std::map<uint32_t, uint32_t>* read_index,
bool force_read_old_delete_signs,
const signed char* __restrict skip_map = nullptr);
void prepare_to_read(const RowLocation& row_location, size_t pos,
PartialUpdateReadPlan* read_plan);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5

-- !sql --
1 1 1 987 987
2 \N \N 987 987
3 3 3 3 3
4 -1 -1 987 987
5 \N \N 987 987

Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
7 7 7 7
8 8 8 8
10 \N 999 \N
11 \N 888 \N
11 \N \N \N

-- !sql_2_1 --
0 0 0 0
3 3 30 3
7 7 7 7
8 8 8 8
10 \N 999 \N
11 \N 888 \N
11 \N \N \N

-- !sql_2_2 --
0 0 0 0
Expand Down Expand Up @@ -90,7 +90,7 @@
7 7 7 7
8 8 8 8
10 \N 999 \N
11 \N 888 \N
11 \N \N \N

-- !inspect --
0 0 0 0 1 0
Expand All @@ -109,15 +109,15 @@
8 8 8 8 1 0
10 \N 999 \N 2 0
11 \N 888 \N 2 1
11 \N 888 \N 3 0
11 \N \N \N 3 0

-- !sql_4_1 --
0 0 0 0
3 3 30 3
7 7 7 7
8 8 8 8
10 \N 999 \N
11 \N 888 \N
11 \N \N \N

-- !inspect --
0 0 0 0 1 0
Expand All @@ -138,7 +138,7 @@
8 8 8 8 1 0
10 \N 999 \N 2 0
11 \N 888 \N 2 1
11 \N 888 \N 3 0
11 \N \N \N 3 0

-- !sql_4_2 --
0 0 0 0
Expand Down Expand Up @@ -166,8 +166,8 @@
8 8 8 8 1 0
10 \N 999 \N 2 0
11 \N 888 \N 2 1
11 \N 888 \N 3 0
11 \N 888 \N 5 1
11 \N \N \N 3 0
11 \N \N \N 5 1

-- !sql --
0 0 0 0
Expand Down Expand Up @@ -198,15 +198,15 @@
7 7 7 7
8 8 8 8
10 \N 999 \N
11 \N 888 \N
11 \N \N \N

-- !sql_2_1 --
0 0 0 0
3 3 30 3
7 7 7 7
8 8 8 8
10 \N 999 \N
11 \N 888 \N
11 \N \N \N

-- !sql_2_2 --
0 0 0 0
Expand Down Expand Up @@ -260,7 +260,7 @@
7 7 7 7
8 8 8 8
10 \N 999 \N
11 \N 888 \N
11 \N \N \N

-- !inspect --
0 0 0 0 1 0
Expand All @@ -279,15 +279,15 @@
8 8 8 8 1 0
10 \N 999 \N 2 0
11 \N 888 \N 2 1
11 \N 888 \N 3 0
11 \N \N \N 3 0

-- !sql_4_1 --
0 0 0 0
3 3 30 3
7 7 7 7
8 8 8 8
10 \N 999 \N
11 \N 888 \N
11 \N \N \N

-- !inspect --
0 0 0 0 1 0
Expand All @@ -308,7 +308,7 @@
8 8 8 8 1 0
10 \N 999 \N 2 0
11 \N 888 \N 2 1
11 \N 888 \N 3 0
11 \N \N \N 3 0

-- !sql_4_2 --
0 0 0 0
Expand Down Expand Up @@ -336,6 +336,6 @@
8 8 8 8 1 0
10 \N 999 \N 2 0
11 \N 888 \N 2 1
11 \N 888 \N 3 0
11 \N 888 \N 5 1
11 \N \N \N 3 0
11 \N \N \N 5 1

Binary file not shown.
Binary file not shown.
Loading
Loading