Skip to content

Text index: fast-path for filter-only postprocessors - #109049

Merged
ahmadov merged 13 commits into
masterfrom
ahmadov/postprocessor-token-filter-fast-path
Jul 22, 2026
Merged

ahmadov merged 13 commits into
masterfrom
ahmadov/postprocessor-token-filter-fast-path

Conversation

@ahmadov

@ahmadov ahmadov commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

Filter-only postprocessors (if(..., '', token)) now build the granule from raw tokens and drop the empties at build time, avoiding the general path's per-occurrence materialization and ActionsDAG run.

Version info

  • Merged into: 26.7.1.1313 (included in 26.7 and later)

ahmadov added 2 commits July 1, 2026 14:58
Filter-only postprocessors (`if(..., '', token)`) now build the granule from
raw tokens and drop the empties at build time, avoiding the general path's
per-occurrence materialization and `ActionsDAG` run.
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1eb62b4]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) FAIL
test_check_table/test.py::test_check_all_tables FAIL cidb, issue ISSUE EXISTS
Stress test (arm_asan_ubsan, s3) FAIL
Cannot start clickhouse-server FAIL cidb IGNORED
Check failed FAIL cidb IGNORED

AI Review

Summary

This PR now limits the fast path to literal IN/NOT IN token-drop postprocessors, skips posting-list construction for dropped tokens, and adds focused coverage for the supported forms. I did not find a remaining correctness, safety, or performance-contract issue in the current code, and the one still-open bot thread was obsolete after the latest counter change and has been resolved.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Jul 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 36 queries analysed

This PR adds an INSERT-time fast path for text-index postprocessor IN/NOT IN stop-word filters, so it only affects text-index building — never query execution. None of the flagged ClickBench queries use a text index or its postprocessor, so all three deltas are off-path run-to-run variance rather than PR effects. Q4's -11.8% is correctly suppressed inside master's variance band; Q15's -22.2% flagged improvement is downgraded to not_sure as off-path; Q18 is borderline and likewise unrelated to the change.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 15 not_sure 243 189 -22.2% <0.0001 This PR only adds an INSERT-time fast path for text-index postprocessor filters; Q15 is a SELECT with no text index, so the -22.2% improvement is off-path run-to-run variance, not a PR effect.
⚠️ 18 not_sure 1250 1317 +5.3% 0.0070 Borderline with mixed signals from the two tests (+5.3%), and the query does not exercise the changed index-build path, so this is not attributable to the PR.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 0e4c25e7-e1e7-4dff-ae57-d0bc80daf91c
  • MIRAI run: 32978c1d-b33a-48d6-a2a6-94588352d509
  • PR check IDs:
    • clickbench_92319_1784676231
    • clickbench_92330_1784676231
    • clickbench_92336_1784676231
    • tpch_adapted_1_official_92343_1784676231
    • tpch_adapted_1_official_92356_1784676231
    • tpch_adapted_1_official_92368_1784676231

@Ergus Ergus 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.

I like this idea, it a good point in between a skip words list without breakinbg the postprocessor semantic ;)

  1. We need some tests (many if possible ;p ).
  2. The hybrid IN path is completely uncovered (not in existing tests for postprocessor because that path was not special, but now it is)
  3. Of course we need some performance test to ensure/prove that this improves performance as expected and worth the extra code/complexity.

@ahmadov
ahmadov marked this pull request as ready for review July 15, 2026 11:27
@ahmadov
ahmadov force-pushed the ahmadov/postprocessor-token-filter-fast-path branch from 9e859fb to 168d7f6 Compare July 15, 2026 15:39
ahmadov added 2 commits July 21, 2026 09:22
…OT IN`

The postprocessor fast path had two branches: a generic filter-only flush
path (build every token, then drop the distinct ones the postprocessor maps
to `''` at segment flush) and the `IN`/`NOT IN` hybrid (drop per distinct
token in `addToken`, so dropped tokens never build postings).

The generic flush path built posting lists for tokens it would discard and
counted those dropped occurrences toward the segment-flush threshold, so on
high-drop non-`IN` filters (e.g. `if(lengthUTF8(token) < 3, '', token)`) it
could increase temporary-segment churn, and it was never benchmarked against
the general path.

Keep only the `IN`/`NOT IN` hybrid - the benchmarked, memory-bounded case -
and route every other filter-only postprocessor through the general per-batch
path (identical to the behaviour before the fast path existed). This removes
`use_filter_fast_path`, `filterTokens`, `dropped_tokens` and
`isFilterOnlyExpression`, and makes `build` unable to silently drop a token
(it no longer skips anything).
Rename `use_hybrid_filter` -> `use_postprocessor_drop_fast_path` and
`token_drop_filter` -> `postprocessor_drop_filter` so the names link
to the postprocessor and drop the too-generic "hybrid" term.
@ahmadov
ahmadov requested review from Ergus and rschu1ze July 21, 2026 09:33
Comment thread src/Interpreters/ITokenizer.cpp Resolved

@Ergus Ergus 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.

LGTM :)

@clickhouse-gh

clickhouse-gh Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.30% 78.30% +0.00%

Changed lines: Changed C/C++ lines covered: 80/97 (82.47%) · Uncovered code

Full report · Diff report

@ahmadov
ahmadov added this pull request to the merge queue Jul 22, 2026
Merged via the queue into master with commit c5bed8b Jul 22, 2026
347 of 353 checks passed
@ahmadov
ahmadov deleted the ahmadov/postprocessor-token-filter-fast-path branch July 22, 2026 08:33
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 22, 2026
@CurtizJ

CurtizJ commented Jul 22, 2026

Copy link
Copy Markdown
Member

It looks like perf test didn't show any improvement, and even showed a small slowdown:

Screenshot 2026-07-22 at 19 20 18 Screenshot 2026-07-22 at 19 20 28

@ahmadov

ahmadov commented Jul 22, 2026 •

Copy link
Copy Markdown
Member Author

It looks like perf test didn't show any improvement, and even showed a small slowdown:

Screenshot 2026-07-22 at 19 20 18 Screenshot 2026-07-22 at 19 20 28

it is interesting... I benchmarked during the development and there was an perf improvement. I will check it out again

@ahmadov

ahmadov commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

It looks like perf test didn't show any improvement, and even showed a small slowdown:

Screenshot 2026-07-22 at 19 20 18 Screenshot 2026-07-22 at 19 20 28

it is interesting... I benchmarked during the development and there was an perf improvement. I will check it out again

@groeneai can you check the reason?

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. Investigating why the filter-only fast-path shows no improvement / a small slowdown in the CI perf comparison versus your dev-time benchmark: I'll reproduce the text-index perf test on the merged head, profile the raw-token granule build against the general path, and follow up here with findings (and a fix PR if a real regression is confirmed).

@groeneai

Copy link
Copy Markdown
Collaborator

Checked the CI perf comparison (release builds, head 1eb62b43). The slowdown is real and reproducible, but small and fully localized to the index-build stage. It is not a "fast path didn't fire" bug.

Query (INSERT INTO tab_filter ...):

  • amd_release: 3.397s -> 3.561s (+4.8%; relative diff 0.048, exactly at the p<0.01 threshold, so it is not flagged as a significant change)
  • arm_release: 6.029s -> 6.861s (+13.8%)

The fast path is active: FunctionExecute 248 -> 2, i.e. the if(token IN (...), '', token) ActionsDAG is gone as intended.

Where the time went (profile events, base vs head, same query):

  • MergeTreeDataWriterSkipIndicesCalculationMicroseconds: +6.4% amd / +17.4% arm <- the entire delta
  • RealTimeMicroseconds +4.8% amd / +13.7% arm (tracks the query numbers)
  • Byte-identical on both paths: InsertedRows, MergeTreeDataWriterRows, compressed/uncompressed bytes, disk-write time, sorting-blocks time.

So the whole regression is inside the text-index build.

Why the win doesn't show on this dataset (and likely why it differs from your dev benchmark): the test builds 1M rows x 30 tokens = 30M occurrences; ~2/3 survive and are high-cardinality (cityHash64(number, x) % 100000, up to 100k distinct numeric strings). The dominant build cost is the token-map + posting-list construction over ~20M insertions / ~100k distinct tokens, and that work is identical on both paths. What the fast path removes (the DAG run + the intermediate Array(String) materialization) is a small fraction of it, while it adds a per-occurrence flat_hash_set::contains drop-check inside addToken for all 30M tokens in place of the single vectorized IN pass over the contiguous ColumnString. On a high-cardinality workload that nets to a wash-to-slight-loss; the optimization pays off when map-building is cheap relative to the postprocessor cost (high drop ratio and/or low surviving cardinality).

The scalar-vs-vectorized membership-test part is a hypothesis, not measured; the localization above is measured. If your dev benchmark used fewer distinct surviving tokens or a higher drop ratio, that would explain the improvement there. I can profile the build stage to confirm the micro-cause before you decide whether it is worth tuning.

@clickgapai

Copy link
Copy Markdown
Contributor

Hi @ahmadov @Ergus @rschu1ze — while reviewing this PR I found the following:

Could you review the test PR and add the can be tested label if it looks good?
Happy to discuss — close anything that's wrong or already addressed.

@rschu1ze

Copy link
Copy Markdown
Member

Hmmm, there was also no performance improvement visible in earlier commits, in particular the first one after the xml performance test was added: here / here.

@ahmadov I think it's worth testing like the bot^^ said, basically make every row inserted into the target table a stop word.

@ahmadov

ahmadov commented Jul 28, 2026 •

Copy link
Copy Markdown
Member Author

@CurtizJ Thanks for noticing it, I suppose one of the commit introduced the regression and I missed it in the performance dashboard. I opened this follow-up PR #111690 to fix it. Now, there is definitely a performance improvement.

FYI @rschu1ze

zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…essor-token-filter-fast-path

Text index: fast-path for filter-only postprocessors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants