Skip to content

Backport #112007 to 26.6: Fix AMBIGUOUS_COLUMN_NAME when a JOIN ON condition is repeated in WHERE - #112175

Merged
clickhouse-gh[bot] merged 6 commits into
26.6from
backport/26.6/112007
Aug 3, 2026
Merged

clickhouse-gh[bot] merged 6 commits into
26.6from
backport/26.6/112007

Conversation

@robot-clickhouse-ci-1

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #112007

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.6.2.151

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default labels Jul 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [5d6cfa5]

Summary: ✅

alexey-milovidov and others added 2 commits July 28, 2026 14:05
… `26.6`

The backported test carried `SET explain_query_plan_default = 'legacy'`, a setting added after
`26.6`, so every run failed with `UNKNOWN_SETTING` (115). On `26.6` the legacy `EXPLAIN` output
is already the only output, so the pin is unnecessary here.

Verified with the release binaries: the test reproduces `Block structure mismatch` (352) on stock
`26.6` and matches the reference with this backport applied.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (amd_tsan) hung check on f658c385 is unrelated to this backport: the hung query is INSERT INTO set_idx SELECT number, number FROM system.numbers LIMIT 100 from 00907_set_index_max_rows.sh, inflated by the AST fuzzer to ~1M rows, spending 822 of 848 elapsed seconds inside MergeTreeIndexAggregatorSet::update while already cancelled — the set skipping-index calculation in MergeTreeDataPartWriterOnDisk::calculateAndSerializeSkipIndices does not observe cancellation. No JOIN or analyzer frames anywhere in the stacks. Same class of problem as #112203 (uninterruptible CPU-bound work), but a different code path.

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112175&sha=f658c3853dad8eafeaa8873f5c2e1747196c8682&name_0=BackportPR&name_1=Stress%20test%20%28amd_tsan%29 and provide a fix in a separate PR (a cancellation check in the skip-index calculation loop). If the fix is already in progress, link it here.

I merged 26.6 into the branch to retrigger CI.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The only red on 6cdf4dfa is the job-level ERROR of Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) — no test results were uploaded, so it shows as 0 tests. The job log shows a host-level stall rather than a test failure: all three xdist workers froze at ~09:27 and then reported FAILED at the same instant (10:12:28.6) — test_keeper_snapshot_chunked_transfer/test.py::test_recover_from_snapshot_sent_by_old_leader[local_disk], test_restore_db_replica/test.py::test_restore_db_replica_with_diffrent_table_metadata[restore node2-node1] and test_distributed_load_balancing/test.py::test_load_balancing_in_order. The run then hit the 7800 s session timeout on test_recover_from_snapshot_sent_by_old_leader[remote_disk] (sending SIGTERM to process group, exit code: -9) and the whole job was cancelled while packing logs.tar.gz.

Three unrelated tests in three different workers hanging simultaneously and dying at the same timestamp points at the runner/Docker host, not at any of them. This backport touches only src/Processors/QueryPlan/FilterStep.cpp and one stateless test, and no integration test exercises that path.

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112175&sha=6cdf4dfaea6e071cddeea4daeb74ea26e0d96e19&name_0=BackportPR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%205%2F6%29 and provide a fix in a separate PR. Two things look worth addressing: the runner-level stall itself, and the fact that a session timeout kills the job before any partial result is uploaded, which turns a flaky shard into an opaque job ERROR. If a fix is already in progress, link it here.

I merged 26.6 into the branch again (15 commits behind) to retrigger CI.

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Both are already-known code paths, and only one of them needs a new PR from me.

(a) skip-index cancellation. Your diagnosis reproduces exactly from the artifact: elapsed 847.98, is_cancelled: 1, MergeTreeDataWriterSkipIndicesCalculationMicroseconds = 821815080, i.e. 821.8 s of the 848 s inside the index build. The fix you describe is already merged: #108351 by @ tiandiwonder added the per-granule query_status->checkTimeLimit() to MergeTreeDataPartWriterOnDisk::calculateAndSerializeSkipIndices, merged into 26.7.1.206.

It is missing here only because this is a 26.6 backport. Measuring checkTimeLimit occurrences in that function per branch: master 2, 26.7 2, and 26.6, 26.5, 26.4, 26.3, 25.12, 25.11, 25.10 all 0. It is also absent from the failing sha itself, so this build predates the fix rather than the fix not working.

The guard would have covered this run: the hung query has SelectedRows: 1048949 over MergeTreeDataWriterBlocks: 6 with index_granularity = 6, so the build is many granules, not one large one, and the check is reached mid-work.

So no new PR is needed for the code, only a backport of #108351 to 26.6 (and to the older lines if you want them covered). #108351 was never backported. Tell me if you want me to open that backport and I will.

(b) integration-test session timeout. Confirmed from the job log, with one correction to the sequence that changes where the fix goes. The results were not lost to the kill; the run collected 502 test outcomes, the three simultaneous freezes at 09:27 are real, the 7800 s hard subprocess backstop fired at 11:05:22 with sending SIGTERM to process group and exit code: -9, and the harness survived that and started archiving at 11:05:29:

tar -cf - -T /tmp/tmpuld8adk_ | gzip > .../ci/tmp/logs.tar.gz

That is the last thing the job ever logs. It ran for 80 minutes until the workflow cancelled the job at 12:25:07, so the upload block never ran and nothing at all was stored, not even job.log (the sibling shard has one, this shard's URL is 403). That is why the report shows status: ERROR, info: '', duration: None, results: [], links: [].

The archiving call is Utils.compress_files_gz at ci/jobs/integration_test_job.py:1242, over every _instances* directory of every failed suite, and it is unbounded. Shell.check already takes timeout=, so bounding it is small. The same shape exists in the other direction at ci/praktika/runner.py:572-575, where the on_error_hook is run with no timeout and the comment already says # Add hook timeout once it's needed, and that hook also runs before the upload block.

So results should be dumped and uploaded before any archiving, and archiving should be bounded so an overrun degrades to a missing tarball rather than an empty report. This is not specific to this shard: over 14 days, Integration tests% job-level error rows with no test results cover 19 distinct check names, including 332 rows on master across the four amd_asan_ubsan, db disk shards.

I will open a PR for that part. I am not proposing a fix for the runner-level stall itself, since I cannot attribute it beyond the host from these logs.

Neither failure is caused by the backport diff, which touches only src/Processors/QueryPlan/FilterStep.cpp and one stateless test.

@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Opened for part (b): #112972

One correction to the framing in your comment, which moved where the fix goes. The session
timeout did not kill the job before a partial result could be uploaded - the harness survived
it, collected all 502 test outcomes, and then hung 80 minutes in Utils.compress_files_gz,
which is unbounded and sits between result collection and the only result dump. So the report
was discarded from memory rather than never produced.

The PR bounds both archiving paths ahead of the upload (compress_files_gz and the
on_error_hook, whose own comment already said # Add hook timeout once it's needed) at 30
minutes, non-fatally, so an overrun costs the tarball instead of the report, and dumps the
collected results first. Bounding needed a working watchdog, so Shell._check_timeout now
wakes when the attempt's child is reaped instead of sleeping the timeout out. Three
pre-existing defects fell out on the way, each of which could publish or discard the wrong
archive without any timeout firing - the details are in the PR body.

Still not proposing a fix for the runner-level stall itself; I cannot attribute it beyond the
host from these logs.

For part (a) the offer stands: #108351 needs a v26.6-must-backport label to reach this
branch, and I have not opened anything by hand for it.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112175&sha=5af55d5ac9dbe8d076e99c2022053c89a17accd9&name_0=BackportPR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%205%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

Note that this shard finally produced a report instead of the job-level ERROR with zero tests that it returned on the four previous runs of this backport — that empty-report shape is what your #112972 addresses, and it is a different problem from what is red now.

The six failures are all in test_storage_iceberg_interoperability_local/test_interoperability.py (plus test_storage_iceberg_concurrent/test_concurrent_reads.py in the same shard), and none of them reach ClickHouse — the pyspark JVM gateway never comes up:

File: /usr/local/lib/python3.13/dist-packages/py4j/clientserver.py:438 - in connect_to_java_server
    self.socket.connect((self.java_address, self.java_port))
E   ConnectionRefusedError: [Errno 111] Connection refused

and, for the sessions that get slightly further,

File: /usr/local/lib/python3.13/dist-packages/py4j/java_gateway.py:1725 - in __getattr__
    raise Py4JError(message)
E   py4j.protocol.Py4JError: SparkConf does not exist in the JVM

Both come out of helpers/spark_tools.py:54 in ResilientSparkSession.__init__, i.e. the very first builder.getOrCreate in the started_cluster_iceberg fixture, so every test in those modules errors at setup. All are labeled retry_ok, and the retries did not help — which suggests the JVM is unavailable for the whole job, not per-attempt.

This is not caused by the backport. The same five test_interoperability cases failed the same way on the same day, 2026-08-02, on runs with pull_request_number = 0 (branch runs, not this PR):

SELECT check_start_time::Date d, pull_request_number, test_name, count()
FROM checks
WHERE check_start_time > now() - INTERVAL 10 DAY
  AND test_name LIKE 'test_storage_iceberg_interoperability_local%'
  AND test_status IN ('FAIL', 'ERROR')
GROUP BY ALL ORDER BY d DESC

The backport diff itself touches only src/Processors/QueryPlan/FilterStep.cpp and one stateless test, nothing on the Iceberg or Spark path.

I merged 26.6 (the branch was 25 commits behind, clean merge) and pushed 5d6cfa5ef55 to retrigger CI.

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Fix owed by me, task filed, PR to follow here. Two independent defects, and the evidence contradicts two points in your reading.

The JVM was alive and working in that worker. gw0 ran test_storage_delta/test.py from 11:37 to 12:00 and passed every case; the iceberg fixture failed on the same worker at 12:25:58. spark-submit and launch_gateway appear 0 times in the log, so no gateway was ever relaunched. The condition is per-process-after-the-first-stop(), not per-job.

The mechanism is cached class state in pyspark. SparkContext._ensure_initialized (3.5.5 context.py:434-437) relaunches only if not SparkContext._gateway, and neither SparkContext.stop (context.py:646-669, which clears only _jsc and _active_spark_context) nor SparkSession.stop ever clears _gateway or _jvm. helpers/cluster.py:4399 calls spark_session.stop() when an earlier spark module tears down, xdist reuses the process, and the next module inherits a truthy _gateway pointing at a dead socket. SparkConf.__init__ (conf.py:132) then does _jvm = _jvm or SparkContext._jvm, takes the non-None branch on the stale view, and py4j reports SparkConf does not exist in the JVM. That message is the signature of a stale gateway, not of a JVM that never started; ConnectionRefusedError is the same state reached one step earlier.

ResilientSparkSession cannot help here for two reasons. It clears builder._options and _instantiatedSession but not SparkContext._gateway/_jvm, so _restart would not recover it; and _restart is unreachable anyway, because __getattr__/_is_alive guard only attribute access on an already-constructed wrapper while the failure is inside __init__ (spark_tools.py:54). Spark session is dead appears 0 times in the log, confirming it never ran.

The retries did help. The retry run at 12:53:13 executed all six with -n 1 and reported 6 passed in 173.12s, which is consistent with the above: a fresh process has unpoisoned class state. The job still reported Failures: 6/805 because retry_ok is only consumed under coverage. integration_test_job.py:1252-1267 sets OK_ON_RETRY, but the sole consumer that turns it into OK sits inside if is_llvm_coverage: at :1376-1390, and that flag is set only for amd_llvm_coverage (:683). So on every other build the label is set, rendered as a tooltip, and ignored.

I plan to fix the gateway state, since that stops the failure rather than hiding it, and the natural regression test is two spark modules in one worker (pytest test_storage_delta/test.py test_storage_iceberg_interoperability_local/test_interoperability.py -n 1 --dist=loadfile). Widening retry_ok beyond coverage is a policy change that would also mask genuine flakiness, and I would rather not do it silently in the same PR. Tell me if you want it, and I will include it.

Breadth agrees with your branch-run point and narrows it: 11 rows in 21 days for that signature, all on this one shard name, on 26.6 and two of its backports, and none on master. helpers/spark_tools.py is byte-identical on master and 26.6 (blob d0270403), so the differentiator is which spark modules share a worker under --dist=loadfile -n 3, not the file.

@clickhouse-gh
clickhouse-gh Bot merged commit 864d0ef into 26.6 Aug 3, 2026
77 of 78 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.6/112007 branch August 3, 2026 19:25
@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Fix for the gateway half: #113430

Reproduced in the integration runner image on the CI-pinned pyspark 3.5.5 with the exact message
and frame, so the mechanism is confirmed: _ensure_initialized relaunches the JVM only
if not SparkContext._gateway (context.py:435-437), no stop() clears that handle, and the
wrapper could not recover because the failure is inside __init__. The PR probes the cached
gateway before building a session and discards it only when it stops answering. It recovers from
the JVM's death rather than preventing it; the trigger of the pipe break in that job is not
recoverable from its artifacts.

Two things I said above were wrong, and I would rather flag them than leave them in the record.

cluster.shutdown() calling stop() does not kill the JVM. I measured it alive and answering
after a successful stop(), which the failing job's own log also shows 10 minutes later. Neither
SparkContext.stop nor SparkSession.stop touches gateway.proc at all. So the poisoning state
is a cached handle to a JVM that died for some other reason, not one that stop() shut down.

My spark-submit and launch_gateway zero-count was not evidence. Neither string is ever
written to a log by pyspark: there is no logging, print or warn call containing either one,
so the count is zero for a successful launch too. The per-process-after-the-first-stop()
conclusion still holds, but on the class-state mechanism above, not on that count.

The retry_ok half is untouched here. Honouring it outside LLVM coverage would turn currently
failing jobs green, so it is a policy change rather than a bug fix, and I did not want to slip it
into a harness PR. Say the word if you want it and I will open it separately.

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-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants