Repository navigation
Include the webassembly_udf_* settings in the query condition cache key - #120050
alexey-milovidov wants to merge 1 commit into
Conversation
… key A `LANGUAGE WASM` function declared `DETERMINISTIC` is admitted to the query condition cache like any other function, but `FunctionUserDefinedWasm` snapshots its execution budget when it is built (`webassembly_udf_max_fuel`, `webassembly_udf_max_memory`) and reads `webassembly_udf_max_input_block_size` and `webassembly_udf_input_split_memory_ratio` per call, none of which reaches `ActionsDAG::Node::updateHash`. A "no marks match" verdict primed under a lenient budget was served to a session with a stricter budget instead of its `WASM_ERROR` / `BAD_ARGUMENTS` exception. Fold the four settings into `queryConditionCacheSettingsSalt`, following the registration rule introduced in #117803. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [f375e84] Summary: ❌
AI ReviewSummaryThis PR adds the query-scoped Findings❌ Blockers
Final VerdictChanges requested. The new salt covers the obvious query-scoped budgets, but the review surface for deterministic WASM UDFs is still incomplete and one of the new regression assertions is mis-targeted. LLVM Coverage Report |
| /// (a stricter budget runs out of fuel or memory on the same rows, an out-of-range ratio is rejected), and | ||
| /// none of them changes the function name or the result type, so a verdict primed under a lenient budget | ||
| /// must not be served to a session with a stricter one. | ||
| hash.update(settings[Setting::webassembly_udf_max_fuel].value); |
There was a problem hiding this comment.
FunctionUserDefinedWasm still has semantics-affecting state outside this salt. In particular, it latches the persisted webassembly_udf_enable_fuel UDF setting into getWasmModuleConfig(... getFuelMode()) and captures other persisted WASM-definition properties like serialization_format in the executable object, but ActionsDAG::Node::updateHash() only hashes the SQL function name / result type and CREATE OR REPLACE FUNCTION does not clear the query condition cache. That means CREATE OR REPLACE FUNCTION f ... SETTINGS webassembly_udf_enable_fuel = false, prime a no-match entry, then replace the same f with fuel enabled and rerun under webassembly_udf_max_fuel = 1 will still reuse the stale verdict instead of surfacing the WASM_ERROR. Either invalidate the query condition cache on WASM UDF create/replace/drop, or include a stable fingerprint of the persisted WASM definition in the deterministic-function hash.
|
|
||
| -- Prime the cache with an unlimited budget: the identity function never returns -1, so no mark matches. | ||
| SYSTEM DROP QUERY CONDITION CACHE; | ||
| SELECT count() FROM t_qcc_wasm WHERE identity_qcc_det(x) = -1 SETTINGS webassembly_udf_max_fuel = 0, webassembly_udf_max_memory = 134217728, webassembly_udf_input_split_memory_ratio = 0.5; |
There was a problem hiding this comment.
The title/body say all four execution-budget settings are now part of the cache key, but this regression only varies three of them. Nothing here changes webassembly_udf_max_input_block_size, so the new hash.update(settings[Setting::webassembly_udf_max_input_block_size].value); line can be deleted and this test still passes. Please add a case where the prime query uses a small fixed block size to fit under the same fuel/memory budget and the rerun uses webassembly_udf_max_input_block_size = 0 (or a larger block) so the uncached execution is supposed to raise.
| -- one unit of fuel is exhausted by the first call, | ||
| SELECT count() FROM t_qcc_wasm WHERE identity_qcc_det(x) = -1 SETTINGS webassembly_udf_max_fuel = 1; -- { serverError WASM_ERROR } | ||
| -- a memory limit below the module's minimum memory cannot even instantiate it, | ||
| SELECT count() FROM t_qcc_wasm WHERE identity_qcc_det(x) = -1 SETTINGS webassembly_udf_max_memory = 1024; -- { serverError WASM_ERROR } |
There was a problem hiding this comment.
This assertion is targeting a different branch than the comment above and the PR body describe. FunctionUserDefinedWasm::executeImpl rejects any guest-memory ABI below one WASM_PAGE_SIZE with BAD_ARGUMENTS before instantiation, so webassembly_udf_max_memory = 1024 does not reach the module-minimum-memory WASM_ERROR path. Either make the expected error BAD_ARGUMENTS, or switch this to a one-page cap against a module whose declared minimum is larger (like 05088_wasm_abi_sub_page_memory_limit.sh) if you want to validate the instantiation failure stays uncached.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
|
Will be fixed properly by #120690 |
Related: #117803
Follow-up to #117803, which folds function settings that do not reach the condition's
ActionsDAGinto the query condition cache key. The AI review on that PR pointed out one more family after it was merged: aLANGUAGE WASMfunction declaredDETERMINISTICis admitted to the cache, andFunctionUserDefinedWasmsnapshotswebassembly_udf_max_fuel/webassembly_udf_max_memoryin its compartment pool config when it is built and readswebassembly_udf_max_input_block_size/webassembly_udf_input_split_memory_ratioper call. They decide between a result and aWASM_ERROR/BAD_ARGUMENTSexception without changing the function name or the result type, so a "no marks match" verdict primed under a lenient budget was served to a session with a stricter budget instead of its exception.This registers the four settings in
queryConditionCacheSettingsSaltunder the same rule as the rest of the salt. The regression test primes the cache with an unlimited budget and then checks that one unit of fuel, a memory cap below the module's minimum memory, and an out-of-range split ratio each still raise on the same predicate. Verified against a binary without the fix: the fuel line "succeeded but the server error 770 was expected".Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The query condition cache key now includes the
webassembly_udf_*execution budget settings, so a "no rows match" verdict from a deterministicLANGUAGE WASMfunction evaluated under a lenient fuel or memory budget is no longer served to a query with a stricter budget that is supposed to raise an exception.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/120050]