Skip to content

Commit b21ac40

Browse files
committed
[fix](be) Preserve point-query I/O context when resolving commit TSO
### What problem does this PR solve? Issue Number: None Related PR: #68097 Problem Summary: A point query requesting commit TSO fetched that column through an independent helper with local statistics and no query I/O context. For a multi-version rowset with a cold physical TSO page, this bypassed the query's file-cache write limiter and omitted detailed read statistics from its profile. Always classify TSO as unavailable from JSONB. Build explicit row-store and missing-column projections, skip empty JSONB projections, and resolve TSO through the existing missing-column loop with the pinned source rowset. Reuse query I/O context and limiter, and use the same statistics object as print_profile for all point-query reads. Preserve delete-sign reads and restrictions on ordinary missing columns when column-store access is disabled. Remove the independent TSO fetch, placeholder rollback and redundant projection-set copies. ### Release note Preserve point-query file-cache write limits and detailed I/O statistics when reading commit TSO, including physical TSO pages in multi-version rowsets. ### Check List (For Author) - Test: Unit Test: 85 tests in 8 suites passed under ASAN_UT via run-be-ut.sh -j 96. Covers row-store projections, ordinary column restrictions, delete-sign reads, physical multi-version TSO with zero/exhausted cache-write budgets, an unlimited control, query statistics, and the existing logical TSO/cache/historical paths. The real remote-cache reader uses a local file as the object-storage stand-in. Regression test: extended tso_p0/test_commit_tso_reader_paths; not run locally. Manual test: clang-format 16, build hygiene and git diff --check passed. clang-tidy attempted; existing core/types.h:576 unmatched NOLINTEND blocks a clean result. New diagnostics were corrected; the check is not reported as passed. - Behavior changed: Yes. TSO uses the normal missing-column I/O context and profile statistics; JSONB never supplies its value. - Does this need documentation: No.
1 parent 6363e04 commit b21ac40

4 files changed

Lines changed: 368 additions & 100 deletions

File tree

‎be/src/service/point_query_executor.cpp‎

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -79,35 +79,27 @@ class PointQueryResultBlockBuffer final : public MySQLResultBlockBuffer {
7979

8080
Reusable::~Reusable() = default;
8181

82-
// get missing and include column ids
83-
// input include_cids : the output expr slots columns unique ids
84-
// missing_cids : the output expr columns that not in row columns cids
82+
// Partition the required slots into explicit row-store and column-reader projections.
83+
// JSONB may contain a commit TSO placeholder, so it never supplies this column's logical value.
8584
static void get_missing_and_include_cids(const TabletSchema& schema,
8685
const std::vector<SlotDescriptor*>& slots,
8786
int target_rs_column_id,
8887
std::unordered_set<int>& missing_cids,
8988
std::unordered_set<int>& include_cids) {
9089
missing_cids.clear();
9190
include_cids.clear();
92-
for (auto* slot : slots) {
93-
missing_cids.insert(slot->col_unique_id());
94-
}
95-
// insert delete sign column id
96-
missing_cids.insert(schema.columns()[schema.delete_sign_idx()]->unique_id());
97-
if (target_rs_column_id == -1) {
98-
// no row store columns
99-
return;
100-
}
101-
const TabletColumn& target_rs_column = schema.column_by_uid(target_rs_column_id);
102-
DCHECK(target_rs_column.is_row_store_column());
103-
// The full column group is considered a full match, thus no missing cids
104-
if (schema.row_columns_uids().empty()) {
105-
missing_cids.clear();
106-
return;
107-
}
108-
for (int cid : schema.row_columns_uids()) {
109-
missing_cids.erase(cid);
110-
include_cids.insert(cid);
91+
const std::unordered_set<int32_t> row_store_cids(schema.row_columns_uids().begin(),
92+
schema.row_columns_uids().end());
93+
for (const auto* slot : slots) {
94+
const int cid = slot->col_unique_id();
95+
const bool covered_by_row_store = target_rs_column_id != -1 &&
96+
slot->col_name() != COMMIT_TSO_COL &&
97+
(row_store_cids.empty() || row_store_cids.contains(cid));
98+
if (covered_by_row_store) {
99+
include_cids.insert(cid);
100+
} else {
101+
missing_cids.insert(cid);
102+
}
111103
}
112104
}
113105

@@ -178,6 +170,7 @@ Status Reusable::init(const TDescriptorTable& t_desc_tbl, const std::vector<TExp
178170
// get the delete sign idx in block
179171
if (has_delete_sign) {
180172
_delete_sign_idx = _col_uid_to_idx[schema.columns()[schema.delete_sign_idx()]->unique_id()];
173+
output_slot_descs.push_back(tuple_desc()->slots()[_delete_sign_idx]);
181174
}
182175

183176
if (schema.have_column(BeConsts::ROW_STORE_COL)) {
@@ -189,7 +182,6 @@ Status Reusable::init(const TDescriptorTable& t_desc_tbl, const std::vector<TExp
189182
for (const auto* slot : output_slot_descs) {
190183
if (slot->col_name() == COMMIT_TSO_COL) {
191184
_commit_tso_idx = _col_uid_to_idx.at(slot->col_unique_id());
192-
_missing_col_uids.erase(slot->col_unique_id());
193185
break;
194186
}
195187
}
@@ -541,22 +533,25 @@ Status PointQueryExecutor::_lookup_row_data() {
541533
MutableColumns& result_columns = result_columns_guard.mutable_columns();
542534
for (size_t i = 0; i < _row_read_ctxs.size(); ++i) {
543535
if (_row_read_ctxs[i]._cached_row_data.valid()) {
544-
RETURN_IF_ERROR(JsonbSerializeUtil::jsonb_to_columns(
545-
_reusable->get_data_type_serdes(),
546-
_row_read_ctxs[i]._cached_row_data.data().data,
547-
_row_read_ctxs[i]._cached_row_data.data().size,
548-
_reusable->get_col_uid_to_idx(), result_columns,
549-
_reusable->get_col_default_values(), _reusable->include_col_uids()));
536+
if (!_reusable->include_col_uids().empty()) {
537+
RETURN_IF_ERROR(JsonbSerializeUtil::jsonb_to_columns(
538+
_reusable->get_data_type_serdes(),
539+
_row_read_ctxs[i]._cached_row_data.data().data,
540+
_row_read_ctxs[i]._cached_row_data.data().size,
541+
_reusable->get_col_uid_to_idx(), result_columns,
542+
_reusable->get_col_default_values(), _reusable->include_col_uids()));
543+
}
550544
continue;
551545
}
552546
if (!_row_read_ctxs[i]._row_location.has_value()) {
553547
continue;
554548
}
555549
std::string value;
556550
const int tso_idx = _reusable->commit_tso_idx();
557-
const size_t old_tso_rows = tso_idx == -1 ? 0 : result_columns[tso_idx]->size();
558551
// fill block by row store
559-
if (_reusable->rs_column_uid() != -1) {
552+
// An empty JSONB projection means no row-store read. The decoder interprets an
553+
// empty include set as "all columns", which would also fill the TSO placeholder.
554+
if (!_reusable->include_col_uids().empty()) {
560555
bool use_row_cache = !config::disable_storage_row_cache && tso_idx == -1;
561556
io::IOContext io_ctx;
562557
io_ctx.reader_type = ReaderType::READER_QUERY;
@@ -573,11 +568,19 @@ Status PointQueryExecutor::_lookup_row_data() {
573568
_reusable->get_col_default_values(), _reusable->include_col_uids()));
574569
}
575570
if (!_reusable->missing_col_uids().empty()) {
576-
if (!_reusable->runtime_state()->enable_short_circuit_query_access_column_store()) {
571+
// Resolving TSO is mandatory even for full row-store queries with column-store
572+
// access disabled. Keep the existing restriction for ordinary missing columns.
573+
const size_t missing_user_columns =
574+
_reusable->missing_col_uids().size() - (tso_idx != -1 ? 1 : 0);
575+
if (missing_user_columns != 0 &&
576+
!_reusable->runtime_state()->enable_short_circuit_query_access_column_store()) {
577577
std::string missing_columns;
578578
for (int cid : _reusable->missing_col_uids()) {
579-
missing_columns +=
580-
_tablet->tablet_schema()->column_by_uid(cid).name() + ",";
579+
const auto& column = _tablet->tablet_schema()->column_by_uid(cid);
580+
if (column.name() == COMMIT_TSO_COL) {
581+
continue;
582+
}
583+
missing_columns += column.name() + ",";
581584
}
582585
return Status::InternalError(
583586
"Not support column store, set store_row_column=true or "
@@ -586,17 +589,20 @@ Status PointQueryExecutor::_lookup_row_data() {
586589
}
587590
// fill missing columns by column store
588591
RowLocation row_loc = _row_read_ctxs[i]._row_location.value();
589-
BetaRowsetSharedPtr rowset = std::static_pointer_cast<BetaRowset>(
590-
_tablet->get_rowset(row_loc.rowset_id));
592+
// Key lookup pins the source rowset for this read, even if compaction replaces
593+
// it in the tablet's version map before the value fetch.
594+
BetaRowsetSharedPtr rowset =
595+
std::static_pointer_cast<BetaRowset>(*(_row_read_ctxs[i]._rowset_ptr));
591596
SegmentCacheHandle segment_cache;
592597
io::IOContext io_ctx;
593598
io_ctx.reader_type = ReaderType::READER_QUERY;
594-
io_ctx.file_cache_stats = &_read_stats.file_cache_stats;
599+
io_ctx.file_cache_stats = &_profile_metrics.read_stats.file_cache_stats;
595600
io_ctx.remote_scan_cache_write_limiter = _remote_scan_cache_write_limiter.get();
596601
{
597602
SCOPED_TIMER(&_profile_metrics.load_segment_data_stage_ns);
598603
RETURN_IF_ERROR(SegmentLoader::instance()->load_segments(
599-
rowset, &segment_cache, true, false, &_read_stats, &io_ctx));
604+
rowset, &segment_cache, true, false, &_profile_metrics.read_stats,
605+
&io_ctx));
600606
}
601607
// find segment
602608
auto it = std::find_if(segment_cache.get_segments().cbegin(),
@@ -613,7 +619,7 @@ Status PointQueryExecutor::_lookup_row_data() {
613619
std::unique_ptr<ColumnIterator> iter;
614620
SlotDescriptor* slot = _reusable->tuple_desc()->slots()[pos];
615621
StorageReadOptions storage_read_options;
616-
storage_read_options.stats = &_read_stats;
622+
storage_read_options.stats = &_profile_metrics.read_stats;
617623
storage_read_options.io_ctx = io_ctx;
618624
storage_read_options.tablet_schema = rowset->tablet_schema();
619625
storage_read_options.rowset_id = rowset->rowset_id();
@@ -624,15 +630,6 @@ Status PointQueryExecutor::_lookup_row_data() {
624630
storage_read_options, iter));
625631
}
626632
}
627-
if (tso_idx != -1) {
628-
const auto& loc = _row_read_ctxs[i]._row_location.value();
629-
auto& column = result_columns[tso_idx];
630-
column->resize(old_tso_rows);
631-
const auto* slot = _reusable->tuple_desc()->slots()[tso_idx];
632-
RETURN_IF_ERROR(BaseTablet::fetch_value_by_rowids(
633-
*(_row_read_ctxs[i]._rowset_ptr), loc.segment_id, {loc.row_id},
634-
_tablet->tablet_schema()->column_by_uid(slot->col_unique_id()), column));
635-
}
636633
}
637634
if (result_columns.size() > _reusable->include_col_uids().size()) {
638635
// Padding rows for some columns that no need to output to mysql client

‎be/src/service/point_query_executor.h‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ class Reusable {
9494

9595
int32_t rs_column_uid() const { return _row_store_column_ids; }
9696

97-
const std::unordered_set<int32_t> missing_col_uids() const { return _missing_col_uids; }
97+
const std::unordered_set<int32_t>& missing_col_uids() const { return _missing_col_uids; }
9898

99-
const std::unordered_set<int32_t> include_col_uids() const { return _include_col_uids; }
99+
const std::unordered_set<int32_t>& include_col_uids() const { return _include_col_uids; }
100100

101101
RuntimeState* runtime_state() { return _runtime_state.get(); }
102102

@@ -119,9 +119,9 @@ class Reusable {
119119
std::vector<std::string> _col_default_values;
120120
// picked rowstore(column group) column unique id
121121
int32_t _row_store_column_ids = -1;
122-
// some column is missing in rowstore(column group), we need to fill them with column store values
122+
// Required columns not supplied by row store, including logical commit TSO.
123123
std::unordered_set<int32_t> _missing_col_uids;
124-
// included cids in rowstore(column group)
124+
// Explicit row-store projection; empty means skip row-store reading and JSONB decoding.
125125
std::unordered_set<int32_t> _include_col_uids;
126126
// delete sign idx in block
127127
int32_t _delete_sign_idx = -1;
@@ -309,7 +309,7 @@ class PointQueryExecutor {
309309

310310
void print_profile();
311311

312-
const OlapReaderStatistics& read_stats() const { return _read_stats; }
312+
const OlapReaderStatistics& read_stats() const { return _profile_metrics.read_stats; }
313313

314314
private:
315315
Status _init_keys(const PTabletKeyLookupRequest* request);
@@ -348,7 +348,6 @@ class PointQueryExecutor {
348348
std::unique_ptr<Block> _result_block;
349349
Metrics _profile_metrics;
350350
bool _binary_row_format = false;
351-
OlapReaderStatistics _read_stats;
352351
std::unique_ptr<io::RemoteScanCacheWriteLimiter> _remote_scan_cache_write_limiter;
353352
int32_t _row_hits = 0;
354353
// snapshot read version

0 commit comments

Comments
 (0)