5555#include " storage/rowset/rowset_fwd.h"
5656#include " storage/schema.h"
5757#include " storage/segment/column_reader.h"
58+ #include " storage/segment/rowid_read_ahead.h"
59+ #include " storage/segment/segment_read_ahead.h"
5860#include " storage/tablet/tablet_schema.h"
5961#include " storage/utils.h"
6062#include " util/defer_op.h"
@@ -528,6 +530,12 @@ Status PointQueryExecutor::_lookup_row_key() {
528530Status PointQueryExecutor::_lookup_row_data () {
529531 // 3. get values
530532 SCOPED_TIMER (&_profile_metrics.lookup_data_ns );
533+ std::shared_ptr<io::FileRangeReadContext> read_ahead_context;
534+ if (segment_v2::SegmentReadAhead::enabled ()) {
535+ auto * scheduler = ExecEnv::GetInstance ()->file_range_read_scheduler ();
536+ DORIS_CHECK (scheduler != nullptr );
537+ read_ahead_context = scheduler->create_context ();
538+ }
531539 {
532540 auto result_columns_guard = _result_block->mutate_columns_scoped ();
533541 MutableColumns& result_columns = result_columns_guard.mutable_columns ();
@@ -552,10 +560,17 @@ Status PointQueryExecutor::_lookup_row_data() {
552560 io_ctx.reader_type = ReaderType::READER_QUERY ;
553561 io_ctx.file_cache_stats = &_profile_metrics.read_stats .file_cache_stats ;
554562 io_ctx.remote_scan_cache_write_limiter = _remote_scan_cache_write_limiter.get ();
555- RETURN_IF_ERROR (_tablet->lookup_row_data (
556- _row_read_ctxs[i]._primary_key , _row_read_ctxs[i]._row_location .value (),
557- *(_row_read_ctxs[i]._rowset_ptr ), _profile_metrics.read_stats , value,
558- use_row_cache, &io_ctx));
563+ if (read_ahead_context != nullptr ) {
564+ RETURN_IF_ERROR (_tablet->lookup_row_data_with_read_ahead (
565+ _row_read_ctxs[i]._primary_key , _row_read_ctxs[i]._row_location .value (),
566+ *(_row_read_ctxs[i]._rowset_ptr ), _profile_metrics.read_stats , value,
567+ use_row_cache, &io_ctx, read_ahead_context));
568+ } else {
569+ RETURN_IF_ERROR (_tablet->lookup_row_data (
570+ _row_read_ctxs[i]._primary_key , _row_read_ctxs[i]._row_location .value (),
571+ *(_row_read_ctxs[i]._rowset_ptr ), _profile_metrics.read_stats , value,
572+ use_row_cache, &io_ctx));
573+ }
559574 // serialize value to block, currently only jsonb row format
560575 RETURN_IF_ERROR (JsonbSerializeUtil::jsonb_to_columns (
561576 _reusable->get_data_type_serdes (), value.data (), value.size (),
@@ -598,37 +613,80 @@ Status PointQueryExecutor::_lookup_row_data() {
598613 return seg->id () == row_loc.segment_id ;
599614 });
600615 const auto & segment = *it;
601- const auto tablet_schema = _tablet->tablet_schema ();
602- for (int cid : _reusable->missing_col_uids ()) {
603- int pos = _reusable->get_col_uid_to_idx ().at (cid);
616+ StorageReadOptions read_ahead_options (_read_stats);
617+ read_ahead_options.use_page_cache = !config::disable_storage_page_cache;
618+ read_ahead_options.io_ctx = io_ctx;
619+ // Pre-read iterators need the same rowset constants as the synchronous path:
620+ // a version column in rowset [7-7] must produce 7, not its stored placeholder 0.
621+ read_ahead_options.version = rowset->version ();
622+ read_ahead_options.commit_tso = rowset->commit_tso ();
623+ std::unique_ptr<segment_v2::SegmentReadAhead> read_ahead;
624+ if (read_ahead_context != nullptr ) {
625+ const auto status = segment_v2::SegmentReadAhead::create_for_query (
626+ segment->file_reader (), ExecEnv::GetInstance (), read_ahead_context,
627+ read_ahead_options, &read_ahead);
628+ if (!status.ok ()) {
629+ LOG_EVERY_N (WARNING , 100 )
630+ << " failed to initialize point-read column read-ahead; use the "
631+ " original read path: "
632+ << status;
633+ }
634+ }
635+ if (read_ahead != nullptr ) {
636+ const auto missing_column_count = _reusable->missing_col_uids ().size ();
637+ std::vector<StorageReadOptions> read_options (missing_column_count,
638+ read_ahead_options);
639+ std::vector<std::unique_ptr<ColumnIterator>> iterators (missing_column_count);
640+ std::vector<segment_v2::RowIdColumnRead> column_reads;
641+ column_reads.reserve (missing_column_count);
642+ size_t read_index = 0 ;
643+ for (int cid : _reusable->missing_col_uids ()) {
644+ int pos = _reusable->get_col_uid_to_idx ().at (cid);
645+ SlotDescriptor* slot = _reusable->tuple_desc ()->slots ()[pos];
646+ column_reads.push_back ({.slot = slot,
647+ .result = &result_columns[pos],
648+ .read_options = &read_options[read_index],
649+ .iterator = &iterators[read_index]});
650+ ++read_index;
651+ }
604652 std::vector<segment_v2::rowid_t > row_ids {
605653 static_cast <segment_v2::rowid_t >(row_loc.row_id )};
606- auto & column = result_columns[pos];
607- std::unique_ptr<ColumnIterator> iter;
608- SlotDescriptor* slot = _reusable->tuple_desc ()->slots ()[pos];
609- int32_t index = slot->col_unique_id () >= 0
610- ? tablet_schema->field_index (slot->col_unique_id ())
611- : tablet_schema->field_index (slot->col_name ());
612- // A light schema change adds a column without writing anything, and
613- // BaseTablet::_max_version_schema only moves forward on write, so until the
614- // next load the tablet schema here does not have it. No segment holds it
615- // either, so describe it from the slot and let the segment answer with its
616- // default -- the same answer it gives once a load does bring the column in.
617- TabletColumn column_awaiting_a_load;
618- if (index < 0 ) {
619- column_awaiting_a_load = ReadSchema::tablet_column_from_slot (*slot);
654+ RETURN_IF_ERROR (segment_v2::read_columns_by_rowids_with_read_ahead (
655+ *segment, *_tablet->tablet_schema (), row_ids, column_reads,
656+ *read_ahead));
657+ } else {
658+ const auto tablet_schema = _tablet->tablet_schema ();
659+ for (int cid : _reusable->missing_col_uids ()) {
660+ int pos = _reusable->get_col_uid_to_idx ().at (cid);
661+ std::vector<segment_v2::rowid_t > row_ids {
662+ static_cast <segment_v2::rowid_t >(row_loc.row_id )};
663+ auto & column = result_columns[pos];
664+ std::unique_ptr<ColumnIterator> iter;
665+ SlotDescriptor* slot = _reusable->tuple_desc ()->slots ()[pos];
666+ int32_t index = slot->col_unique_id () >= 0
667+ ? tablet_schema->field_index (slot->col_unique_id ())
668+ : tablet_schema->field_index (slot->col_name ());
669+ // A light schema change adds a column without writing anything, and
670+ // BaseTablet::_max_version_schema only moves forward on write, so until the
671+ // next load the tablet schema here does not have it. No segment holds it
672+ // either, so describe it from the slot and let the segment answer with its
673+ // default -- the same answer it gives once a load does bring the column in.
674+ TabletColumn column_awaiting_a_load;
675+ if (index < 0 ) {
676+ column_awaiting_a_load = ReadSchema::tablet_column_from_slot (*slot);
677+ }
678+ const TabletColumn& read_column =
679+ index >= 0 ? tablet_schema->column (index) : column_awaiting_a_load;
680+ StorageReadOptions storage_read_options (_read_stats);
681+ storage_read_options.io_ctx = io_ctx;
682+ // A point lookup bypasses TabletReader, so supply the rowset context here. For
683+ // example, reading __DORIS_VERSION_COL__ from rowset [7-7] must return 7
684+ // instead of its on-disk placeholder 0.
685+ storage_read_options.version = rowset->version ();
686+ storage_read_options.commit_tso = rowset->commit_tso ();
687+ RETURN_IF_ERROR (segment->seek_and_read_by_rowid (
688+ read_column, slot, row_ids, column, storage_read_options, iter));
620689 }
621- const TabletColumn& read_column =
622- index >= 0 ? tablet_schema->column (index) : column_awaiting_a_load;
623- StorageReadOptions storage_read_options (_read_stats);
624- storage_read_options.io_ctx = io_ctx;
625- // A point lookup bypasses TabletReader, so supply the rowset context here. For
626- // example, reading __DORIS_VERSION_COL__ from rowset [7-7] must return 7
627- // instead of its on-disk placeholder 0.
628- storage_read_options.version = rowset->version ();
629- storage_read_options.commit_tso = rowset->commit_tso ();
630- RETURN_IF_ERROR (segment->seek_and_read_by_rowid (
631- read_column, slot, row_ids, column, storage_read_options, iter));
632690 }
633691 }
634692 }
0 commit comments