Skip to content

Push PromQL label matchers into the "one" side of binary operators - #128177

Open
valerypetrov wants to merge 7 commits into
ClickHouse:masterfrom
valerypetrov:promql-matchers-one-side
Open

valerypetrov wants to merge 7 commits into
ClickHouse:masterfrom
valerypetrov:promql-matchers-one-side

Conversation

@valerypetrov

@valerypetrov valerypetrov commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

This PR lets the PromQL label matcher pushdown also filter the "one" side of a binary operator (the right side, or the left side with group_right), so rate(a{instance="x"}[5m]) / on(instance, cpu) rate(b[5m]) now reads only the series of b with instance="x". Since #124879 duplicate series are checked only in matched groups, so dropping the other groups changes no result or error. A side is now filtered only if the other side can't fail by itself, because the JOIN doesn't read the other side when one side is empty: before this PR rate({__name__=~"a|b"}[1m]) and on(x) c returned an empty result instead of the duplicate-series error that Prometheus and promql_push_down_label_matchers = 0 give.

On a 10-core Mac mini with a 19,800-series dataset (6 h, 15 s, default bucketed layout), medians of 7 interleaved runs against a master build: rate(node_cpu_seconds_total{instance="host-001:9100", mode="user"}[5m]) / ignoring(mode) group_left sum without (mode) (rate(node_cpu_seconds_total[5m])) over 1 h takes 140 -> 60 ms (memory 137 -> 17 MB), rate(node_cpu_seconds_total{instance="host-001:9100"}[5m]) / on(instance, cpu, mode) rate(node_cpu_seconds_total[5m] offset 1h) 131 -> 45 ms, and a matcher keeping 75% of the series or nothing to copy stays the same.

Changelog category (leave one):

  • Performance Improvement

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

PromQL: label matchers are now also copied into the "one" side of a binary operator, so a{instance="x"} / on(instance) b reads only the series of b with instance="x". The pushdown no longer turns an error of one side into an empty result.

🤖 Generated with Claude Code


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

Since ClickHouse#124879 a binary operator checks duplicate series only in matched groups,
so the "one" side can be filtered like the other side. A side is filtered only
if the other side can't fail, because the JOIN can skip a side when the other
one is empty, and this hid errors of `and`, `group_right` and aggregations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... external Author is not a member of the ClickHouse organization labels Oct 29, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [78cf82d]

Summary: ✅


AI Review

Summary

The PR extends PromQL label matcher pushdown to the “one” operand of binary operators and prevents empty join inputs from hiding duplicate-series exceptions. No unresolved findings remain; both previous review points are addressed in the current code. The focused regression coverage and reported before/after measurements support the change.

Missing context / blind spots
  • ⚠️ CI for head 78cf82d0e8d4d78895aca4d43c673aa55534d816 is still running. The earlier targeted ASan run passed all 75 executions of the two matcher-pushdown tests, and the optimizer source is identical. Completion of the latest CI run would close the remaining merge-validation gap; tests were not rerun locally.
Final Verdict

Status: ✅ Approve. No code changes requested.

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

clickhouse-gh Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 78cf82d0e with master c3124c7e8 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.65, programs/clickhouse-keeper ×0.80 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 5.0 s 8.4 s +5.1 s (+158%)
Compile time of recompiled translation units

8 translation units recompiled, 14 s compile time in total, 8 of them have a recent master baseline.

Job report

@vitlibar vitlibar self-assigned this Nov 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

PromQL Compliance Report

Baseline: S3 master c3124c7e8

Suite Baseline Current Delta
Prometheus compliance 100.00% 100.00% +0.00%
Extended support (upstream engine tests) 93.17% 93.17% +0.00%
Suite Passed Failed Unsupported
Prometheus compliance 539 -> 539 (+0) 0 -> 0 (+0) 0 -> 0 (+0)
Extended support (upstream engine tests) 682 -> 682 (+0) 16 -> 16 (+0) 34 -> 34 (+0)

Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream 3da2514eff5c.

Note: Prometheus compliance score is unchanged vs baseline.

Uploaded compliance JSON for this PR commit

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

can be tested Allows running workflows for external contributors comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... external Author is not a member of the ClickHouse organization pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants