matrixorigin / matrixorigin/matrixone
[Enhancement]: Extend proven single-row aggregate laws beyond the initial family
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 311
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 768
Description
## Summary
Extend proof-gated aggregate elimination after uniqueness has established that every output group contains one row. The initial #27850 family is deliberately narrow; additional aggregate/configuration forms should be admitted only with an explicit single-row value, type, metadata and error contract.
## Candidate laws to evaluate
For one non-NULL input row, candidates include:
- DISTINCT variants of COUNT/SUM/AVG/MIN/MAX, because DISTINCT cannot remove the only value;
- BIT_AND/BIT_OR/BIT_XOR as the converted input value;
- population variance/stddev as zero and sample variance/stddev as NULL, subject to exact engine type/rounding contracts;
- GROUP_CONCAT of one value, including separator, ordering, collation and `group_concat_max_len` behavior;
- JSON/array/object aggregates with exactly one element, including NULL and duplicate-key behavior;
- configured/ordered aggregates whose configuration is provably irrelevant for one row.
This list is investigative, not automatic eligibility. Unsupported functions must fail closed.
## Required capability contract
Each aggregate overload should expose or register a planner-visible single-row law containing:
- accepted overload/function identity, including DISTINCT/config flags;
- result expression for NULL and non-NULL input;
- exact result type, width, scale, collation and nullability;
- proof that any cast/conversion is total over the complete source domain;
- error, truncation, warning and session-variable behavior;
- volatility/evaluation-count requirements;
- whether the law remains valid for prepared/reused execution.
Avoid a growing switch that guesses semantics from aggregate names alone.
## Mandatory boundary cases
- empty input versus one-row grouped input; scalar aggregates must not be conflated with grouped aggregates;
- nullable and non-null arguments;
- Decimal64/128/256 precision and scale extrema, explicitly covering #27855;
- signed/unsigned maxima, NaN/Inf where supported;
- VARCHAR collation, CHAR padding, ENUM/SET, binary and temporal values;
- DISTINCT NULL behavior;
- GROUP_CONCAT length/session limits and JSON errors;
- mixed aggregate queries: one unsupported aggregate rejects the complete rewrite;
- HAVING/ORDER BY aliases and volatile expressions evaluated exactly once.
## Validation requirements
1. Differentially execute each candidate law against the established Aggregate path for values, metadata, warnings and error status.
2. Use property/boundary tables, not only ordinary small integers.
3. Add planner tests for exact overload/config admission and fail-closed mixed families.
4. Add public SQL BVT for every admitted family.
5. Measure planner/runtime impact and prove unsupported controls retain their plan.
6. Do not merge a law whose executor baseline is already wrong; track and fix the baseline defect separately, as with #27855.
## Related
- Initial single-row family: #27850
- DECIMAL AVG baseline bug: #27855
- Non-PK unique-key proof: #27856
- Constant ORDER BY/HAVING simplification: #27858
- Umbrella decision: #27730
Contributor guide
Assessment
This issue has not been assessed yet.