Repository navigation
Add settings for SQL compatible behaviour of SEMI and ANTI joins - #96662
alexey-milovidov merged 83 commits into
Conversation
|
IMHO it is backward incompatible change and you need to add a setting to control this behaviour. It can be a good change, but you don't want it to be reverted if there is a big set of users that use the other bevahiour. |
Thanks for the feedback! That's a fair point. We should add a setting to keep backward compatibility. |
|
Workflow [PR], commit [2d5eed9] Summary: ✅
AI ReviewSummaryThis PR adds Final Verdict✅ No new blockers or majors found in the current diff. LLVM Coverage ReportMeasured on commit 2d5eed9.
Changed lines: Changed C/C++ lines covered: 360/371 (97.04%) · Uncovered code |
bed8e61 to
9bd4eac
Compare
9bd4eac to
ebe707c
Compare
ebe707c to
838d1a9
Compare
SELECT * returning right table columns for SEMI and ANTI JOINSEMI and ANTI joins
a3df5c9 to
16f6813
Compare
ecb8162 to
e2a5772
Compare
… wall clock `Build profile diff` is SIGKILLed at its 1800 s job timeout while retrying CI logs cluster reads, so it reds a pull request for an outage of an unrelated shared service and reports no reason at all. LogCluster.select bounds a read by attempt count only (retries=8, timeout=60, plus a 5+10+...+40 = 180 s backoff, so about 684 s worst case for one read, and requests' timeout bounds one socket read rather than the request, so a trickling connection was measured at 185 s for a single attempt). It is never bounded by wall clock, while build_profile_diff_job.py issues 16 db.query reads inside a job whose timeout is 1800 s. Three degraded reads exhaust the window, praktika SIGTERM/SIGKILLs the process, and select never returns and never raises: Db.query cannot propagate, main()'s except LogClusterUnavailable never runs, and the green report_cluster_unavailable completion added in ClickHouse#121048 is unreachable in exactly the window it was written for. The kill also skips update_comment, leaving the comparison comment of an earlier commit of the same pull request in place as if it were the current one. Observed on PR ClickHouse#96662 at head 72541f0, which already contains ClickHouse#121048 and ClickHouse#121393: 18 requests.exceptions.ReadTimeout, zero "LogCluster not ready", and the job killed exactly 1800 s after its process started with no Result at all. Reads were succeeding in between, so the job was crawling at about 420 s per read rather than blocked, which is why the budget is shared across the job's reads instead of applied to each one. A LogCluster instance now takes an optional read budget (default None, so every other caller is unchanged) and select gains one guard at the top of its retry loop, on a spent budget AND a POST already attempted. Both conditions are load-bearing rather than conveniences, for the same reason: the post-loop discriminator is defined by what the attempts did, so any read that leaves the loop having attempted no POST classifies as LogClusterNotReady (red) even though the cluster was answering. Exempting attempt 0 covers the read that starts after the deadline; requiring post_attempted covers the read whose first readiness probe fails transiently, which would otherwise break at the second iteration with nothing attempted. So the budget stops POST retries only, and the readiness schedule, which exists because is_ready fails during the same pressure spikes as the query itself, always keeps its full count. The added cost is bounded and paid at most once per job: a read that never becomes ready spends 8 probes plus the 180 s backoff, about 204 s, and then ends the job. No new green path appears, LogClusterNotReady stays red and TRANSIENT_EXCEPTION_CODES is untouched, so both the rule that only "the cluster never answered" is green and ClickHouse#121393's narrowing that keeps 159 and 209 hard continue to hold. The number is derived from the job's own configured timeout via Info().job_config, following stateful_prep_step_timeout in ci/jobs/functional_tests.py, minus a fixed reserve of 550 s, so 1250 s at the current timeout=1800. The reserve is fixed rather than a fraction because every component of it is independent of the timeout: interpreter startup before the first read, one in-flight POST overrunning its 60 s socket timeout, one already-started backoff, and the reporting tail. The docker image pull is not charged to it, because job.timeout only starts with the job process. Applied to the ClickHouse#96662 timeline the read raises at about 13:21:20 instead, 8.5 minutes before the kill, and the check completes green with the reason and a refreshed comment. The failed-attempt spacing there (65/70/75/80/86/90 s, the 60 s socket timeout plus 5*(retry+1)) identifies the 13:20:43 failure as the seventh attempt of that read, so the guard is next reached after its 35 s backoff; 13:23:14 is the first attempt of the following read, which the change never reaches. Validated against a local HTTP stub over three runs with identical classifications, with a control on the pre-change file that matches wherever no budget is passed, with assertions on the derivation keyed on the real JobConfigs.build_profile_diff_job.timeout, and with a case that pins the readiness behaviour: a spent budget plus one transient probe failure returns the body, while the same case without the post_attempted condition raises LogClusterNotReady. Co-Authored-By: Claude Opus 5 <[email protected]>
…e_table_column Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…e_table_column Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok, but I don't like setting names. Instead of ...compatibility let's unwrap the meaning of them.
|
semi_join_include_columns_from_both_sides = true |
…th_sides` / `anti_join_include_columns_from_both_sides` Replace `semi_join_compatibility` and `anti_join_compatibility` with settings whose names state their meaning. The new settings have the inverted meaning: they are enabled by default (legacy behavior, columns from both sides of a `SEMI` / `ANTI` JOIN are accessible), and disabling them restricts access to the preserved side in accordance with the SQL standard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Renamed the settings as requested ( |
… JOIN Address review: pin down that a sibling table on the hidden side of an outer `SEMI` JOIN cannot leak into a nested `JOIN ON`. Parenthesized joined-table groups become subqueries and comma joins are folded into the left operand of the next `JOIN`, so the only reachable shapes are a preceding table (part of the nested join's own left operand, visible), a later-joined table (not visible, as with the settings enabled), and the hidden side of an earlier `SEMI` JOIN (still denied). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The only failure on |
|
🕵 Merged |
# Conflicts: # src/Common/ErrorCodes.cpp
|
🕵 Merged |
With `analyzer_compatibility_prefer_alias_over_subcolumn = 1`, when the qualifier of `t.*` names both a table and a Tuple column, the matcher only ran the SEMI/ANTI access check for the table and then still expanded the Tuple subcolumns. Skip the Tuple expansion in that case and fall through to the table-expression path, which also performs the access check. Remove the duplicated Tuple expansion code and add regressions for the accessible-table case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review: `tryBindIdentifierToArrayJoinExpressions` still treated the aliases of an `ARRAY JOIN` on the hidden side of a `SEMI`/`ANTI` JOIN as live binders, so with `semi_join_include_columns_from_both_sides = 0` a preserved-side column of the same name was qualified by `SELECT *` (e.g. as `l.a`) and an outer `SELECT a` failed. Skip `ArrayJoinNode`s hidden by `isTableExpressionHiddenBySemiAntiJoin`, as `tryBindIdentifierToTableExpressions` already does. Such an `ARRAY JOIN` could not be resolved at all before: its own expression (`ARRAY JOIN arr` over the hidden table) was denied. Resolve the `ARRAY JOIN` expressions with `resolving_join_on_expression` pointing at the `ARRAY JOIN` node, so `SemiAntiJoinSideChecker` exposes only the side that contains its input, the same way a nested JOIN's `ON` expression is handled. The early `AND`/`OR` short-circuit exclusion stays limited to JOIN `ON` expressions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Pushed The only CI failure on |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add settings
semi_join_include_columns_from_both_sidesandanti_join_include_columns_from_both_sides(enabled by default) forSEMIandANTIjoins in the analyzer. When enabled, behavior is unchanged: columns from both sides are accessible after the join. Disable either setting to enforce SQL-standard semantics, where only the preserved side's columns are visible after the join.Related: #95738
Note
Medium Risk
Touches query analysis/identifier resolution around JOINs and can change query results or raise
UNKNOWN_IDENTIFIERwhen the new settings are enabled. Default behavior remains unchanged, but the JOIN-scoping logic is subtle and may have edge cases in nested joins and qualified matchers.Overview
Adds
semi_join_compatibilityandanti_join_compatibilitysettings to optionally enforce SQL-standard semantics forSEMI/ANTIJOINs, where only the preserved-side columns are visible inSELECT,WHERE, and qualified matchers.Implements preserved-side filtering during identifier resolution and
SELECT *expansion, while explicitly allowing both sides inside the current JOIN’sONexpression via a newresolving_join_on_expressionscope marker. Updates settings docs/history and adds stateless tests covering column visibility, qualifiedt.*,USING,WHERE, and nested-join scenarios.Written by Cursor Bugbot for commit a81b4d5. This will update automatically on new commits. Configure here.
Workflow [PR]
Sync PR [sync-upstream/pr/96662]
Version info
26.10.1.1614-master(included in26.10and later)