Repository navigation
Allow running queries detached from client session - #112816
Conversation
|
Workflow [PR], commit [ffa89f3] Summary: ✅
AI ReviewSummaryThis PR adds PR Metadata
Missing context / blind spots
Findings❌ Blockers
Tests
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 421/447 (94.18%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes248 object files changed (+344.55 KiB total), 4 added.
738 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1637 translation units recompiled, 10285 s compile time in total, 1634 of them have a recent master baseline. Translation units without a recent master baseline:
|
…ound # Conflicts: # src/Common/ThreadPool.h
| auto background_context = Context::createCopy(context); | ||
| background_context->makeQueryContext(); | ||
|
|
||
| context->getBackgroundQueryPool().scheduleOrThrow([query_text = String(query), background_context] |
There was a problem hiding this comment.
Is it possible at this point for the context->getBackgroundQueryPool() to return nullptr due to concurrent shutdown?
There was a problem hiding this comment.
It seems not.
Before setting the pointer to null in the context, on shutdown, we do:
global_context->getBackgroundQueryPool().finish();
bool joined_background_queries = global_context->getBackgroundQueryPool().waitUntil(shutdown_deadline);
if (!joined_background_queries)
{
safeExit(0, LeakCheck::SkipAndReport);
}
And servers are started after the SCOPE_EXIT_SAFE scope is created. So there's no window between the servers being started and the scope being defined where an exception could be thrown to break this invariant.
| if (detached && session_context) | ||
| { | ||
| query_context->setCurrentRoles(session_context->getCurrentRoles()); | ||
| query_context->setSettings(session_context->getSettingsRef()); |
There was a problem hiding this comment.
Looks like we can override at least the setting constraints set with a SET command inside the session like this:
-- setup, once (as a user who can manage access)
CREATE SETTINGS PROFILE strict SETTINGS max_result_rows = 10 CONST;
-- in the session
SET profile = 'strict';
-- foreground: rejected
SELECT 1 SETTINGS max_result_rows = 999;
--> SETTING_CONSTRAINT_VIOLATION
-- background: accepted, constraint bypassed
SELECT 1 SETTINGS max_result_rows = 999, run_query_in_background = 1;
--> succeeds; system.query_log shows Settings['max_result_rows'] = '999'
Maybe something like this makes sense?
| query_context->setSettings(session_context->getSettingsRef()); | |
| /// Carry over the session's profiles, so their constraints come along; setSettings below copies only values. | |
| for (const auto & profile_id : session_context->getSettingsConstraintsAndCurrentProfiles()->current_profiles) | |
| query_context->setCurrentProfile(profile_id, /* check_constraints= */ false); | |
| query_context->setSettings(session_context->getSettingsRef()); |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
This is introduced in v26.8. As a part of this PR. ClickHouse#112816 We made some design and implementation tradeoff to make progress on this feature. Which makes it not super intuitive to use it. This doc clarifies some of the nuances Signed-off-by: Kaviraj <[email protected]>
04665 is claimed by two live open PRs (ClickHouse#112846, ClickHouse#112849). The collision is silent: the filenames differ so git reports no conflict, and check_gaps_in_tests_numbers only rejects gaps of 100 or more, never collisions. 04666, 04670, 04674 and 04675 are claimed too, by ClickHouse#112816, ClickHouse#112458 and unpublished branches respectively. Co-Authored-By: Claude Fable 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
New setting
run_query_in_background. The server accepts the query, immediately returns an empty result, and runs it to completion regardless of what happens to the connection. The result is discarded. Track the query by itsquery_idinsystem.processesandsystem.query_log. Intended for long queries likeINSERT ... SELECT,CREATE TABLE … AS SELECT, orCREATE MATERIALIZED VIEW … POPULATEthat must not die with a dropped connection.Workflow [PR]
Sync PR [sync-upstream/pr/112816]
Version info
26.8.1.1697(included in26.8and later)