Repository navigation
Description
Is there an existing issue for the same feature request?
- I have checked the existing issues.
Is your feature request related to a problem?
When building NL-to-SQL analytics on MatrixOne for a real-world POC (toll-plaza monitoring, 1000-question stress test), arbitrary-percentile queries are very common ("95th-percentile gate processing time yesterday", "P99 wait minutes per plaza", etc.).
MatrixOne has a native MEDIAN() which is great for P50 only. For any other percentile the user / LLM has to hand-roll a ROW_NUMBER() OVER (ORDER BY x) / COUNT(*) OVER () workaround, which is:
- error-prone (LLMs frequently write subtly wrong versions — observed in 100% of P95 attempts during our stress test),
- slow on large fact tables,
- and unfamiliar to users coming from PostgreSQL / Snowflake / Oracle / Spark / DuckDB, all of which support
PERCENTILE_CONT(p) WITHIN GROUP (ORDER BY col)as a standard ordered-set aggregate.
Describe the feature you'd like
Implement the two SQL-standard ordered-set aggregates:
PERCENTILE_CONT(p) WITHIN GROUP (ORDER BY expr)— continuous percentile (linear interpolation between adjacent values).PERCENTILE_DISC(p) WITHIN GROUP (ORDER BY expr)— discrete percentile (the smallest value with cumulative distribution ≥ p).
Both should be usable as scalar aggregates and (ideally later) as window functions via WITHIN GROUP over partitions.
```sql
-- desired
SELECT plaza_id,
PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY gate_processing_sec) AS p95_sec
FROM toll_transactions
WHERE transaction_datetime >= NOW() - INTERVAL 1 HOUR
GROUP BY plaza_id;
```
Describe implementation you've considered
PostgreSQL's implementation is a good reference — they treat these as ordered-set aggregates with the special WITHIN GROUP (ORDER BY …) clause. Internally a sorted run of the input column is materialized per group; for CONT the position is interpolated, for DISC the value at the ceiling position is returned.
A pragmatic shortcut for the MVP could be to support only the non-window scalar form first, since that's the form 99% of NL2SQL output uses. Window-partitioned variants can come later.
Documentation, Adoption, Use Case, Migration Strategy
Any analytics tool that emits MySQL/PostgreSQL-flavored SQL (Looker, Metabase, Superset, Tableau live-query, LangChain SQL agents, custom NL2SQL pipelines) generates these aggregates routinely. Without native support, integrators have to special-case MatrixOne in their dialect rules — which is what we ended up doing in our LLM system prompt for this POC.
Additional information
Reproduction on `8.0.30-OmniFabric-v4.0.0-rc2` (commit `e0a8185`):
```
mysql> SELECT PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY gate_processing_sec) FROM toll_transactions LIMIT 1;
ERROR 1064 (HY000): SQL parser error: syntax error at line 1 column 43 near " (ORDER BY gate_processing_sec) ..."
mysql> SELECT PERCENTILE_CONT(0.95) FROM toll_transactions LIMIT 1;
ERROR 20105 (HY000): not supported: function or operator 'percentile_cont'
mysql> SELECT PERCENTILE_DISC(0.95) WITHIN GROUP (ORDER BY gate_processing_sec) FROM toll_transactions LIMIT 1;
ERROR 1064 (HY000): SQL parser error: ...
```
Observed in a 1000-question NL2SQL stress test as the only LLM failure that was directly caused by a missing MatrixOne function — every other failure was generic SQL hygiene or a model-side issue.
Activity
fengttt commentedon Jun 26, 2026
Dup #24550
add within group (#26781)
6 remaining items
add within group (matrixorigin#26781)
add within group (matrixorigin#26781)
add within group (matrixorigin#26781)
feat: support ordered-set aggregate windows (#29106)
slyunnn commentedon Sep 21, 2026
@daviszhen 请确认 PCT-R024 的最终 NaN 排序合同。
PCT-R024 NaN ordering test status
Feature: #25144. Test design: MatrixOne Ordered-Set Percentile 测试设计. The R024 expectation is ASC NaN before ordinary numeric values and DESC NaN after them; a NaN continuous-percentile endpoint returns NaN.
Previous 3-CN evidence:
9a07655c54efdd1b5d24f801f701602b7231d013passed the NaN assertion in TKE 35504840643; other assertions in that run failed independently.7f9505e7b8eb4ba45264114a76e3145f6fa26c7aand370c310a994de258ee01e87c31062590a7022f34returned ASC p=0 as -Inf and DESC p=0 as +Inf in TKE 35496856957 and TKE 35498299316.2026-10-29 local follow-up
On MatrixOne main
652a8ec6d0ea8999d2fe45b4cb28b67f8c4f2430, an isolated 1-CN SQL test used NaN, -Inf and +Inf constructed from their DOUBLE bit patterns, together with -1, 0 and 1. For(CONT ASC p0, DISC ASC p0, DISC ASC p1, DISC DESC p0, DISC DESC p1):(NaN, NaN, +Inf, +Inf, NaN).(-Inf, -Inf, NaN, +Inf, NaN). This result reproduced in the individual and combined runs.ORDER BY v ASCreturned[-Inf,-1,0,1,+Inf,NaN];ORDER BY v DESCreturned[+Inf,1,0,-1,-Inf,NaN].The result matches SQL float ordering described by PR #26956 and the expectation of the closed #28854, while R024 expects the opposite ASC NaN placement. The expected result has not been changed, and this discrepancy has not been submitted as a duplicate product bug. Please decide which contract should govern this feature; the local test does not establish a mixed-version or multi-CN result on this SHA.
slyunnn commentedon Nov 2, 2026
Feature verification for #25144 (Ordered-Set Percentile) (2026-11-02)
Test environment
Feature implementation: #26781, merge commit
f6889dd2a90077aa4fbe46e66ad91e02b36966cf. The merge commit is an ancestor ofmainatea184ad90624ae3dba8ced628ac019271a6c309c, verified on 2026-11-02 by GitHub's commit comparison;git fetch origin mainalso completed successfully. The local tests below used this frozen main commit.The evidence below comes from separate earlier executions on different MatrixOne commits, not one frozen release build. A common release binary SHA256 or image digest, build parameters, and complete deployment/resource fingerprint for all required cases have not been established.
Earlier SQL tests and the latest local follow-up ran against isolated MatrixOne services using a MySQL-protocol client. Cancellation tests ran on isolated TKE deployments with one or three CNs as specified below.
The latest local follow-up used an isolated one-CN, one-TN and one-LogService deployment on macOS arm64, Go 1.27.1.
git_version()returnedea184ad90624ae3dba8ced628ac019271a6c309c; themo-servicebinary SHA256 wase230970187d179a8d9f0947dd645818fb513b0db3daae69c39b26b80abc15067. Standard native build failed its completion-marker check; after building native libraries from the same source, the repository'sbuild-with-prebuilt-nativetarget produced the binary. Both build logs are retained locally.Test results
ea184ad90624ae3dba8ced628ac019271a6c309c, three individual scripts from MOTR #291 commitc83a873ef39127641b0c40c515caf2d1eb58793bpassed 23/23, 27/27 and 2/2 printed assertions; the MOTR runner subsequently passed all three serially with their checked-in expected outputs. This was not the complete MOTR suite.51e23b6c61fa471fa8ad569d14f9d9d9119748cdpassed individually and through the runner on the same product commit. Its script blob matched GitHub; no same-named golden output was found. The existing ordered-percentile unit-test group passed 21/21 top-level tests and four remote-protocol unit tests passed; these do not prove target-specific multi-CN cleanup.1through5,p=0.95returned continuous4.8and discrete5on21991b38274208798e67e14d4b2dfc4743048572. This is not the original toll-transactions SQL with its original data.c0dd71c7b9d980969f96ef24e7a1bec086828a7cchecked NaN ordering and percentile results in memory and actual spill paths; the focused cases and their function group passed. The revised design uses NaN-last ordering in both directions. This does not prove multi-CN behavior on that commit.a54850983d9cddaacc97e38a84515ec724c937b7canceled an active spilling query withcontext canceled; the observed spill file descriptors closed and a subsequent health query succeeded. Query-specific mpool release was not observed directly.d24f446e1e94a58c329d422519f7aad621cdcd05canceled the active target statement and the subsequent health query succeeded. Its diagnostic record reports selection of three CNs and spill activity; the collected logs do not establish target-associated remote execution and exit on each involved CN or query-specific resource release. The successful workflow does not establish the full cancellation/cleanup requirement.Bugs
21991b38274208798e67e14d4b2dfc4743048572. NormalMergeGrouppreflight rejects the mismatch; SQL reachability and the direct internal API contract remain unconfirmed. The issue is open.ea184ad90624ae3dba8ced628ac019271a6c309c.Regression coverage
0b8a4a190679e76826a6eb4bb9e55fc82176a4cbwas used in the three-CN run above. A real spilling workload is relevant to the feature; generic two-hour soak and large-scale performance matrices are not required by the revised necessary-scope design.Evidence and not covered
ea184ad90624ae3dba8ced628ac019271a6c309cand script9038822138c3e114e80c7a0265d42831b1523c47. The three-CN SQL preflight passed, but the baseline step failed because the service reports the short revisionea184adwhile the script required the full SHA. This was a test-script validation failure; the 10M fixture was not loaded, and the run-owned cluster, bucketclaim and namespace were cleaned up. The artifact contains the original results. The corrected image-version check subsequently passed on TKE as described below.ea184ad90624ae3dba8ced628ac019271a6c309cusing script492738a96814a20d51a269d7a82adc6769ec080a. The built image and actual CN, DN and Log pod image IDs had digestsha256:6542d4fb89990e5e9ef2735a21bddd2abd516abea6bca1ebec7db0381797236e; SQL reported short revisionea184ad. The captured cluster-spec fingerprint is a custom canonical-JSON SHA256, not a Kubernetes deployment digest. This preflight did not run the cancellation workload.context canceled, but the observation script failed when the held-open session still showed the target SQL. It did not preserve the session-pool samples, so no mpool-release conclusion can be drawn. The run-owned database, cluster, bucketclaim and namespace were cleaned up. A script fix was locally tested and pushed in PR [Feature Request]: Make MO compatible to mysqldump #1888; the first focused follow-up stopped before loading the 10M fixture: the runtime-baseline script did not yet support TKE CN pods owned byCloneSet. Its run-owned cluster and namespace were cleaned up. In a subsequent follow-up, the cluster object was created but no Running Pods appeared for over 10 minutes; the run was canceled and the owned cluster and namespace were deleted. Its cause was not established. The bounded baseline-only environment probe did not reach SQL or load the fixture: scheduler events report insufficient CPU/memory, node affinity and taint constraints, and node groups at maximum size. The three Log pods remained Pending. The run-owned cluster and namespace were deleted; the baseline, cancellation mpool release and target-associated remote exit remain unverified.Conclusion
Blocked — the feature is merged and prior focused tests provide useful evidence, but the necessary release-baseline and cancellation/resource evidence is insufficient for a complete acceptance conclusion. The historical executions above must not be combined into a single all-passed run.
slyunnn commentedon Nov 3, 2026
Follow-up verification — 2026-11-03
Product baseline: MatrixOne main commit
ea184ad90624ae3dba8ced628ac019271a6c309c; test script commit7a300f6d09346e06791d90697327d13a2677fff3.1317 / context canceled. Its identified session pool recorded off-heap current bytes of 0 before, 2,555,904 while active, and 0 after cancellation; on-heap current bytes were 8 at each sample. Both observed spill file descriptors closed, and the subsequent health query passed. This demonstrates the sampled session pool on one CN, not all operator or remote allocations.1317 / context canceledand the subsequent health query passed. The target-filtered marker and before/after goroutine stacks show that one non-coordinator CN receiver handler was active and subsequently exited, with the same pod, container and process identity. Another remote CN emitted a marker but did not have a paired active/after witness. Therefore this is partial remote evidence; it does not establish that every remote fragment, child goroutine or allocation exited. Raw artifact.The remaining gap is complete target-associated remote execution and exit and resource cleanup evidence across the involved remote execution; the above observations should not be treated as proof of all remote/operator cleanup. The earlier overall conclusion is retained pending the remaining necessary evidence.
Follow-up run 41574808417 on script
ee1e793ea438453284d906a7e190fc3874382214recorded markers on both remote CNs and cancellation of the target; one handler was observed exiting after cancellation, while the other handler was absent already in the active snapshot. The stricter collector marked that latter witness unavailable and the job failed. This is an observation gap, not a demonstrated product failure. Owned resources were cleaned up. A revised collector separately records handlers absent before cancellation and requires at least one handler to exit afterward; it does not claim that all child work or allocations were cleaned up. The focused follow-up 41575688908 did not start SQL: TKE scheduling reported insufficient CPU/memory, node constraints and maxed node groups. The owned cluster and namespace were deleted. This is an environment failure; no product assertion was executed.Run 41587492692 on script
c0d8810ddbe2993082d39ef91ac87fab9ca6eebbagain stopped during TKE cluster setup: scheduler events report insufficient CPU and memory, node affinity/taint constraints, and node groups at maximum size. No SQL or 10M fixture ran. The owned cluster and namespace were deleted. This is an environment capacity constraint, not a product test failure.2026-11-05: multi-CN cancellation follow-up
Run 42008949522 used MatrixOne
ea184ad90624ae3dba8ced628ac019271a6c309cand scriptc0d8810ddbe2993082d39ef91ac87fab9ca6eebb. The 10M-row fixture and three-CN environment were confirmed, and all product pod image digests matched the build digest. The target query returned1317 / context canceled; session reuse and the health query passed. Of the two identified remote handlers, one was already absent in the snapshot before cancellation, and one was observed active before cancellation and absent afterward, with unchanged pod/container/process identity. The test report marks acceptance as partial: receiver-handler observations alone do not establish that every remote child goroutine or allocation was released. The owned database, cluster, bucketclaim and namespace were cleaned up. Raw artifact.R050 remote resource evidence review
The target statement record from run 42008949522 reports
missing_fragments=1andmissing_memory_domains=1. The frozen source names remote compile poolscompile; the available pool report is not keyed by statement ID. Therefore neither the incomplete statement summary nor a process-wide pool sample can establish that this target's remote allocations and children were released. The observed handler exit remains valid for that handler and is not, by itself, proof of all descendant cleanup. There is no evidence here of a resource leak.For the necessary test scope, the observed multi-CN cancellation and subsequent health checks pass; the target-related handler observations are retained as direct evidence. Complete query-specific remote pool, registry and descendant cleanup remain partially verified because the relevant diagnostics are incomplete. Record this as an observability limitation rather than requiring another large-data run or asserting that every internal goroutine and allocation was released. Release acceptance of the remaining limitation is separate from the measured result; existing bug issues are tracked separately.
slyunnn commentedon Nov 6, 2026
Feature verification for #25144 (ordered-set percentile) (2026-11-06)
Test environment
f6889dd2a90077aa4fbe46e66ad91e02b36966cf. GitHub's commit comparison confirms that this commit is an ancestor of the local supplemental test target.maincommitb6c57d315c8d1df2aca40ab19dee72136e6f2f81(fix(disttae): preserve optimistic RC write dependencies across snapshot advances (#32174)). The running binary reportedb6c57d315c; its SHA256 wasdd8d7567b1ae6ff7bcd1742a674162fa00c5ccbee6206c33f4226114bafd1ec6. The local isolated deployment had one CN, one TN and one LogService; tests used PyMySQL over the MySQL protocol. The original build command for this existing binary was not independently recorded in this supplemental run.ea184ad90624ae3dba8ced628ac019271a6c309c. The TKE runs captured build image digestsha256:6542d4fb89990e5e9ef2735a21bddd2abd516abea6bca1ebec7db0381797236eand checked the product pod image IDs against that digest. Results below identify their execution round; they are not one run on a single SHA.Test results
b6c57d3, both percentile functions returned the expected results for the basic input; implicit and explicit ascending order agreed. A filtered grouped query withHAVINGand output ordering by the percentile alias returned the expected per-group results. AJOIN/CTE input and an equivalentUNION ALLinput preserved row multiplicity and returned the same expected aggregates. These are representative queries; the original issue's production table and SQL were not replayed verbatim.b6c57d3, single values, duplicates, empty and all-NULL inputs, NULL filtering, NULL percentile rejection, large integers, Infinity ordering and discrete endpoints, and Decimal64 values and result metadata passed targeted checks. Seeded tests varied input size, NULLs, duplicates, groups, direction and percentile. A separate recheck of the archived 120 continuous results against the independent oracle found 120/120 identical binary64 bit patterns; discrete results were also exact.ea184adpassed prepared-parameter reuse and rejection checks, partitioned window checks, Decimal128/256 boundaries, supported and rejected order types, and NaN/Infinity cases including forced spill. Protocol gating and aggregation-state behavior were exercised by focused implementation-layer tests; these unit tests are not a mixed-version deployment test.1317 / context canceled; its observed session pool off-heap bytes returned from2,555,904while active to0afterward, two observed spill file descriptors closed, and the health query passed. In the three-CN TKE run, the target was canceled and the subsequent health and session-reuse checks passed. One target-associated remote handler was observed active and then absent; another was already absent before cancellation. This does not prove cleanup of every remote child or allocation. The runtime observations and their limitations are detailed in the follow-up evidence.Bugs
MergeAPI. The normal preflight rejects the mismatch; a SQL-reachable panic or production impact has not been demonstrated. The issue remains open and is tracked separately.Regression coverage
Evidence and not covered
Conclusion
Passed for the tested core ordered-set percentile functionality, with the internal Merge issue tracked separately and the remote resource-observation limitation stated above. This conclusion is limited to the explicitly described executions and does not claim that all tests ran on one release build, that every internal path passed, or that the open Nightly PRs have merged.