Repository navigation
feat(sql): add local sliding-window ranks mrank, cumrank, tmrank - #31020
Conversation
## What type of PR is this? - [ ] API-change - [ ] BUG - [ ] Improvement - [ ] Documentation - [x] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to matrixorigin#29947 ## What this PR does / why we need it: An alert often needs to ask how unusual the current observation is relative to the most recent observations. Partition-wide RANK changes with the entire history and cannot answer that local question, and a ROWS clause on RANK does not make it frame-local: the SQL ranking functions exposed by MatrixOne (`RANK`, `DENSE_RANK`, `PERCENT_RANK`, `ROW_NUMBER`) are all partition-wide by definition. This PR adds the three frame-local competition-rank operators requested in the issue, so the local question has a direct SQL spelling: - `mrank(v, N)`: 1-based ascending competition rank of the current non-NULL `v[j]` among the last N physical rows of the partition (frame `max(partStart(j), j-N+1) .. j`, ties share the rank, NULL values never rank), returning NULL when `v[j]` is NULL. - `cumrank(v)`: the same rank counted from the partition start through the current row. - `tmrank(v, INTERVAL n unit)`: the same rank over the trailing time window - RANGE-interval membership `[ts_j - D, ts_j]` including the current timestamp's peer group - intersected with the rows at or before the current row (`k <= j`), using the same window-interval grammar user RANGE frame bounds use (string spellings take MySQL's integral prefix, decimal magnitudes quantize to microseconds, prepared numeric values take MySQL's nearest-integer conversion). The declared business profile from the issue - `mrank(v, 3)` over its six-row fixture producing `NULL, 1, 2, 2, NULL, 1`, agreeing with the issue's own independent self-join control - is asserted end to end by the new BVT case. ### Root cause The capability has no owner in the engine: no frame-local ranking entry existed in the function catalog, the binder had no path that publishes the (moving) row-count or (time) interval width as window-function configuration, and the window operator had no kernel that ranks only within the current frame. Adding it requires three coordinated owners (catalog entry with exact shape checks, a binder path for each operator's width contract, and a window operator kernel with per-row frame access), which is why the change ships with the reviewed versioned design `docs/design/20261023-local-sliding-window-ranks.md` and tests at every layer. ### What changed - Parser (`pkg/sql/parsers/dialect/mysql`): new non-reserved window tokens `MRANK`, `CUMRANK`, `TMRANK` and grammar productions `MRANK '(' expression ',' expression ')' window_spec`, `CUMRANK '(' expression ')' window_spec`, `TMRANK '(' expression ',' interval-shaped expression ')' window_spec`; table/column/alias identifiers named `mrank`/`cumrank`/`tmrank` keep parsing. - Catalog (`pkg/sql/plan/function`): function IDs 605-607 and window-function entries with exact shape checks - `mrank` exactly (numeric-or-temporal value, integer width), `cumrank` exactly (value), `tmrank` only the internal three-argument (value, count, unit) shape the binder's conversion case publishes. Non-integer ordinary widths (1.5, strings) keep the ordinary bind rejection, mirroring NTILE's bucket count. - Binder (`pkg/sql/plan`): `tmrank`'s public `INTERVAL n unit` width is converted through the window frame-bound interval grammar (`bindTmRankWidthArgument`); control functions, non-foldable and indirect prepared width sources are refused before evaluation by the shared admission boundary (matrixorigin#28985 pattern); statement-constant width validation runs per execution before sources start, independently of row production (`ValidateIntervalFrameBounds` extension), including PREPAREd widths over empty input and under LIMIT 0; a bare prepared `mrank` width marker binds in the integer domain (NTILE parity) so `PREPARE ... mrank(v, ?) OVER (...)` succeeds and every EXECUTE is re-resolved against the fill's own domain; prepared `tmrank` magnitudes retain the raw (source, unit) pair and re-materialize per execution. - Plan rules: `visit_plan_rule.go` re-materializes prepared width sources with their runtime domain; `deepcopy.go` carries the new published expressions. - Operator (`pkg/sql/colexec/window`): new `local_rank.go` kernel - 1-based ascending competition rank over every catalog-admitted numeric/temporal value domain (including YEAR storage and DECIMAL256), a uint64-safe width reader (a width above the partition simply covers it), the trailing `k <= j` cut, NULL current values returning NULL, and scan-level cancellation; `window.go` resolves tmrank membership at partition-stable bounds through a civil-order index reused by every row of a partition generation (with a generation-scoped cache clear); `interval.go` owns tmrank's width materialization and its overflow validation. - Tests: grammar/error-shape tests (`window_local_rank_parser_test.go`), registry pin (`function_id_test.go`), bind tests (`window_local_rank_bind_test.go` including the prepared-width contracts), kernel tests (`local_rank_test.go`: fixtures and oracles, NULL bits, ties, partition resets, frame entry/exit, value domains, unsigned width boundaries, the DST-fold civil ordering, mid-scan cancellation, width-adapter typed conversions, plan immutability), and the BVT case `test/distributed/cases/window/window_local_rank.sql` (178 statements: the profile fixture and its self-join control, partitions, ties, NULL values and keys, value domains, unsigned widths, prepared mrank/tmrank ladders with overflow refusals and recovery, and a 40-hour-witness section separating the constant decimal width grammar from the prepared nearest-int reading). ### Issue-to-test proof - The issue's declared profile is asserted by the new BVT case: `mrank(v, 3)` over the six-row fixture returns `NULL, 1, 2, 2, NULL, 1`, exactly what the issue's independent self-join control produces, and the case also covers the issue's requested additions: partitions, ties, NULL-valued rows, frame entry/exit, value-type and width boundaries, and prepared execution. Named/API availability is validated separately from the mathematical rewrite (entry resolution, grammar rejections, the OVER-less probe). - Red/green on the same case: 178/178 statements pass (100%) with this change; the identical case fails 98/178 (44%) on the unmodified base binary, where every `mrank`/`cumrank`/`tmrank` statement rejects on the grammar or binds as an unsupported function - the case itself discriminates the fix. - Kernel-level oracles pin the semantics the SQL case cannot isolate: the `k <= j` trailing cut with a higher-valued first peer (a leaked later lower-valued peer would flip its rank), equal-value peers under any engine scan order, the DST-fold civil wall-clock membership, and the mutation check that scan-level cancellation actually aborts an active frame scan. ### Test commands ``` go test ./pkg/sql/parsers/dialect/mysql/ ./pkg/sql/plan/function/ ./pkg/sql/colexec/window/ ./pkg/sql/plan/ # ok for each owning package (plan: ok 233.9s, window: ok 21.3s on this change) # BVT single case (mo-tester, window directory): io.mo.Tester path=test/distributed/cases/window/ method=run rate=100 include=window_local_rank # with this change: TOTAL: 178, SUCCESS: 178, SUCCESS RATE: 100% # unmodified base binary: TOTAL: 178, SUCCESS: 80, FAILED: 98 ``` ### Residual risks - The neighboring nine window BVT files carry pre-existing drifted expectations (identical failure sets on the base binary and on this branch); they are untouched by this PR and remain for CI's expected-failure handling. Only `window_local_rank` differs between the two binaries. - The full distributed BVT tree and launched-cluster/distributed modes were not run locally; the branch's evidence is the owning-directory single case plus the owning Go packages, and CI covers the wider matrix. - The prepared-width typed conventions are pinned at three layers (bind-level fill, SQL EXECUTE, COM_STMT); the recorded refusal texts (`[DOUBLE DECIMAL64]`, `[DOUBLE VARCHAR]`, `[DOUBLE ANY]`, `invalid argument interval`) would change if the generic prepared re-resolution is ever unified - BVT expectations must then be regenerated deliberately. - Function-ID tail 605-608 is pinned by `Test_funids` and fails loudly if the registry rebase moves it.
|
CI status note for run 40063809240 — attempt 2 reached its terminal failure at 2026-10-24T05:57:13Z. The single authorized failed-jobs rerun (issued 05:48:41Z) reproduced the same infrastructure failure classes as attempt 1, this time entirely inside repository checkout: all three rerun producer jobs died fetching this PR's head
All failures are isolated from this PR's code: within the same run, The per-run failed-jobs rerun budget for run 40063809240 is consumed (attempt 2); no further rerun of this run is requested. The PR stays blocked on these documented runner-proxy infrastructure classes until a fresh CI attempt can reach a real verdict. Update 2026-10-24T07:15Z — fresh run on the unchanged head reproduced the same two checkout-failure classes. A new full MatrixOne ALL CI run, run 40072115909 (attempt 1, created 2026-10-24T06:55:35Z; head still
Within this same fresh run, Update 2026-10-24T07:37Z — run 40072115909: the UT Coverage lane concluded with the same silent-stall checkout timeout. Correction to the 07:15Z note above: the UT Coverage lane of run 40072115909 had already concluded by that time — Matrixone UT Coverage execution / UT Coverage on Ubuntu/x86 (job 120807679034, 06:56:38Z→07:06:16Z, runner Fleet-wide context: the same tracker and #28113/#31028 also recorded fresh occurrences of the same checkout-transport classes today on other PRs behind the same runner proxy (PR #30311 runs 40068065600 / 40072523092, and records from PRs #30973 / #30928), confirming a broad runner-proxy infrastructure outage isolated from all affected PRs' code. Run 40072115909 remains non-terminal at this update (both compose BVT lanes, started 07:05:31Z, still executing; the downstream Update 2026-10-24T07:57Z — run 40072115909 reached terminal state; rerun of its failed jobs issued. Run 40072115909 (attempt 1) concluded at 07:50:37Z with the same two checkout-transport failure classes and no code-verdict anywhere.
Since this run's attempt is 1 and every failed lane is one of the transient runner-proxy checkout classes tracked above, the single authorized failed-jobs rerun of run 40072115909 was issued at 2026-10-24T07:57:20Z; the run now shows attempt 2 / queued on the unchanged head. Its outcome will be evaluated as a new event when its checks complete. No source change is warranted for these failures and none was made. (Bookkeeping note: #27066, #28113 and #28411 have meanwhile been closed, but these entries stay in the marker below until a fresh attempt of this PR's reach verifies the classes as resolved — the classes recurred in this very run and the umbrella #31028 remains open.) Update 2026-10-24T08:15Z — run 40072115909 attempt 2: both reran producer lanes failed again in runner-proxy transport, before any code verdict; per-run rerun budget consumed. The failed-jobs rerun issued at 07:57:20Z (attempt 2, unchanged head
The reran Matrixone CI execution / SCA Test on Linux/arm64 lane (job 120819805601) was still executing at 08:15Z — past its attempt-1 checkout-failure duration, so checkout did not kill it this time; its outcome, and this run's terminal state, will be evaluated as a new event when the checks complete. The identical head remains proven fetchable, buildable, and testable by this run's retained attempt-1 successes ( Run 40072115909's single authorized failed-jobs rerun is consumed (attempt 2); no further rerun of this run is requested. Attempt-2 recurrence records for both classes were posted on the open umbrella #31028: record. Update 2026-10-24T09:14Z — run 40072115909 terminal: the reran SCA lane completed fully green (first static-analysis verdict on this head); every remaining failure is one of the two documented runner-proxy transport classes or its downstream gate; per-run rerun budget consumed. The run concluded at 09:01:49Z (attempt 2, unchanged head
Net for the run: no unit-test or coverage verdict for this PR's code exists in either attempt — both producers died in runner-proxy transport before any MatrixOne source was built, tested, or covered — while the completed verdicts (Shared Build, SCA, both compose BVT lanes, with this PR's Run 40072115909's single authorized failed-jobs rerun is consumed (attempt 2); no further rerun of this run is requested, and these failures justify no base update. Terminal record posted on the open umbrella #31028: record. The PR remains blocked on these runner-proxy infrastructure classes until a fresh CI attempt reaches a real UT/coverage verdict; the blocker marker below is unchanged because the checkout-transport and toolchain-download classes recurred in this very attempt. Update 2026-10-24T12:36Z — fresh run 40092867706 on the review-fix head Pushing the review-fix commit
Within this same run, Run 40092867706 remains non-terminal at this update (attempt 1; both compose BVT lanes started 12:21:03Z and are still executing; the downstream coverage merge and Update 2026-10-24T13:30Z — run 40092867706 reached terminal state at 13:07:55Z; the single authorized failed-jobs rerun was issued at 13:29:41Z. The first ALL CI run on the review-fix head
Positive verdicts on the identical head inside this terminal run: Since this run is attempt 1, terminal, and every failed lane is one of the documented transient transport classes, the single authorized failed-jobs rerun of run 40092867706 was issued at 2026-10-24T13:29:41Z ( Update 2026-10-24T13:50Z — run 40092867706 attempt 2: both completed producer lanes failed again in the same two runner-proxy transport classes, before any code verdict; per-run rerun budget consumed, run non-terminal. The failed-jobs rerun issued at 13:29:41Z (attempt 2, unchanged head
The reran The identical head The blocker marker below is unchanged — both classes recurred in this very attempt and the umbrella #31028 remains open; the Update 2026-10-24T14:10Z — run 40092867706 attempt 2 terminal (14:01:14Z): the last reran producer lane completed in the Go-toolchain download transport class; per-run rerun budget consumed, no further rerun requested. Completing the 13:50Z note — the reran UT lane, which was still executing then, finished as follows:
Net for run 40092867706 (attempt 1 + attempt 2, unchanged head Run 40092867706's single authorized failed-jobs rerun is consumed (attempt 2); no further rerun of this run is requested. The PR stays blocked on these documented runner-proxy infrastructure classes until a fresh CI attempt reaches a real UT/coverage/SCA verdict. The blocker marker below is unchanged — the checkout-transport and toolchain-download classes both recurred in this very attempt — and the Update 2026-10-24T15:28Z — merged-head run 40105630160: the UT Coverage producer died inside Context: the authorized base update merged main
The blocker marker below is unchanged — the runner-proxy transport classes recurred on this very head — and the Update 2026-10-24T15:42Z — run 40105630160: the UT producer died in the Go-toolchain download transport class, before any code verdict; run attempt 1 is still in progress at this update, so no rerun is issued. Completing the 15:28Z picture for merged-head run 40105630160 — its
The blocker marker below is unchanged — the toolchain-download class (and the coverage-lane action-archive class) recurred in this very attempt — and the Update 2026-10-24T16:19Z — run 40105630160: the Coverage merge gate failed as the pure downstream projection of this run's recorded UT Coverage producer transport death; run attempt 1 is still in progress (the SCA lane is executing normally), so no rerun is issued.
Update 2026-10-24T17:00Z — run 40105630160 reached terminal state at 16:40:09Z: the last lane, SCA arm64, was cancelled by an external action mid static-check (so no code verdict exists anywhere in the run); the single authorized failed-jobs rerun was issued at 16:55:31Z and is in progress as attempt 2.
Update 2026-10-24T17:30Z — run 40105630160 attempt 2: both reran producer lanes died again inside runner-proxy checkout transport, before any code verdict; the SCA lane is silent since 17:02:33Z keeping the run non-terminal; per-run rerun budget consumed, no further rerun requested. The failed-jobs rerun issued at 16:55:31Z (attempt 2, unchanged head
The identical head Run 40105630160's single authorized failed-jobs rerun is consumed (attempt 2); no further rerun of this run is requested. Attempt-2 recurrence record posted on the open umbrella #31028: record. The PR remains blocked on these documented runner-proxy transport classes until a fresh CI attempt can reach a real UT/coverage/SCA verdict. The blocker marker below is unchanged — both checkout-transport classes recurred in this very attempt — and the Update 2026-10-24T18:26Z — run 40105630160 attempt 2 reached terminal state at 18:09:26Z: the reran SCA lane completed fully green (first static-analysis verdict on the merged head
Net for run 40105630160 (attempt 1 + attempt 2, unchanged head Run 40105630160's single authorized failed-jobs rerun is consumed (attempt 2); no further rerun of this run is requested. The PR stays blocked on the checkout-transport classes until a fresh CI attempt reaches a real UT/coverage verdict (the missing-verdict list on this head is now only UT and UT coverage). Final-state addendum posted on the open umbrella #31028: record. The blocker marker below is unchanged — the checkout-transport classes recurred in this very attempt — and the Update 2026-10-24T19:0Z — run 40105630160 attempt 3 (reviewer-issued rerun, started 18:42:36Z): the UT Coverage producer passed checkout and then died in the Go-toolchain download silent-stall variant of the #27066 class; the Coverage merge gate is its pure downstream projection; the UT producer lane is still executing and the run is non-terminal. Attempt 3 of this run was issued by the reviewer (triggering_actor
Net: every attempt-3 conclusion so far is a documented runner-proxy transport class or its downstream gate, isolated from this PR's code; the identical head The blocker marker below is unchanged — the toolchain-download class recurred in this very attempt — and the Update 2026-10-24T19:50Z — run 40105630160 attempt 3 terminal (19:31:00Z): the reran UT producer completed fully green — the first unit-test verdict on the merged head
The blocker marker below is unchanged — the toolchain-download transport class recurred in this very attempt — and the |
Conflict-resolution merge with main, bringing in the technical-indicator window kernels (matrixorigin#31017) and thirteen other commits. Six files conflicted, every one an append-vs-append collision in the same window/registry area; both sides are kept: - pkg/sql/plan/function/function_id.go and function_id_test.go: main's indicator family (SMA..CUMPOSITIVESTREAK) had already claimed 605-615 with FUNCTION_END_NUMBER = 616, so the never-on-main rank IDs move to the next free block 616/617/618 with the sentinel at 619, following the file's own renumbered-on-main-merge precedent (ONNX_RUN/LOAD_TEXT); all rank references are by name, so the renumber is behavior-neutral. Registry uniqueness is re-pinned by predefinedFunids alongside main's indicator IDs. - pkg/sql/plan/function/list_window.go: both registration sets are kept (the indicator kernels, then MRANK/CUMRANK/TMRANK), plus both sides' helpers (checkIndicatorValueArgs/checkIndicatorStreakArgs and IsLocalRankValueDomain). - pkg/sql/colexec/window/window.go: both generation-scoped cleanups run at the same eval entry (clearCivilOrder and freeIndicatorState). - mysql_sql.y: both token lines and both window-function-name alternation sets merged; mysql_sql.go regenerated through the repository's zero-conflict Makefile gate. docs/design/20261023-local-sliding-window-ranks.md records the D8 merge application (IDs 605-607 -> 616-618) as post-approval bookkeeping in section 9, with the allocation statement, decision record and validation-map row updated to the 616-619 realization.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 136f2838488ad62db7f2622c4aa76c963459982a
Assessment: approve
Reviewed the complete delta and affected callers. The design reasonably extends the existing window operator while retaining authoritative interval normalization, prepared-parameter reconstruction and validation owners. The volatile-width admission defect and missing design approval record are resolved. No actionable findings remain.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Preflight passed; the repository provenance verifier qualified the retained native build against 192 matching current-source inputs.
-
52 top-level test invocations passed (51 distinct tests), including independent probes for descending order, row-dependent widths, TIME/NULL membership, output-chunk boundaries, constant values and error cleanup. Logs match receipts 1792875111466937956-4.json and 1792875137350061467-3.json.
-
Parser regeneration matched the committed parser after command/path normalization, with zero conflicts; receipt 1792875007272881771-4.json.
-
Reused the frozen exact-head CI snapshot reporting successful unit, coverage, static-analysis and compose BVT jobs. Earlier setup failures were distinguished from subsequent successes.
-
Command/source/exit receipts and retained log hashes were reconciled in review-evidence.json. Final audit passed with unchanged source; receipt 1792875319779847274-4.json. Artifacts: /home/xupeng/.local/state/mo-bot/jobs/a50c4d3514c7f1b907a83bfb/attempt-1.
Limitations:
-
No local SQL-server or full-suite rerun; broader validation relies on the supplied exact-head CI evidence. Author-only red/green claims were not counted as independently verified executions.
-
Quadratic CPU for cumulative or broad frames is an explicit accepted design tradeoff. No workload speedup or regression measurement was established; ordinary paths introduce no new I/O, locks or goroutines.
-
The linked issue's standalone body was not supplied; its contract was assessed from the frozen PR and versioned design.
Merge Queue Status
This pull request spent 1 hour 55 minutes 47 seconds in the queue, including 55 minutes 23 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
Related to #29947
What this PR does / why we need it:
An alert often needs to ask how unusual the current observation is relative to
the most recent observations. Partition-wide RANK changes with the entire
history and cannot answer that local question, and a ROWS clause on RANK does
not make it frame-local: the SQL ranking functions exposed by MatrixOne
(
RANK,DENSE_RANK,PERCENT_RANK,ROW_NUMBER) are all partition-wide bydefinition. This PR adds the three frame-local competition-rank operators
requested in the issue, so the local question has a direct SQL spelling:
mrank(v, N): 1-based ascending competition rank of the current non-NULLv[j]among the last N physical rows of the partition (framemax(partStart(j), j-N+1) .. j, ties share the rank, NULL values neverrank), returning NULL when
v[j]is NULL.cumrank(v): the same rank counted from the partition start through thecurrent row.
tmrank(v, INTERVAL n unit): the same rank over the trailing time window -RANGE-interval membership
[ts_j - D, ts_j]including the currenttimestamp's peer group - intersected with the rows at or before the current
row (
k <= j), using the same window-interval grammar user RANGE framebounds use (string spellings take MySQL's integral prefix, decimal
magnitudes quantize to microseconds, prepared numeric values take MySQL's
nearest-integer conversion).
The declared business profile from the issue -
mrank(v, 3)over its six-rowfixture producing
NULL, 1, 2, 2, NULL, 1, agreeing with the issue's ownindependent self-join control - is asserted end to end by the new BVT case.
Root cause
The capability has no owner in the engine: no frame-local ranking entry
existed in the function catalog, the binder had no path that publishes the
(moving) row-count or (time) interval width as window-function configuration,
and the window operator had no kernel that ranks only within the current
frame. Adding it requires three coordinated owners (catalog entry with exact
shape checks, a binder path for each operator's width contract, and a window
operator kernel with per-row frame access), which is why the change ships with
the reviewed versioned design
docs/design/20261023-local-sliding-window-ranks.md(approved revision 8, file SHA-256
7bd5296382c677319455fc8fafc3ed63b4fdf3900e3ab36ff108f51f9ba52e76,design-review PASS completed 2026-10-23 - the traceable record is section 9
of that document) and tests at every layer.
What changed
pkg/sql/parsers/dialect/mysql): new non-reserved window tokensMRANK,CUMRANK,TMRANKand grammar productionsMRANK '(' expression ',' expression ')' window_spec,CUMRANK '(' expression ')' window_spec,TMRANK '(' expression ',' interval-shaped expression ')' window_spec;table/column/alias identifiers named
mrank/cumrank/tmrankkeep parsing.pkg/sql/plan/function): function IDs 616-618 (renumbered from thedrafted 605-607 when main's technical-indicator kernels feat: technical-indicator window kernels and rolling risk analytics #31017 claimed that
block across the 2026-10-24 conflict-resolution merge; every rank reference
is by name) and window-function
entries with exact shape checks -
mrankexactly (numeric-or-temporal value,integer width),
cumrankexactly (value),tmrankonly the internalthree-argument (value, count, unit) shape the binder's conversion case
publishes. Non-integer ordinary widths (1.5, strings) keep the ordinary bind
rejection, mirroring NTILE's bucket count.
pkg/sql/plan):tmrank's publicINTERVAL n unitwidth isconverted through the window frame-bound interval grammar
(
bindTmRankWidthArgument); control functions, non-foldable, indirect-preparedand volatile/effectful width sources (
INTERVAL RAND() DAY,INTERVAL SLEEP(0) DAY,INTERVAL (1 + RAND()) DAYin all spellings) are refusedbefore evaluation by the shared admission boundary ([Bug] CI BVT fulltext2_copy_alter misses expected rows #28985 pattern): the
tier-2 walk admits only the resolver's fold-switch operators over admitted
spines plus functions the registry positively proves pure
(
function.GetFunctionIsProvenPureFoldableById, the same guarded-fold ruleisGeometrySRIDConstFoldSafeuses), so nothing nondeterministic orside-effectful is ever eagerly evaluated at bind time; statement-constant width validation runs per
execution before sources start, independently of row production
(
ValidateIntervalFrameBoundsextension), including PREPAREd widths overempty input and under LIMIT 0; a bare prepared
mrankwidth marker binds inthe integer domain (NTILE parity) so
PREPARE ... mrank(v, ?) OVER (...)succeeds and every EXECUTE is re-resolved against the fill's own domain;
prepared
tmrankmagnitudes retain the raw (source, unit) pair andre-materialize per execution.
visit_plan_rule.gore-materializes prepared width sources withtheir runtime domain;
deepcopy.gocarries the new published expressions.pkg/sql/colexec/window): newlocal_rank.gokernel - 1-basedascending competition rank over every catalog-admitted numeric/temporal value
domain (including YEAR storage and DECIMAL256), a uint64-safe width reader
(a width above the partition simply covers it), the trailing
k <= jcut,NULL current values returning NULL, and scan-level cancellation;
window.goresolves tmrank membership at partition-stable bounds through a civil-order
index reused by every row of a partition generation (with a generation-scoped
cache clear);
interval.goowns tmrank's width materialization and itsoverflow validation.
(
window_local_rank_parser_test.go), registry pin(
function_id_test.go), bind tests (window_local_rank_bind_test.goincluding the prepared-width contracts), kernel tests
(
local_rank_test.go: fixtures and oracles, NULL bits, ties, partitionresets, frame entry/exit, value domains, unsigned width boundaries, the
DST-fold civil ordering, mid-scan cancellation, width-adapter typed
conversions, plan immutability), bind-level volatile-width
admission rejections (rand/sleep direct, sleep under an admitted arithmetic
spine, the nil-proc pre-evaluation refusal proofs), and the BVT case
test/distributed/cases/window/window_local_rank.sql(181 statements: theprofile fixture and its self-join control, partitions, ties, NULL values and
keys, value domains, unsigned widths, prepared mrank/tmrank ladders with
overflow refusals and recovery, a 40-hour-witness section separating the
constant decimal width grammar from the prepared nearest-int reading, and
the public volatile-width refusals for rand/sleep, direct and nested).
Branch maintenance (2026-10-24)
mainadvanced into this PR's window/registry area with thetechnical-indicator kernels (#31017), making the branch conflicting. The
conflict-resolution merge keeps both sides: the eleven indicator
registrations (SMA..CUMPOSITIVESTREAK, IDs 605-615) and the three rank
registrations (MRANK/CUMRANK/TMRANK, IDs 616-618, sentinel 619 - the
drafted 605-607 block was claimed on main first and was never in any
release; all rank references are by name, so the ordered renumber is
behavior-neutral per the registry's own ONNX_RUN/LOAD_TEXT merge
precedent); both generation-scoped executor cleanups at the same eval
entry; both grammar token/alternation sets, with
mysql_sql.goregenerated through the repository's zero-conflict gate. The merged
package suites stay green (parsers, function registry, plan,
window - the last running both this kernel and the indicator kernels).
The design document's section 9 records the ID renumber as
post-approval bookkeeping (D8's first-free-numbers decision applied to
the merged base). No public SQL surface changed.
Issue-to-test proof
mrank(v, 3)over the six-row fixture returnsNULL, 1, 2, 2, NULL, 1,exactly what the issue's independent self-join control produces, and the
case also covers the issue's requested additions: partitions, ties,
NULL-valued rows, frame entry/exit, value-type and width boundaries, and
prepared execution. Named/API availability is validated separately from the
mathematical rewrite (entry resolution, grammar rejections, the OVER-less
probe).
the identical case fails 101/181 on the unmodified base binary, where
every
mrank/cumrank/tmrankstatement rejects on the grammar or bindsas an unsupported function - the case itself discriminates the fix.
admission tests fail on the pre-fix walker (rand/sleep/nested-rand widths
published as literal count/unit pairs) and pass with the fix, including the
nil-proc refusal proofs that no eager evaluation runs before the admission
decision.
k <= jtrailing cut with a higher-valued first peer (a leaked laterlower-valued peer would flip its rank), equal-value peers under any engine
scan order, the DST-fold civil wall-clock membership, and the mutation check
that scan-level cancellation actually aborts an active frame scan.
Test commands
Residual risks
(identical failure sets on the base binary and on this branch); they are
untouched by this PR and remain for CI's expected-failure handling. Only
window_local_rankdiffers between the two binaries.not run locally; the branch's evidence is the owning-directory single case
plus the owning Go packages, and CI covers the wider matrix.
fill, SQL EXECUTE, COM_STMT); the recorded refusal texts (
[DOUBLE DECIMAL64],[DOUBLE VARCHAR],[DOUBLE ANY],invalid argument interval)would change if the generic prepared re-resolution is ever unified - BVT
expectations must then be regenerated deliberately.
Test_funids(renumbered from thedrafted 605-608 when main's feat: technical-indicator window kernels and rolling risk analytics #31017 claimed 605-615 across the merge) and
fails loudly if a later registry rebase moves it again.