Skip to content

add ColumnDecimal::compareTrackAt - #105110

Merged
alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
4ertus2:compare-track-at-decimal
May 19, 2026
Merged

alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
4ertus2:compare-track-at-decimal

Conversation

@4ertus2

@4ertus2 4ertus2 commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Performance Improvement

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

add compareTrackAt for ColumnDecimal

Missing part of #99013 #100945

Version info

  • Merged into: 26.5.1.845

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label May 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3e51b54]

Summary: ✅


AI Review

Summary

This PR adds ColumnDecimal::compareTrackAt and decimal partial_merge join tests to speed up key-track comparison in MergeJoin. The implementation and prior UB fix look good, but there is still missing regression evidence for the new cross-scale comparison branch, so the review remains in request-changes state.

Tests
  • ⚠️ [src/Columns/ColumnDecimal.cpp:107] The new scale != other.scale path in compareTrackAt is not covered by the added SQL test (01881_join_on_conditions_merge_decimal.sql.j2 only exercises Decimal32(0) on both sides). Add a focused partial_merge join case with different decimal scales and expected output to lock this behavior.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
  1. Add a regression case that exercises decimal-key partial_merge join with different left/right scales.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label May 16, 2026
Comment thread src/Columns/ColumnDecimal.cpp Resolved
Comment thread src/Columns/ColumnDecimal.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member

This was fixed by #105146. Let's update the branch.

@4ertus2
4ertus2 force-pushed the compare-track-at-decimal branch from f6ae7ff to 5f00b11 Compare May 17, 2026 18:57
@4ertus2

4ertus2 commented May 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Some synthetic over TPC-H

SELECT o_orderdate, l_orderkey, l_extendedprice FROM orders, lineitem WHERE (l_extendedprice = o_totalprice) ORDER BY o_orderdate ASC LIMIT 10 SETTINGS join_algorithm = 'partial_merge', max_rows_in_join = 100000000000000, max_bytes_in_join = 100000000000000

Before (26.4.2)

Not-nullable

Queries executed: 11.

localhost:9000, queries: 11, QPS: 0.194, RPS: 14550644.869, MiB/s: 160.967, result RPS: 1.940, result MiB/s: 0.000.

0%              5.113 sec.
10%             5.114 sec.
20%             5.116 sec.
30%             5.120 sec.
40%             5.124 sec.
50%             5.126 sec.
60%             5.152 sec.
70%             5.154 sec.
80%             5.177 sec.
90%             5.224 sec.
95%             5.248 sec.
99%             5.248 sec.
99.9%           5.248 sec.
99.99%          5.248 sec.

Nullable

Queries executed: 11.

localhost:9000, queries: 11, QPS: 0.144, RPS: 10796856.701, MiB/s: 140.034, result RPS: 1.440, result MiB/s: 0.000.

0%              6.890 sec.
10%             6.902 sec.
20%             6.909 sec.
30%             6.932 sec.
40%             6.935 sec.
50%             6.941 sec.
60%             6.948 sec.
70%             6.958 sec.
80%             6.979 sec.
90%             6.985 sec.
95%             6.995 sec.
99%             6.995 sec.
99.9%           6.995 sec.
99.99%          6.995 sec.

After

Not-nullable

Queries executed: 11.

localhost:9000, queries: 11, QPS: 0.302, RPS: 22648122.686, MiB/s: 250.546, result RPS: 3.020, result MiB/s: 0.000.

0%              3.262 sec.
10%             3.275 sec.
20%             3.276 sec.
30%             3.279 sec.
40%             3.290 sec.
50%             3.302 sec.
60%             3.314 sec.
70%             3.337 sec.
80%             3.340 sec.
90%             3.362 sec.
95%             3.362 sec.
99%             3.362 sec.
99.9%           3.362 sec.
99.99%          3.362 sec.

Nullable

Queries executed: 11.

localhost:9000, queries: 11, QPS: 0.248, RPS: 18561835.895, MiB/s: 240.745, result RPS: 2.475, result MiB/s: 0.000.

0%              3.980 sec.
10%             3.996 sec.
20%             4.014 sec.
30%             4.015 sec.
40%             4.019 sec.
50%             4.043 sec.
60%             4.053 sec.
70%             4.062 sec.
80%             4.067 sec.
90%             4.075 sec.
95%             4.092 sec.
99%             4.092 sec.
99.9%           4.092 sec.
99.99%          4.092 sec.

Default JOIN not-null (better parallelism)

Queries executed: 18.

localhost:9000, queries: 18, QPS: 1.308, RPS: 98080748.600, MiB/s: 1085.023, result RPS: 13.080, result MiB/s: 0.000.

0%              0.728 sec.
10%             0.733 sec.
20%             0.735 sec.
30%             0.736 sec.
40%             0.738 sec.
50%             0.740 sec.
60%             0.741 sec.
70%             0.747 sec.
80%             0.766 sec.
90%             0.778 sec.
95%             0.825 sec.
99%             0.974 sec.
99.9%           0.974 sec.
99.99%          0.974 sec.

@alexey-milovidov alexey-milovidov self-assigned this May 17, 2026
}
return res;
}
else

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 new scale != other.scale branch in compareTrackAt is not covered by the added test: all join keys there are Decimal32(0) on both sides.

Please add at least one partial_merge join case with different decimal scales (for example, Decimal32(0) joined with Decimal32(2) after compatible casting) so this path is exercised and guarded against regressions.

@clickhouse-gh

clickhouse-gh Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.20% 84.10% -0.10%
Functions 91.40% 91.40% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 66.67% (42/63) | lost baseline coverage: 1 line(s) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov merged commit f575fc7 into ClickHouse:master May 19, 2026
165 of 166 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label May 19, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @4ertus2 @alexey-milovidov — 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.

pull Bot pushed a commit to infdahai/ClickHouse that referenced this pull request Jun 11, 2026
The test uses `remote('127.{2,3}', $DB, data_01814, key)` so both shards
target the same server and therefore return identical rows (0..99). With
`optimize_distributed_group_by_sharding_key = 1` the coordinator skips
the cross-shard deduplication merge under the assumption that data is
partitioned by the sharding key. Each shard pre-aggregates and emits its
own top-10 keys (0..9); the coordinator's plan reduces to
`Limit(10) <- Union(shard1, shard2)`, which takes the first 10 rows in
arrival order.

Per-shard row production timing depends on `max_threads`, page-cache
injection, filesystem-cache settings and `prefer_localhost_replica`,
which the CI randomizes. Under some combinations the coordinator sees
e.g. `0_shardA, 0_shardB, 1_shardA, ..., 8_shardA` and LIMIT 10 fires
on `8` -- producing `0,0,1,2,3,4,5,6,7,8` instead of `0..9`.

Reproduced locally at 8/30 (~27%) with the exact randomization snapshot
from PR ClickHouse#105110; 50/50 passes with the fix on both the failing-settings
combo and the default randomization.

The check that matters is `read_rows = 40` per shard, i.e. the LIMIT was
actually pushed down (`distributed_push_down_limit = 0` reads 100/shard
in the sibling subtest). Discarding the per-key output with
`--format Null` keeps that assertion and removes the timing-dependent
one. The OFFSET subtest is unaffected -- it uses `ORDER BY key DESC`
which produces a deterministic output anyway.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105110&sha=f6ae7ff78cc0306e215e41c5384680da11fde14c&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29
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 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.

4 participants