Skip to content

Commit

Permalink
read seq value from pk index
Browse files Browse the repository at this point in the history
  • Loading branch information
bobhan1 committed Oct 5, 2024
1 parent e71e5a5 commit 2627c19
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 288 deletions.
5 changes: 3 additions & 2 deletions be/src/olap/base_tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ Status BaseTablet::lookup_row_key(const Slice& encoded_key, TabletSchema* latest
const std::vector<RowsetSharedPtr>& specified_rowsets,
RowLocation* row_location, uint32_t version,
std::vector<std::unique_ptr<SegmentCacheHandle>>& segment_caches,
RowsetSharedPtr* rowset, bool with_rowid) {
RowsetSharedPtr* rowset, bool with_rowid,
std::string* encoded_seq_value) {
SCOPED_BVAR_LATENCY(g_tablet_lookup_rowkey_latency);
size_t seq_col_length = 0;
// use the latest tablet schema to decide if the tablet has sequence column currently
Expand Down Expand Up @@ -489,7 +490,7 @@ Status BaseTablet::lookup_row_key(const Slice& encoded_key, TabletSchema* latest

for (auto id : picked_segments) {
Status s = segments[id]->lookup_row_key(encoded_key, schema, with_seq_col, with_rowid,
&loc);
&loc, encoded_seq_value);
if (s.is<KEY_NOT_FOUND>()) {
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion be/src/olap/base_tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class BaseTablet {
const std::vector<RowsetSharedPtr>& specified_rowsets,
RowLocation* row_location, uint32_t version,
std::vector<std::unique_ptr<SegmentCacheHandle>>& segment_caches,
RowsetSharedPtr* rowset = nullptr, bool with_rowid = true);
RowsetSharedPtr* rowset = nullptr, bool with_rowid = true,
std::string* encoded_seq_value = nullptr);

// calc delete bitmap when flush memtable, use a fake version to calc
// For example, cur max version is 5, and we use version 6 to calc but
Expand Down
11 changes: 3 additions & 8 deletions be/src/olap/partial_update_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ Status FixedReadPlan::fill_missing_columns(

void FlexibleReadPlan::prepare_to_read(const RowLocation& row_location, size_t pos,
const BitmapValue& skip_bitmap) {
if (!has_row_store) {
if (!use_row_store) {
for (uint64_t col_uid : skip_bitmap) {
plan[row_location.rowset_id][row_location.segment_id][col_uid].emplace_back(
row_location.row_id, pos);
Expand All @@ -408,10 +408,6 @@ void FlexibleReadPlan::prepare_to_read(const RowLocation& row_location, size_t p
}
}

void FlexibleReadPlan::set_row_store(bool has_row_store_column) {
has_row_store = has_row_store_column;
}

Status FlexibleReadPlan::read_columns_by_plan(
const TabletSchema& tablet_schema,
const std::map<RowsetId, RowsetSharedPtr>& rsid_to_rowset,
Expand Down Expand Up @@ -456,7 +452,7 @@ Status FlexibleReadPlan::read_columns_by_plan(
const TabletSchema& tablet_schema, const std::vector<uint32_t>& cids_to_read,
const std::map<RowsetId, RowsetSharedPtr>& rsid_to_rowset,
vectorized::Block& old_value_block, std::map<uint32_t, uint32_t>* read_index) const {
DCHECK(has_row_store);
DCHECK(use_row_store);
auto mutable_columns = old_value_block.mutate_columns();
size_t read_idx = 0;
for (const auto& [rowset_id, segment_row_mappings] : row_store_plan) {
Expand Down Expand Up @@ -491,14 +487,13 @@ Status FlexibleReadPlan::fill_non_primary_key_columns(
const std::size_t segment_start_pos, const std::size_t block_start_pos,
const vectorized::Block* block, std::vector<BitmapValue>* skip_bitmaps) const {
auto mutable_full_columns = full_block.mutate_columns();
bool has_row_column = tablet_schema.has_row_store_for_all_columns();

// missing_cids are all non sort key columns' cids
const auto& non_sort_key_cids = rowset_ctx->partial_update_info->missing_cids;
auto old_value_block = tablet_schema.create_block_by_cids(non_sort_key_cids);
CHECK_EQ(non_sort_key_cids.size(), old_value_block.columns());

if (!has_row_column) {
if (!use_row_store) {
RETURN_IF_ERROR(fill_non_primary_key_columns_for_column_store(
rowset_ctx, rsid_to_rowset, tablet_schema, non_sort_key_cids, old_value_block,
mutable_full_columns, use_default_or_null_flag, has_default_or_nullable,
Expand Down
5 changes: 2 additions & 3 deletions be/src/olap/partial_update_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class FixedReadPlan {

class FlexibleReadPlan {
public:
void set_row_store(bool has_row_store_column);
FlexibleReadPlan(bool has_row_store_for_column) : use_row_store(has_row_store_for_column) {}
void prepare_to_read(const RowLocation& row_location, size_t pos,
const BitmapValue& skip_bitmap);
// for column store
Expand Down Expand Up @@ -171,10 +171,9 @@ class FlexibleReadPlan {
const vectorized::Block* block, std::vector<BitmapValue>* skip_bitmaps) const;

private:
bool use_row_store {false};
// rowset_id -> segment_id -> column unique id -> mappings
std::map<RowsetId, std::map<uint32_t, std::map<uint32_t, std::vector<RidAndPos>>>> plan;

bool has_row_store {false};
std::map<RowsetId, std::map<uint32_t /* segment_id */, std::vector<RidAndPos>>> row_store_plan;
};

Expand Down
14 changes: 13 additions & 1 deletion be/src/olap/rowset/segment_v2/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,8 @@ Status Segment::new_inverted_index_iterator(const TabletColumn& tablet_column,
}

Status Segment::lookup_row_key(const Slice& key, const TabletSchema* latest_schema,
bool with_seq_col, bool with_rowid, RowLocation* row_location) {
bool with_seq_col, bool with_rowid, RowLocation* row_location,
std::string* encoded_seq_value) {
RETURN_IF_ERROR(load_pk_index_and_bf());
bool has_seq_col = latest_schema->has_sequence_col();
bool has_rowid = !latest_schema->cluster_key_idxes().empty();
Expand Down Expand Up @@ -970,6 +971,7 @@ Status Segment::lookup_row_key(const Slice& key, const TabletSchema* latest_sche
Slice sought_key_without_seq = Slice(
sought_key.get_data(),
sought_key.get_size() - (segment_has_seq_col ? seq_col_length : 0) - rowid_length);

if (has_seq_col) {
// compare key
if (key_without_seq.compare(sought_key_without_seq) != 0) {
Expand Down Expand Up @@ -1007,6 +1009,16 @@ Status Segment::lookup_row_key(const Slice& key, const TabletSchema* latest_sche
(uint8_t*)&row_location->row_id));
}

if (encoded_seq_value) {
if (!segment_has_seq_col) {
*encoded_seq_value = std::string {};
} else {
// include marker
Slice encoded_seq_value_slice = Slice(
sought_key.get_data() + sought_key_without_seq.get_size(), seq_col_length);
*encoded_seq_value = encoded_seq_value_slice.to_string();
}
}
return Status::OK();
}

Expand Down
3 changes: 2 additions & 1 deletion be/src/olap/rowset/segment_v2/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class Segment : public std::enable_shared_from_this<Segment> {
}

Status lookup_row_key(const Slice& key, const TabletSchema* latest_schema, bool with_seq_col,
bool with_rowid, RowLocation* row_location);
bool with_rowid, RowLocation* row_location,
std::string* encoded_seq_value = nullptr);

Status read_key_by_rowid(uint32_t row_id, std::string* key);

Expand Down
Loading

0 comments on commit 2627c19

Please sign in to comment.