Skip to content

Backport #119680 to 26.7: Validate the length of a BIT column value coming from MySQL - #119753

Merged
clickhouse-gh[bot] merged 3 commits into
26.7from
backport/26.7/119680
Sep 13, 2026
Merged

clickhouse-gh[bot] merged 3 commits into
26.7from
backport/26.7/119680

Conversation

@robot-ch-test-poll

@robot-ch-test-poll robot-ch-test-poll commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #119680

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.7.8.12

@robot-ch-test-poll robot-ch-test-poll added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix labels Sep 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [2683d25]

Summary: ✅

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=119753&sha=a6aee925abe8b5c975dd92f998ddb12b3b834a1f&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

Context: Logical error: 'Bucket 4 is pushed twice' in GroupingAggregatedTransform::tryPushTwoLevelData on the 26.7 release branch. This is the family tracked in #115986; the master fix #116446 was never backported to 26.7 (its merge commit is not an ancestor of origin/26.7), so 26.7 may need that backport. Unrelated to this PR, which only touches MySQLSource.cpp and adds test 04870.

The other red, Stress test (amd_tsan) failing with Cannot start clickhouse-server on a stale Filesystem database for 05057, is fixed by #119757 (backport of #119618), which I have just merged into this branch.

@groeneai

Copy link
Copy Markdown
Collaborator

The plan of the dying query contains no exchange, so this is not the distributed-plan face and #116446 will not close it.

Pinned from the job's own server log: query 71858b9d-c602-454c-a4af-d66d1b3835be is 04605_parallel_replicas_merging_aggregated_bucket_order.sh, a Distributed table over test_cluster_two_shard_three_replicas_localhost where each shard reads its local table with plan-based parallel replicas (distributed_aggregation_memory_efficient = 1, group_by_two_level_threshold = 1, max_parallel_replicas = 3, prefer_localhost_replica = 0). The only optimizer line for that query id is Unsupported steps: MergingAggregated_25, ReadFromRemote_20, with no Shuffle, Scatter, Exchange or Gather step anywhere.

Root cause on 26.7: applyParallelReplicas.cpp:95 builds the per-shard replica merge with const bool memory_efficient_aggregation = false hard-coded, so MergingAggregatedStep::transformPipeline takes the !memory_efficient_aggregation branch (MergingAggregatedStep.cpp:130), resizes to one stream and uses the plain MergingAggregatedTransform. That transform returns the two-level buckets in Aggregator::convertToChunks order and ignores should_produce_results_in_order_of_bucket_number, which the shard has already promised to the initiator. The initiator merges memory efficiently, and bucket 4 arrives twice.

Master does not have this because #112942 made that merge obey distributed_aggregation_memory_efficient (7a902aec5b1f6). Its 26.7 cherry-pick #113810 had conflicts, was never resolved, and the robot closed it on 2026-08-17 12:58Z. Eight hours later the 26.7 backport of #112794 (691fa4c41e4cf) landed the assert and this test on the branch, so 26.7 now asserts an invariant whose fix it never received. The route is 26.7-only: 26.6 has no applyParallelReplicas.cpp.

#118802, the open backport of #114523, does not close it either. It keeps memory_efficient_aggregation = false because the 26.7 visitor is constructed without QueryPlanOptimizationSettings, so its new setProduceResultsInBucketOrder(should_produce_results_in_order_of_bucket_number || memory_efficient_aggregation) reduces to the value AggregatingStep::clone() already copies. Its own new test 04869_distributed_plan_partial_aggregation_bucket_order also fails deterministically on 26.7: 23 of 23 with the randomized settings and 34 of 34 without them, result differs, not a randomization issue.

So what this red needs is #112942 reaching 26.7. The branch backport/26.7/112942 still exists, so I will resolve the conflicts there and open the separate PR against that base, and link it here. Tell me if you would rather the original authors finish their own cherry-pick.

`04408_array_fold_cancellation` failed with

    -TIMEOUT_EXCEEDED
    +runtime throw: no timeout

and the harness's own reruns then passed five times out of five. The
test builds the array with `range(120000)` on this branch, while
`master` halved it to `range(60000)` (#110942, 2026-07-18) precisely
because "a longer array makes that setup rival `max_execution_time`,
so under sanitizers the query can be killed by the outer `timeout`
before the in-function check fires" - and the failing job is the
`amd_asan_ubsan` one. #110942 is now labelled for 26.6 and 26.7; this
merge re-triggers the workflow in the meantime.

The earlier run of this branch also died on `Logical error: 'Bucket 4
is pushed twice'`, which is a pre-existing 26.6/26.7 abort in
`04605_parallel_replicas_merging_aggregated_bucket_order` unrelated to
validating a MySQL `BIT` length - it has hit a dozen unrelated 26.7
pull requests in three weeks, and the `chassert` that turns it into a
dead server is only replaced by a thrown exception on `master` and
26.8.
@clickhouse-gh
clickhouse-gh Bot merged commit cbe5200 into 26.7 Sep 13, 2026
38 of 39 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.7/119680 branch September 13, 2026 21:46
@groeneai

Copy link
Copy Markdown
Collaborator

The separate PR is #121593, late, and I am sorry for the delay. It resolves the conflicts of the auto-closed cherry-pick #113810 against backport/26.7/112942, the base cherry_pick.py expects, so merging it fast-forwards that branch.

#118802 landed while I was working, and it improves the picture: 26.7 now has #114523's bucket-order setter and its unconditional throw, so #112942 is the only piece still missing. Until it lands that setter is inert, because applyParallelReplicas.cpp still hard-codes memory_efficient_aggregation = false; #118802's own comment says it stayed hard-coded because the visitor has no access to the optimization settings, and #112942 is what supplies them.

Measured on cbe5200ad319, debug build, randomization on: 04605 fails 3 of 20 runs and #112942's own 04606 7 of 20, always GroupingAggregatedTransform pushed bucket N twice. With #112942 applied on top of that tip: 04606 20/20 and 50/50 in one batch, 04605 20/20, 04607 10/10, 04669 10/10.

Two points need you.

1. The automation will not resume on its own. cherry_pick.py:300-306 discards a closed cherry-pick PR before create_backport(). The clean route is to fast-forward the robot's branch and reopen #113810, after which the robot merges it and opens the 26.7-facing PR itself:

git fetch https://github.com/groeneai/ClickHouse groeneai/cherrypick-26.7-112942-resolved
git push origin FETCH_HEAD:cherrypick/26.7/112942

Merging my PR instead also works, but then the 26.7-facing PR has to be created by hand, and it blocks the route above because #113810's diff becomes empty afterwards. Either way the squash onto 26.7 needs one further resolution over #118802, which rewrote the same region: keep #118802's setProduceResultsInBucketOrder call and take the derived memory_efficient_aggregation from my side, so 26.7 gets both halves. I built and tested that result, and the numbers above come from it.

2. #112942's 04606 cannot run on 26.7 in its upstream form. The outer query prunes the aggregate, so the shard-side fragment has no aggregate-state column, ReadFromParallelReplicas.cpp:197 hard-codes add_agg_info = false, and RemoteSource only auto-detects that flag from such a column. That aborts debug and sanitizer builds on the first run, on the pristine tip too; release builds raise the logical error instead. A bare client reproduces it with everything except the parallel-replica settings at default:

CREATE TABLE t (x UInt64, y UInt64) ENGINE = MergeTree ORDER BY x;
INSERT INTO t SELECT number % 200000, number FROM numbers_mt(400000);
CREATE TABLE d AS t ENGINE = Distributed('test_cluster_two_shard_three_replicas_localhost', currentDatabase(), t);

SELECT count() - uniqExact(x) FROM (SELECT x, sum(y) FROM d GROUP BY x)
SETTINGS enable_parallel_replicas = 1, max_parallel_replicas = 3, parallel_replicas_plan_based = 1,
         parallel_replicas_for_non_replicated_merge_tree = 1, prefer_localhost_replica = 0;
-- Logical error: 'Chunk should have AggregatedChunkInfo in MergingAggregatedTransform.'

Master fixed that in #111063 (+7/-1 in one function), merged five days after 26.7 was cut and never labelled for a backport. It needs parallel_replicas_plan_based = 1, which is experimental and off by default, so I would not call it a release risk. Rather than import that hunk into a #112942 cherry-pick, I restored 04606's own earlier table-based body, the form upstream used until master had the fix. If 26.7 should have #111063 as well, labelling that merged PR v26.7-must-backport is the route and the subquery form can come back with it; I will not hand-author the cherry-pick.

If you would rather the original authors finish their own cherry-pick, tell me and I will link theirs and stand down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants