Skip to content

Add a memory_prewhere query with a condition on a wide selected column - #123155

Merged
alexey-milovidov merged 1 commit into
masterfrom
memory-prewhere-perf-wide-column
Oct 1, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
memory-prewhere-perf-wide-column

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Adds a query to tests/performance/memory_prewhere.xml that measures a condition on a wide column next to a selective one, shaped like ClickBench Q37 (URL <> '' next to CounterID = 62).

The query selects the wide column as well as filtering on it (SELECT s2, count() ... WHERE filt BETWEEN ... AND s2 != '' GROUP BY s2). That makes the condition read the whole column. If the query only filters on the column, as the query added in #122604 does with s3, the optimizer rewrites the condition to s3.size != 0 and reads only the cheap size subcolumn, so the test never exercises the wide-column case. That query showed 28.4 → 28.7 ms in #122604's performance check.

On current master, the whole conjunction is one PREWHERE step (notEmpty(s2) AND filt <= 1000100 AND filt >= 1000000), so s2 is decompressed for every block. On a master binary, 20M rows, this query takes 0.025 s, against 0.007 s when s2 != '' is kept out of PREWHERE (explicit PREWHERE filt BETWEEN ...). Merging this first gives #122604 a baseline to show the multi-step improvement against.

Related: #122604

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/123155]

Version info

  • Merged into: 26.10.1.1188-master (included in 26.10 and later)

The query is shaped like ClickBench Q37: a selective condition on a narrow
column next to `s2 != ''`, with `s2` also selected. Because `s2` is selected,
the condition reads the whole column rather than its `size` subcolumn, so it
shows whether `Memory` decompresses the wide column for every block (a single
PREWHERE step) or only for the blocks where the selective condition has
passing rows (multiple steps).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [520c7ba]

Summary: ✅


AI Review

Summary

This PR adds a new memory_prewhere benchmark query meant to exercise the expensive case where a wide String column participates in the filter and is also selected, so a later PREWHERE-splitting change can show a meaningful before/after delta. I agree with the target shape, but I do not think the new benchmark is ready yet: the PR description itself says it runs in about 0.025 s on current master, which is well below the perf harness’s documented stability floor.

Findings

⚠️ Majors

  • [tests/performance/memory_prewhere.xml:28] The benchmark contract here is “stable enough to measure the PREWHERE regression”, but the PR description reports only about 0.025 s on current master while tests/performance/scripts/README.md expects perf queries to stay above 0.1 s. At that length the measurement is likely noisy, so the new case may become an unstable / too-short benchmark instead of a reliable guard for the wide-column path.
    Suggested fix: scale the workload until the query is comfortably above the harness floor on CI hardware (for example more rows, a wider filt range, or max_threads = 1).
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: make the new benchmark long enough to produce a stable signal for the intended PREWHERE regression.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 30, 2026
`CounterID = 62`). The query also selects the wide column, so the condition reads the whole column,
not its `size` subcolumn. With a single PREWHERE step the column is decompressed for every block;
with multiple steps only for the blocks where the selective condition has passing rows. -->
<query tag='selective, with a condition on a wide selected column'>SELECT s2, count() FROM mem_prewhere WHERE filt BETWEEN 1000000 AND 1000100 AND s2 != '' GROUP BY s2 FORMAT Null</query>

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.

The contract for a perf query here is “long enough to produce a stable signal”. The PR description says this new case is about 0.025 s on current master, but tests/performance/scripts/README.md asks perf queries to stay above 0.1 s because shorter ones get noisy. That makes this a weak baseline for #122604: it risks surfacing as an unstable / too-short benchmark instead of reliably measuring the PREWHERE wide-column regression. Please scale the workload up until it is comfortably above the floor on CI hardware (for example more rows, a wider filt window, or max_threads = 1).

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.

We support short queries as well.

alexey-milovidov added a commit that referenced this pull request Oct 1, 2026
The query added earlier filtered on `s3 != ''` without selecting `s3`, so the
optimizer rewrote the condition to `s3.size != 0`, which reads only the cheap
`size` subcolumn, and the query did not exercise the change (28.4 -> 28.7 ms in
the performance check). Use the same query as
#123155, which selects the column
it filters on, so that the two PRs make an identical change to the file.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 1, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 1, 2026
Merged via the queue into master with commit 17010a3 Oct 1, 2026
149 checks passed
@alexey-milovidov
alexey-milovidov deleted the memory-prewhere-perf-wide-column branch October 1, 2026 16:38
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 1, 2026
@clickhouse-gh clickhouse-gh Bot added comp-simple-engines Lightweight single-node table engines: Log/StripeLog (append-only logs), Buffer (async batching),... and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-simple-engines Lightweight single-node table engines: Log/StripeLog (append-only logs), Buffer (async batching),... pr-not-for-changelog This PR should not be mentioned in the changelog 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.

2 participants