Skip to content

Delay creating column readers with use_skip_indexes_on_data_read=1 - #107109

Draft
shankar-iyer wants to merge 3 commits into
ClickHouse:masterfrom
shankar-iyer:skip_indexes_and_data_read_impl
Draft

shankar-iyer wants to merge 3 commits into
ClickHouse:masterfrom
shankar-iyer:skip_indexes_and_data_read_impl

Conversation

@shankar-iyer

Copy link
Copy Markdown
Member

Change : With use_skip_indexes_on_data_read = 1, evaluate skip indexes before instantiating MergeTree readers so that fully filtered parts do not load column marks (or prefetch column data), while keeping skip index checks parallel across read threads.

Note that the essential identity of use_skip_indexes_on_data_read = 1 is still maintained. Data read of a selected part will begin immediately when it's skip index filtering is complete.

Currently, take a case where PK filtering has resulted in 1000 parts and skip index filtering is deferred to read time with use_skip_indexes_on_data_read = 1. The column readers of the 1000 parts will immediately start reading their marks etc and cause significant load on the thread pool / storage. Skip Index filtering may finally find only 20 parts to be read.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

@shankar-iyer
shankar-iyer marked this pull request as draft June 11, 2026 00:06
@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [23b23e5]

Summary: ❌

job_name test_name status info comment
Stress test (arm_tsan) FAIL
Logical error: Can't extract iceberg table state from storage snapshot for table location A (STID: 2606-4a47) FAIL cidb, issue

AI Review

Summary

This PR delays MergeTree column reader creation when use_skip_indexes_on_data_read is active, so skip/projection indexes can filter fully skipped parts before column marks are loaded or prefetches are enqueued. The current code fixes the earlier prefetch-pool deadlock by scheduling warmup jobs after releasing MergeTreePrefetchedReadPool::mutex, but I am requesting changes for missing deterministic coverage of the new prefetched read pool behavior and a changelog metadata mismatch.

PR Metadata
  • 💡 Changelog category should be Performance Improvement, not Not for changelog, because the change is a user-visible performance improvement for use_skip_indexes_on_data_read.
  • Suggested Changelog entry: Delay creation of MergeTree column readers when use_skip_indexes_on_data_read is enabled, so parts fully filtered by skip or projection indexes no longer load column marks or enqueue prefetches.
Tests
  • ⚠️ [src/Storages/MergeTree/MergeTreePrefetchedReadPool.cpp:234] Missing deterministic regression coverage for the new prefetched read pool path. Please add a focused test that forces MergeTreePrefetchedReadPool with use_skip_indexes_on_data_read = 1, creates many parts where most are filtered by skip indexes, and asserts via ProfileEvents such as RowsReadByMainReader / SelectedMarks that only selected parts load column marks and prefetch data.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions: add the focused prefetched-pool regression test and update the PR changelog category/entry.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 11, 2026
@shankar-iyer

Copy link
Copy Markdown
Member Author

@groeneai Can you review the PR description and then check the code changes ? Following should be handled with use_skip_indexes_on_data_read = 1 : 1) With normal read pool and with prefetch read pool, loading of column marks should start only after skip index filtering is complete. If the part is completely filtered out, no column marks should be loaded 2) With prefetch read pool, prefetching of column data should be enqueued only after skip index filtering is complete for a part and part has some ranges to read 3) skip index filtering should be executed concurrently on multiple parts 4) Prefetching should still be effective!

@groeneai

Copy link
Copy Markdown
Collaborator

@shankar-iyer Reviewed the description and the diff against your four requirements (read against master at c8a66ca). The approach is sound, and reqs (1) and (2) are correctly handled for both read pools. The one real concern is req (3) for the prefetch pool, which matches the clickhouse-gh bot note.

(1) Column marks load only after skip-index filtering; a fully-filtered part loads no marks. OK for both pools.
Reader creation is deferred out of MergeTreeReadPoolBase::createTask (early return when defer_reader_creation) into MergeTreeReadTask::createColumnReadersIfNeeded, which calls partHasSelectedGranules before createReaders. If the part is fully filtered it returns false, initializeReadersChain clears mark_ranges / patches_mark_ranges and returns without building the chain, and read() early-returns on !readers.main. isFinished() is then mark_ranges.empty() && readers_chain.isCurrentRangeFinished() (= true, since the chain was never initialized), so the task terminates cleanly with zero column marks loaded. Confirmed.

(2) Prefetch enqueued only after filtering, and only when the part has ranges to read. OK.
MergeTreePrefetchedReadPool::createPrefetchedReadersForTask now checks partHasSelectedGranules and returns before constructing PrefetchedReaders, so no prefetch future is created for a fully-filtered part.

(3) Skip-index filtering should run concurrently across parts. NOT met for the prefetch pool. The bot is right, and here is the asymmetry in detail:

  • Normal pool: filtering runs per task inside initializeReadersChain, on the reader thread, off the pool mutex (MergeTreeReadPool::getTask even releases the mutex before createTask, with the comment "createTask() is costly and not needed guarded by mutex"). So parts filter in parallel and a selected part starts reading as soon as its own filtering completes. This matches the stated contract.
  • Prefetch pool: getTask takes MergeTreePrefetchedReadPool::mutex and, on the first call, runs startPrefetches() still under that mutex. startPrefetches() drains the entire prefetch_queue in one loop, and each createPrefetchedReadersForTask now synchronously calls partHasSelectedGranules -> getOrBuildIndexReadResult -> skip_index_reader->read(...), which is the expensive index evaluation and can hit remote storage. So the first reader thread evaluates skip indexes for every prefetch-eligible part, serially, under the mutex, before any task is returned to any thread. That serializes filtering (breaks req 3), delays data reads for already-selected parts until unrelated parts finish filtering (breaks the "data read of a selected part begins immediately when its filtering is complete" contract from the description), and blocks the other reader threads on the mutex meanwhile.

Suggestion: reader creation in the prefetch path is already async (PrefetchedReaders runs on prefetch_threadpool); only the partHasSelectedGranules gate is synchronous-under-mutex. Move that gate into the async unit rather than calling it in startPrefetches: schedule one filtering + reader-creation job per task on prefetch_threadpool and let startPrefetches just enqueue and return the mutex. The getOrBuildIndexReadResult registry already dedupes per part via its promise/future, so concurrent jobs are safe and will not double-read a part. Selected parts then get their readers/prefetch as soon as their own filtering finishes, and filtering across parts runs concurrently. That preserves (1) and (2) while restoring (3) and (4).

(4) Prefetching still effective. Mostly OK, but gated by the (3) issue.
For selected parts the prefetch future is still created, so prefetching is preserved. The only degradation is the up-front serial filtering above delaying when prefetches are actually issued. Fixing (3) restores full effectiveness.

Minor, non-blocking:

  • partHasSelectedGranules: the check-then-fill of part_selection_cache is racy in the normal pool (two reader threads can both miss the cache and both compute the same part), but it is idempotent (getOrBuildIndexReadResult dedupes, and markPartFullySkipped stores 0 and erases idempotently), so it is at most a little redundant work, not a correctness problem. Just noting it.
  • A test for the 1000-PK-parts / ~20-selected scenario, asserting (via ProfileEvents or system.query_log) that no column marks are read for the filtered parts, run for both the default and the prefetch read pools, would lock in this behavior and guard against a regression of (3)/(4).

Happy to go deeper on the prefetch refactor if useful.

@shankar-iyer

Copy link
Copy Markdown
Member Author

@groeneai Can you implement (3) for the prefetch pool from your previous response ?

@groeneai

Copy link
Copy Markdown
Collaborator

@shankar-iyer Here is an implementation of (3) for the prefetch pool, following the approach from my previous review. It is localized to MergeTreePrefetchedReadPool.{h,cpp}; the non-deferred (normal prefetch) path is unchanged. Built and tested locally against this PR head (c8a66ca). I cannot push to your branch, so the patch is below as a diff you can apply directly (git apply).

What it does

Instead of filtering every prefetch-eligible part inline inside startPrefetches() while holding MergeTreePrefetchedReadPool::mutex, it schedules one warmup job per part on prefetch_threadpool. Each job runs partHasSelectedGranules (the expensive skip/projection index read) and, if the part survives, createReaders + issues the prefetch. So:

  • Filtering now runs concurrently across parts (req 3), not serially under the mutex.
  • startPrefetches() only enqueues jobs and returns the mutex, so reader threads are not blocked behind filtering of unrelated parts.
  • A selected part gets its readers and prefetch as soon as its own filtering completes (req 4); a fully-filtered part still creates nothing (reqs 1 and 2 preserved).
  • getOrBuildIndexReadResult already dedupes per part via its promise/future registry, so concurrent jobs over the same part are safe.

Three things worth calling out

  1. ThreadTask is now shared_ptr-owned (TaskHolder::task and ThreadTaskPtr). A reader thread can take a task out of per_thread_tasks via getTask while its warmup job is still in flight; shared ownership keeps the task alive for the job. The result is published back under mutex, so it cannot race getTask/createTask.

  2. Self-deadlock avoidance. The warmup jobs run on prefetch_threadpool, and PrefetchedReaders normally schedules the actual prefetch I/O onto the same pool. ThreadPool::scheduleOrThrowOnError blocks when the queue is full, so a warmup job scheduling onto its own saturated pool could deadlock (producer and consumer are the same pool). The warmup path therefore issues prefetchBeginOfRange inline (new issue_prefetch_synchronously flag on PrefetchedReaders); the real I/O still goes to the remote-FS read pool, a different pool. The reader-thread (non-deferred) path is unchanged and still offloads prefetch to prefetch_threadpool.

  3. Error propagation. If a warmup job throws (filtering or reader creation), the exception is stored on the task and rethrown in createTask under the mutex, so it reaches the query instead of being swallowed (the synchronous path propagated such errors directly). prefetch_warmup_runner is declared last so it is destroyed first and drains all in-flight jobs while the members they touch are still alive.

Local validation (debug build, this PR head)

  • Forced the prefetch pool on local FS (allow_prefetched_read_pool_for_local_filesystem=1, local_filesystem_read_method='pread_threadpool') with use_skip_indexes_on_data_read=1, on a 200-part table (minmax skip index, one distinct value per part, merges stopped). Confirmed via server log that MergeTreePrefetchedReadPool is the pool in use.
  • Correctness matches the non-deferred baseline for: single selected part, 50-of-200 selected parts, full scan, and all-filtered. 50 sequential iterations and 12 parallel clients x 15 mixed queries (180 total): all exact, no hangs, no errors.
  • Req 1 / fully-filtered, verified via system.query_log ProfileEvents: 50-part select reads SelectedMarks=50, read_rows=250000, RowsReadByMainReader=250000 (only the selected parts, not all 200); val with no matching part reads SelectedMarks=0, read_rows=0.
  • Existing test 03533_skip_index_on_data_reading still passes; non-deferred prefetch path and deferred-normal-pool path both still correct.

I did not run a TSAN build locally (time), so a ThreadSanitizer pass on the prefetch + skip-index path before merge would be worthwhile to confirm the concurrent warmup path is race-free. A 1000-parts / ~20-selected test asserting the ProfileEvents above for both pools (mentioned in my prior review) would also lock in (3)/(4).

Patch (apply with git apply on this PR head)
diff --git a/src/Storages/MergeTree/MergeTreePrefetchedReadPool.cpp b/src/Storages/MergeTree/MergeTreePrefetchedReadPool.cpp
index 1f5e43c9f571..5cb5631be75d 100644
--- a/src/Storages/MergeTree/MergeTreePrefetchedReadPool.cpp
+++ b/src/Storages/MergeTree/MergeTreePrefetchedReadPool.cpp
@@ -66,18 +66,32 @@ MergeTreePrefetchedReadPool::PrefetchedReaders::PrefetchedReaders(
     ThreadPool & pool,
     MergeTreeReadTask::Readers readers_,
     Priority priority_,
-    MergeTreePrefetchedReadPool & read_prefetch)
+    MergeTreePrefetchedReadPool & read_prefetch,
+    bool issue_prefetch_synchronously)
     : is_valid(true)
     , readers(std::move(readers_))
     , prefetch_runner(pool, ThreadName::PREFETCH_READER)
 {
-    prefetch_runner.enqueueAndKeepTrack(read_prefetch.createPrefetchedTask(readers.main.get(), priority_));
-
+    /// Collect all readers that need a prefetch, then either schedule them on `pool` (default
+    /// path: called from a reader thread, so prefetching is offloaded) or issue them inline
+    /// (deferred warmup path: already running on `pool`, so scheduling onto the same pool again
+    /// could self-deadlock when its queue is full). Both paths run the same task closure (which
+    /// keeps the PrefetchIncrement / async-read metrics accounting identical).
+    std::vector<IMergeTreeReader *> readers_to_prefetch;
+    readers_to_prefetch.push_back(readers.main.get());
     for (const auto & reader : readers.prewhere)
-        prefetch_runner.enqueueAndKeepTrack(read_prefetch.createPrefetchedTask(reader.get(), priority_));
-
+        readers_to_prefetch.push_back(reader.get());
     for (const auto & patch_reader : readers.patches)
-        prefetch_runner.enqueueAndKeepTrack(read_prefetch.createPrefetchedTask(patch_reader->getReader(), priority_));
+        readers_to_prefetch.push_back(patch_reader->getReader());
+
+    for (auto * reader : readers_to_prefetch)
+    {
+        auto prefetch_task = read_prefetch.createPrefetchedTask(reader, priority_);
+        if (issue_prefetch_synchronously)
+            prefetch_task();
+        else
+            prefetch_runner.enqueueAndKeepTrack(std::move(prefetch_task));
+    }
 
     fiu_do_on(FailPoints::prefetched_reader_pool_failpoint,
     {
@@ -139,6 +153,7 @@ MergeTreePrefetchedReadPool::MergeTreePrefetchedReadPool(
     , log(getLogger(
           "MergeTreePrefetchedReadPool("
           + (parts_ranges.empty() ? "" : parts_ranges.front().data_part->storage.getStorageID().getNameForLogs()) + ")"))
+    , prefetch_warmup_runner(prefetch_threadpool, ThreadName::PREFETCH_READER)
 {
     /// Tasks creation might also create a lost of readers - check they do not
     /// do any time consuming operations in ctor.
@@ -164,11 +179,9 @@ std::function<void()> MergeTreePrefetchedReadPool::createPrefetchedTask(IMergeTr
     };
 }
 
-void MergeTreePrefetchedReadPool::createPrefetchedReadersForTask(ThreadTask & task)
+std::unique_ptr<MergeTreePrefetchedReadPool::PrefetchedReaders>
+MergeTreePrefetchedReadPool::buildReadersForTask(const ThreadTask & task, bool on_warmup_thread)
 {
-    if (task.isValidReadersFuture())
-        throw Exception(ErrorCodes::LOGICAL_ERROR, "Task already has a reader");
-
     if (pool_settings.defer_reader_creation)
     {
         const auto & read_info = *task.read_info;
@@ -176,12 +189,25 @@ void MergeTreePrefetchedReadPool::createPrefetchedReadersForTask(ThreadTask & ta
                 read_info.part_index_in_query,
                 storage_snapshot->metadata,
                 read_info.alter_conversions->getAllUpdatedColumns()))
-            return;
+            return nullptr;
     }
 
     auto extras = getExtras();
     auto readers = MergeTreeReadTask::createReaders(task.read_info, extras, task.ranges, task.patches_ranges);
-    task.readers_future = std::make_unique<PrefetchedReaders>(prefetch_threadpool, std::move(readers), task.priority, *this);
+    /// When already running on the prefetch threadpool (deferred warmup path), issue the prefetch
+    /// inline instead of scheduling it onto the same pool again, to avoid a self-deadlock.
+    return std::make_unique<PrefetchedReaders>(
+        prefetch_threadpool, std::move(readers), task.priority, *this, /*issue_prefetch_synchronously=*/on_warmup_thread);
+}
+
+void MergeTreePrefetchedReadPool::createPrefetchedReadersForTask(ThreadTask & task)
+{
+    if (task.isValidReadersFuture())
+        throw Exception(ErrorCodes::LOGICAL_ERROR, "Task already has a reader");
+
+    /// Synchronous path: invoked from startPrefetches() while holding `mutex`, so the result can be
+    /// stored directly. The async (deferred) path schedules buildReadersForTask on the warmup runner.
+    task.readers_future = buildReadersForTask(task, /*on_warmup_thread=*/false);
 }
 
 void MergeTreePrefetchedReadPool::startPrefetches()
@@ -200,7 +226,44 @@ void MergeTreePrefetchedReadPool::startPrefetches()
     while (!prefetch_queue.empty())
     {
         const auto & top = prefetch_queue.top();
-        createPrefetchedReadersForTask(*top.task);
+
+        if (pool_settings.defer_reader_creation)
+        {
+            /// With `use_skip_indexes_on_data_read`, reader creation is gated on skip-index
+            /// filtering (partHasSelectedGranules), which is expensive and may read from remote
+            /// storage. Doing it inline here would serialize filtering across all parts while
+            /// holding `mutex`, blocking every reader thread until the slowest part finishes
+            /// filtering. Instead schedule one warmup job per part: filtering then runs
+            /// concurrently and each selected part starts prefetching as soon as its own filtering
+            /// completes. getOrBuildIndexReadResult dedupes per part via a promise/future registry,
+            /// so concurrent jobs are safe. The task is shared_ptr-owned so it outlives this job
+            /// even if a reader thread takes it from per_thread_tasks first; the result is stored
+            /// back under `mutex` so it cannot race getTask()/createTask().
+            auto task = top.task;
+            prefetch_warmup_runner.enqueueAndKeepTrack(
+                [this, task]
+                {
+                    std::unique_ptr<PrefetchedReaders> readers_future;
+                    std::exception_ptr warmup_exception;
+                    try
+                    {
+                        readers_future = buildReadersForTask(*task, /*on_warmup_thread=*/true);
+                    }
+                    catch (...)
+                    {
+                        warmup_exception = std::current_exception();
+                    }
+
+                    std::lock_guard lock(mutex);
+                    task->readers_future = std::move(readers_future);
+                    task->warmup_exception = std::move(warmup_exception);
+                },
+                top.task->priority);
+        }
+        else
+        {
+            createPrefetchedReadersForTask(*top.task);
+        }
 #ifndef NDEBUG
         if (prev.task)
         {
@@ -342,10 +405,21 @@ MergeTreeReadTaskPtr MergeTreePrefetchedReadPool::stealTask(size_t thread, Merge
 
 MergeTreeReadTaskPtr MergeTreePrefetchedReadPool::createTask(ThreadTask & task, MergeTreeReadTask * previous_task)
 {
+    /// Called under `mutex` (from getTask/stealTask), the same lock the async warmup job uses to
+    /// publish its result, so reading these fields here is race-free. If the warmup job threw
+    /// while filtering or creating readers, rethrow so the error reaches the query instead of
+    /// being silently swallowed (the synchronous path propagates such errors directly).
+    if (task.warmup_exception)
+        std::rethrow_exception(task.warmup_exception);
+
     if (task.isValidReadersFuture())
         return MergeTreeReadPoolBase::createTask(task.read_info, task.readers_future->get(), task.ranges, task.patches_ranges, updater);
-    else
-        return MergeTreeReadPoolBase::createTask(task.read_info, task.ranges, task.patches_ranges, previous_task, updater);
+
+    /// No prefetched readers: either the part was fully filtered out by the warmup job, or a reader
+    /// thread reached this task before its warmup job ran. Fall through to the base pool, which (in
+    /// the deferred path) defers reader creation to MergeTreeReadTask::initializeReadersChain ->
+    /// createColumnReadersIfNeeded, where skip-index filtering is re-checked (cached) on this thread.
+    return MergeTreeReadPoolBase::createTask(task.read_info, task.ranges, task.patches_ranges, previous_task, updater);
 }
 
 void MergeTreePrefetchedReadPool::fillPerPartStatistics()
@@ -573,10 +647,10 @@ void MergeTreePrefetchedReadPool::fillPerThreadTasks(size_t threads, size_t sum_
 
             const auto & read_info = per_part_infos[part_idx];
             auto patch_ranges = ranges_in_patch_parts.getRanges(read_info->data_part, read_info->patch_parts, ranges_to_get_from_part);
-            auto thread_task = std::make_unique<ThreadTask>(read_info, ranges_to_get_from_part, std::move(patch_ranges), priority);
+            auto thread_task = std::make_shared<ThreadTask>(read_info, ranges_to_get_from_part, std::move(patch_ranges), priority);
 
             if (allow_prefetch)
-                prefetch_queue.emplace(TaskHolder{thread_task.get(), i});
+                prefetch_queue.emplace(TaskHolder{thread_task, i});
 
             per_thread_tasks[i].push_back(std::move(thread_task));
 
diff --git a/src/Storages/MergeTree/MergeTreePrefetchedReadPool.h b/src/Storages/MergeTree/MergeTreePrefetchedReadPool.h
index 47b7d1f3572f..5bb151681de4 100644
--- a/src/Storages/MergeTree/MergeTreePrefetchedReadPool.h
+++ b/src/Storages/MergeTree/MergeTreePrefetchedReadPool.h
@@ -60,8 +60,13 @@ private:
     class PrefetchedReaders
     {
     public:
+        /// When `issue_prefetch_synchronously` is true, prefetches are issued inline in the
+        /// constructor instead of being scheduled on `pool`. Used by the deferred warmup path,
+        /// which already runs on a background thread, so it must not recursively enqueue onto the
+        /// same prefetch threadpool (that could self-deadlock when the pool queue is full).
         PrefetchedReaders(
-            ThreadPool & pool, MergeTreeReadTask::Readers readers_, Priority priority_, MergeTreePrefetchedReadPool & read_prefetch);
+            ThreadPool & pool, MergeTreeReadTask::Readers readers_, Priority priority_, MergeTreePrefetchedReadPool & read_prefetch,
+            bool issue_prefetch_synchronously = false);
 
         void wait();
         MergeTreeReadTask::Readers get();
@@ -96,16 +101,22 @@ private:
         std::vector<MarkRanges> patches_ranges;
         Priority priority;
         std::unique_ptr<PrefetchedReaders> readers_future;
+        /// Set by the asynchronous warmup job (deferred path) when skip-index filtering or reader
+        /// creation throws. Rethrown by the reader thread in createTask() so the error is not lost
+        /// (the synchronous path propagates such errors directly).
+        std::exception_ptr warmup_exception;
     };
 
     struct TaskHolder
     {
-        ThreadTask * task = nullptr;
+        std::shared_ptr<ThreadTask> task;
         size_t thread_id = 0;
         bool operator<(const TaskHolder & other) const;
     };
 
-    using ThreadTaskPtr = std::unique_ptr<ThreadTask>;
+    /// Shared so an in-flight asynchronous warmup job (deferred path) can co-own the task and keep
+    /// it alive even after a reader thread takes it from per_thread_tasks via getTask().
+    using ThreadTaskPtr = std::shared_ptr<ThreadTask>;
     using ThreadTasks = std::deque<ThreadTaskPtr>;
     using TasksPerThread = std::map<size_t, ThreadTasks>;
     using PartStatistics = std::vector<PartStatistic>;
@@ -115,6 +126,13 @@ private:
 
     void startPrefetches();
     void createPrefetchedReadersForTask(ThreadTask & task);
+    /// Does the expensive part of reader creation for a single task WITHOUT holding `mutex`:
+    /// skip-index filtering (deferred path) and reader construction + prefetch issuing. Returns
+    /// nullptr when the part is fully filtered out. The caller stores the result into
+    /// `task.readers_future` (under `mutex` in the async path; already-locked in the sync path).
+    /// `on_warmup_thread` is true when invoked from a prefetch_warmup_runner job, in which case
+    /// prefetches are issued inline rather than scheduled onto the same threadpool.
+    std::unique_ptr<PrefetchedReaders> buildReadersForTask(const ThreadTask & task, bool on_warmup_thread);
     std::function<void()> createPrefetchedTask(IMergeTreeReader * reader, Priority priority);
 
     MergeTreeReadTaskPtr stealTask(size_t thread, MergeTreeReadTask * previous_task);
@@ -133,6 +151,12 @@ private:
     bool started_prefetches = false;
     LoggerPtr log;
 
+    /// Runs per-task skip-index filtering + reader creation concurrently across parts on
+    /// `prefetch_threadpool` (deferred path only). Declared after every member its jobs touch
+    /// (mutex, prefetch_threadpool, per_thread_tasks, ...) so it is destroyed FIRST: its
+    /// destructor drains all in-flight jobs while everything they reference is still alive.
+    ThreadPoolCallbackRunnerLocal<void> prefetch_warmup_runner;
+
     /// A struct which allows to track max number of tasks which were in the
     /// threadpool simultaneously (similar to CurrentMetrics, but the result
     /// will be put to QueryLog).

@shankar-iyer

Copy link
Copy Markdown
Member Author

@groeneai Check the above review comment : #107109 (comment)

const auto & top = prefetch_queue.top();
createPrefetchedReadersForTask(*top.task);

if (pool_settings.defer_reader_creation)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new path that enforces the PR's prefetch-pool contract for use_skip_indexes_on_data_read, but the PR does not add a deterministic regression test that forces MergeTreePrefetchedReadPool. The existing skip-index read tests can pass without exercising this branch, so a future change could again create column readers/prefetches for fully skipped parts, or serialize filtering before reads, without a stable test failure. Please add a focused test that enables the prefetched read pool, creates many parts where most are skipped by the index, and asserts via ProfileEvents such as RowsReadByMainReader / SelectedMarks that only selected parts load column marks and prefetch data.

@clickhouse-gh

clickhouse-gh Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.40% 92.30% -0.10%
Branches 77.30% 77.30% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 211/217 (97.24%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 6 line(s) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Dear @shankar-iyer, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

@abashkeev abashkeev added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Dear @shankar-iyer, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants