Skip to content

Apply only the client's setting changes to the query context in clickhouse-local - #125171

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix/local-set-profile
Oct 12, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix/local-set-profile

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

In clickhouse-local, SET profile = 'p' stopped applying the profile's settings to the queries that follow it. Since #114568, LocalConnection::sendQuery replaces the whole Settings of the query context with the client's copy. The client never tracks profile (its SET bookkeeping skips it), so every query lost what the profile had installed in the session. currentProfiles still reported the profile, but getSetting showed the old values, join_use_nulls from the profile was ignored, and a readonly profile did not block writes.

The fix applies only the changes of the client settings, the same way TCPHandler does. The SET dialect pinning that #114568 needed still reaches the query context, because the pinned dialect is a change too.

This also breaks the Fast test of #101785 (04843_set_profile_continuation).

Closes: #123916
Related: #114568
Related: #101785

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Fix SET profile having no effect on the following queries in clickhouse-local.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.2215-master (included in 26.10 and later)

…khouse-local`

Since #114568, `LocalConnection::sendQuery` replaced the whole `Settings` of the
query context with the client's copy. The client does not track `profile` (its
`SET` bookkeeping skips it), so the settings a `SET profile` installed in the
session were dropped for every following query: `currentProfiles` reported the
profile, while `getSetting` showed the old values and a `readonly` profile did
not block writes. Apply only `changes` of the client settings, like `TCPHandler`.

Closes: #123916

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [00ac890]

Summary: ✅


AI Review

Summary

This PR fixes the #123916 regression in clickhouse-local by overlaying only the client's changed settings onto the session-derived query context, which restores SET profile for the execute-time settings the issue reports, including join_use_nulls and readonly. The added stateless shell test exercises both reported failure modes, and I did not find a remaining correctness or safety issue in the current diff. The separate parse-time client_context synchronization gap from the earlier review thread is a broader pre-existing limitation shared with clickhouse-client over TCP, so I do not treat it as a blocker for this narrowly scoped regression fix.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-local clickhouse-local / embedded modes (incl. local file processing). labels Oct 11, 2026
/// a `SET profile`, which the client does not track.
if (query_settings)
query_context->setSettings(*query_settings);
query_context->applySettingsChanges(query_settings->changes());

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.

This only fixes the execute-time overlay inside LocalConnection; clickhouse-local still parses the next statement with the stale client_context. After a successful SET profile, ClientBase still skips mirroring profile back into the client copy (src/Client/ClientBase.cpp:3172), and the single-query / multiquery parsers keep using client_context->getSettingsRef() before LocalConnection sees the query (src/Client/ClientBase.cpp:1606, src/Client/ClientBase.cpp:3363).

That means a profile that changes parse-time settings (dialect, enable_json_ast_dialect, max_parser_depth, etc.) still does not apply to the following queries in clickhouse-local even though it works over TCP. For example, a profile that sets enable_json_ast_dialect = 1, dialect = 'clickhouse_json' will still make the next JSON statement fail on the client side. Please refresh the local client_context from the session after a successful SET profile (or add a local equivalent of applySettingsFromServerIfNeeded) and cover one parse-time setting in the regression test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Not changing this in this PR. The parse-time part is not specific to clickhouse-local: clickhouse-client over TCP has the same limitation. The server sends its settings to the client only once, in the handshake (settings_from_server is filled in Connection::receiveHello, src/Client/Connection.cpp:722). After SET profile = 'p', ClientBase skips profile in the same way (src/Client/ClientBase.cpp:3172) and keeps parsing the next statements with its own client_context. So a profile that sets dialect / enable_json_ast_dialect / max_parser_depth does not reach the client-side parser over TCP either.

This PR restores what worked before #114568: the profile's settings apply when the following queries execute in clickhouse-local. That is what #123916 reports, and the test covers it, including readonly. Copying the session's settings back into client_context after SET profile is a separate change. It would also have to work for the TCP client, which does not get the profile's settings back after the handshake. And the client would then send the copied settings as changes with every query, which interacts badly with readonly profiles (see the note at src/Client/ClientBase.cpp:1278). That deserves its own PR.

@clickhouse-gh

clickhouse-gh Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 00ac890c7 with master 371b23a4b (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.

Compile time of recompiled translation units

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

Job report

alexey-milovidov added a commit to Onyx2406/ClickHouse that referenced this pull request Oct 12, 2026
…l` applying `SET profile`

The last step of the test checked that the Kusto profile was in effect for
the following queries by expecting `SELECT 1` to be rejected. Since
ClickHouse#114568, `clickhouse-local` does
not apply the settings of `SET profile` to later queries
(ClickHouse#123916, fix pending in
ClickHouse#125171), so `SELECT 1` succeeds
and the test times out in Fast test.

That step only guarded against the profile carrying nothing parser-shaping.
Check this on the profile definition in `system.settings_profile_elements`
instead, before `SET profile`, so the test holds both with and without the
`clickhouse-local` fix. The continuation assertion itself is unchanged.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101785&sha=9a99a51ef1b3008f00aff04d4b0a27d499db078d&name_0=PR&name_1=Fast%20test
PR: ClickHouse#101785

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125171&sha=3ce4a5abbf148189390603fae2cb9a68764e4daa&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 (05210_lightweight_update_materialized_cte_in_ignore, UNKNOWN_TABLE for a reused MATERIALIZED CTE under parallel replicas; it fails in many PRs and on master since 2026-10-11) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is already in progress: #123121 (mine, open).

The missing table is the initiator's _materialized_cte_c_*, not t_lwu_cte_in_ignore: query 26 (line 79) of 05210 hits the parallel replicas race from #112642, where the query sent to the replicas can start before the initiator has materialized the CTE. That is why 100 of 101 reruns passed here. It is not caused by this PR. On the current head of #123121 (496e96c6), 05210 passes in this same job. In the last 7 days the failure hit 136 PRs and 22 master commits.

#123121 is waiting for review from @ novikd and @ devcrafter.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

@alexey-milovidov alexey-milovidov self-assigned this Oct 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 12, 2026
Merged via the queue into master with commit b7e2521 Oct 12, 2026
177 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix/local-set-profile branch October 12, 2026 17:34
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-local clickhouse-local / embedded modes (incl. local file processing). pr-not-for-changelog This PR should not be mentioned in the changelog 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.

clickhouse-local ignores SET profile settings in later queries

3 participants