Skip to content
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
18 changes: 12 additions & 6 deletions cpp/src/reader/aligned_chunk_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -740,15 +740,21 @@ bool AlignedChunkReader::should_skip_page_by_offset(int& row_offset) {
if (row_offset <= 0) {
return false;
}
// Use time page statistic for count.
Statistic* stat = cur_time_page_header_.statistic_;
if (stat == nullptr) {
stat = cur_value_page_header_.statistic_;
// Aligned TV pages: only skip a whole page by count when both page headers
// expose the same positive row count. Using a single side (or min) when
// the other is missing or unequal can desynchronize row_offset from
// decoded row order vs. the paired time/value stream.
Statistic* ts = cur_time_page_header_.statistic_;
Statistic* vs = cur_value_page_header_.statistic_;
if (ts == nullptr || vs == nullptr) {
return false;
}
if (stat == nullptr || stat->count_ == 0) {
int32_t tc = ts->count_;
int32_t vc = vs->count_;
if (tc <= 0 || vc <= 0 || tc != vc) {
return false;
}
int32_t count = stat->count_;
int32_t count = tc;
if (row_offset >= count) {
row_offset -= count;
return true;
Expand Down
27 changes: 26 additions & 1 deletion cpp/src/reader/tsfile_series_scan_iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ bool TsFileSeriesScanIterator::should_skip_chunk_by_offset(ChunkMeta* cm) {
return false;
}

bool TsFileSeriesScanIterator::should_skip_aligned_chunk_by_offset(
ChunkMeta* time_cm, ChunkMeta* value_cm) {
if (row_offset_ <= 0) {
return false;
}
if (time_cm->statistic_ == nullptr || value_cm->statistic_ == nullptr) {
return false;
}
int32_t tc = time_cm->statistic_->count_;
int32_t vc = value_cm->statistic_->count_;
if (tc <= 0 || vc <= 0) {
return false;
}
if (tc != vc) {
return false;
}
int32_t count = tc;
if (row_offset_ >= count) {
row_offset_ -= count;
return true;
}
return false;
}

int TsFileSeriesScanIterator::get_next(TsBlock*& ret_tsblock, bool alloc,
Filter* oneshoot_filter,
int64_t min_time_hint) {
Expand Down Expand Up @@ -106,7 +130,8 @@ int TsFileSeriesScanIterator::get_next(TsBlock*& ret_tsblock, bool alloc,
min_time_hint)) {
continue;
}
if (should_skip_chunk_by_offset(value_cm)) {
if (should_skip_aligned_chunk_by_offset(time_cm,
value_cm)) {
continue;
}
chunk_reader_->reset();
Expand Down
8 changes: 8 additions & 0 deletions cpp/src/reader/tsfile_series_scan_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ class TsFileSeriesScanIterator {
}
bool should_skip_chunk_by_time(ChunkMeta* cm, int64_t min_time_hint);
bool should_skip_chunk_by_offset(ChunkMeta* cm);
/**
* Aligned (VECTOR): whole-chunk skip by row count is only safe when the
* time ChunkMeta and value ChunkMeta agree on statistic count (>0). If
* either side lacks count or counts differ, skip is disabled for this
* chunk; pages are loaded and page/row-level offset handling applies.
*/
bool should_skip_aligned_chunk_by_offset(ChunkMeta* time_cm,
ChunkMeta* value_cm);
common::TsBlock* alloc_tsblock();

private:
Expand Down
Loading