feat(sql): add dynamic window support in WINDOW JOIN#6859
Merged
bluestreak01 merged 22 commits intomasterfrom Mar 17, 2026
Merged
feat(sql): add dynamic window support in WINDOW JOIN#6859bluestreak01 merged 22 commits intomasterfrom
bluestreak01 merged 22 commits intomasterfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
… into puzpuzpuz_dynamic_window_join
Store per-worker window function lists in local variables before passing them to the AsyncWindowJoinRecordCursorFactory constructor. This prevents a resource leak if a later constructor argument compilation throws, since the catch block can now free them. Also add setDynamicLo(true)/setDynamicHi(true) to MutableModelsTest.testWindowJoinContextClear() so the test will catch a regression if clear() stops resetting these fields. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
bluestreak01
previously approved these changes
Mar 16, 2026
If functionParser.parseFunction() throws mid-loop, previously created Function objects in the local workerFunctions list were leaked because the list was never returned to the caller. The catch block in generateJoins could not free them since the assignment to perWorkerWindowLoFuncs/perWorkerWindowHiFuncs never completed. Wrap the loop in a try-catch that frees the partial list on failure. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
[PR Coverage check]😍 pass : 1055 / 1441 (73.21%) file detail
|
bluestreak01
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WINDOW JOIN now accepts column references and expressions as RANGE BETWEEN boundaries, in addition to static constants. This allows each left-hand-side (LHS) row to define its own window size based on its data.
Example:
Either or both of the lo/hi boundaries can be dynamic. The other can remain a static constant.
Boundary expressions must evaluate to an integer and must only reference LHS table columns. Negative values are clamped to zero (equivalent to CURRENT ROW). NULL values produce NULL aggregates — the row is skipped.
Each boundary, whether static or dynamic, can optionally include a time unit suffix (
seconds,minutes,hours, etc.). When a time unit is present, the value is scaled to the LHS table's timestamp resolution at runtime (microseconds or nanoseconds). When the time unit is omitted, the raw integer value is interpreted in the LHS table's native timestamp resolution.Dynamic windows disable the fast (symbol-keyed) and vectorized execution paths. Queries with an ON key equality clause fall back to the general path with a join filter instead.
Also, makes parallel HORIZON and WINDOW JOIN queries more responsive to query cancellation.
Technical details
SqlOptimiser.validateWindowJoinsusestryEvalNonNegativeLongConstantto distinguish static vs dynamic bounds. Column references and non-constant expressions fail to compile againstEmptyRecordMetadataand are classified as dynamic.resolveWindowJoinBoundColumnswalks the expression tree to strip LHS table prefixes and reject right-hand-side (RHS) table column references.SqlCodeGeneratorcompiles dynamic bound functions against LHS metadata, computes sign/timeUnit parameters, and creates per-worker function copies for thread-unsafe expressions viacompileWorkerFunctionsConditionally.AsyncWindowJoinRecordCursorFactoryimplements 6 new reducer methods for dynamic windows using a two-pass algorithm: the first pass computes overall RHS bounds across all LHS rows in a page frame, the second pass does per-row binary search within the pre-scanned data.computeEffectiveBoundevaluates the dynamic function per LHS row, handles NULL and negative clamping.WindowJoinRecordCursorFactory(single-threaded path) integratescomputeEffectiveBoundfor per-row bound computation.WindowJoinTimeFrameHelpersupports non-monotonic access patterns from dynamic windows via bookmark-based navigation.circuitBreakerparameter but only uses it for slot acquisition, never inside the per-row processing loops. When a single page frame contains many rows, the worker thread runs uninterruptibly until the entire frame is processed, making the query unresponsive to cancellation. The fix addscircuitBreaker.statefulThrowExceptionIfTripped()at the top of every master-row iteration loop in all four async factories, so that cancellation, timeout, and broken connection signals are detected promptly during heavy frame processing.Test plan
WindowJoinTimeFrameHelperbookmark logic