Skip to content

Allow to prewarm marks of secondary indexes - #97772

Merged
CurtizJ merged 6 commits into
ClickHouse:masterfrom
CurtizJ:prewarm-index-marks
Feb 27, 2026
Merged

CurtizJ merged 6 commits into
ClickHouse:masterfrom
CurtizJ:prewarm-index-marks

Conversation

@CurtizJ

@CurtizJ CurtizJ commented Feb 23, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Marks of secondary indexes are now prewarmed when the prewarm_mark_cache setting is enabled (loaded into the index mark cache during data part fetches and table startup).

Version info

  • Merged into: 26.3.1.101
  • Backported to: 26.2.1.1135

@clickhouse-gh

clickhouse-gh Bot commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fbd73c5]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Feb 23, 2026
@azat azat self-assigned this Feb 24, 2026

@azat azat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

I guess it does not make sense to introduce separate setting to control skip indexes prewarm, since they will be loaded during reading anyway. What do you think?

@CurtizJ

CurtizJ commented Feb 24, 2026 •

Copy link
Copy Markdown
Member Author

I'd like to keep the existing setting to control both prewarms. Moreover, I think that a separate cache for skip index marks is a mistake.

@melvynator

Copy link
Copy Markdown
Member

Can we backport it to 26.2?

@CurtizJ

CurtizJ commented Feb 25, 2026

Copy link
Copy Markdown
Member Author

I don't mind backporting to 26.2.

if ((*settings)[MergeTreeSetting::prewarm_mark_cache])
{
result.mark_cache = getContext()->getMarkCache();
result.index_mark_cache = getContext()->getIndexMarkCache();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was thinking that we may have a separate prewarm_index_mark_cache setting. However, looks like it's covered by index_mark_cache_prewarm_ratio = 0.

Maybe here set index_mark_cache=nullptr if index_mark_cache_prewarm_ratio = 0, but it's a minor thing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd like to keep one setting. As a user, I would expect that index marks are prewarmed with prewarm_index_mark_cache. As I said, I think that separation of the mark cache and the index mark cache was a mistake.

:::
)", 0) \
DECLARE(Double, index_mark_cache_size_ratio, DEFAULT_INDEX_MARK_CACHE_SIZE_RATIO, R"(The size of the protected queue (in case of SLRU policy) in the secondary index mark cache relative to the cache's total size.)", 0) \
DECLARE(Double, index_mark_cache_prewarm_ratio, 0.95, R"(The ratio of total size of index mark cache to fill during prewarm.)", 0) \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't have compatibility for ServerSettings. Does it look fine to use 0.95 by default?

Probably fine with me; we can just fill the index mark cache's memory faster...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It should be ok.

continue;

auto marks_file = index_granularity_info.getMarksFilePath(*stream_name);
auto key = MarkCache::hash(getDataPartStorage().getDiskName() + ":" + (fs::path(getRelativePathOfActivePart()) / marks_file).string());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder why we leaked the internals of mark loader from here

auto key = MarkCache::hash(data_part_storage->getDiskName() + ":" + (fs::path(data_part_storage->getFullPath()) / mrk_path).string());

But at least this PR does not make it worse; it was copied many times in MergeTreeDataPart*::removeMarksFromCache already.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's quite dirty, but there probably isn't a better way to do it. Maybe only move this to a static method of MergeTreeMarksLoader.

@KochetovNicolai KochetovNicolai self-assigned this Feb 25, 2026
@CurtizJ
CurtizJ added this pull request to the merge queue Feb 27, 2026
Merged via the queue into ClickHouse:master with commit b9a91ac Feb 27, 2026
148 checks passed
@CurtizJ
CurtizJ deleted the prewarm-index-marks branch February 27, 2026 10:20
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 27, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Feb 27, 2026
alexey-milovidov added a commit that referenced this pull request Feb 27, 2026
Backport #97772 to 26.2: Allow to prewarm marks of secondary indexes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants