Skip to content

[Bug]: invalid percentile parameters expose compile stack traces to SQL clients #28870

Closed

Description

@Ariznawlll

Description

Invalid percentile arguments return internal Go stack frames and absolute source paths to the SQL client instead of a concise user-facing invalid-input error.

The query does not crash the CN, but its expected validation path is routed through panic recovery.

Environment

  • MatrixOne: latest official main, commit 07fdd4ae0f80f287b93fc4b525fd296d5617abc7
  • Deployment: local standalone launch (isolated Log/TN/CN ports and data directory)

Reproduction

create table t(x double);
insert into t values (10),(20),(30);

select approx_percentile(x,-1) from t;
select approx_percentile(x,cast('NaN' as double)) from t;
select percentile_cont(1.1) within group(order by x) from t;

Actual behavior

The client response begins with the correct validation message, then includes internal frames and build paths:

ERROR 20301 (HY000): invalid input: percentile argument of approx_percentile
must be finite and in [0,1], got -1:

github.com/matrixorigin/matrixone/pkg/sql/compile.constructAggregateConfig
    /private/tmp/matrixone-main-20260912/pkg/sql/compile/operator.go:1966
github.com/matrixorigin/matrixone/pkg/sql/compile.constructGroup
    /private/tmp/matrixone-main-20260912/pkg/sql/compile/operator.go:1899
...

Negative/above-one/NaN/Inf values reproduce the stack for APPROX_PERCENTILE; exact PERCENTILE_CONT/DISC uses the adjacent path and behaves the same. Reproduced in 3/3 runs.

Expected behavior

The SQL client should receive only the stable invalid-input message. Expected user input validation must not expose panic frames or server build paths.

Controls

  • valid p=0, 0.5, and 1 return correct minimum/median/maximum values;
  • NULL and nonconstant percentile arguments return concise validation errors without the same long stack;
  • the service remains available after each query.

Code-path analysis

constructAggregateConfig in pkg/sql/compile/operator.go validates percentile configuration, then calls panic(err) for ordinary invalid-input results from validation, constant evaluation, and config parsing. Compile panic recovery decorates the error with frames before returning it through the MySQL protocol. This is analogous to closed #26980, which fixed unsupported time-window units being logged/returned through compile panic rather than normal error flow.

Suggested regression coverage

  • below-zero, above-one, NaN, ±Inf, NULL, and nonconstant percentile arguments;
  • approximate and ordered-set percentile variants;
  • assert error code/message and absence of stack frames/source paths;
  • verify the CN remains healthy after repeated errors.

Duplicate search

Open and closed issues were searched for percentile stack traces, constructAggregateConfig, source paths in SQL errors, and compile panic validation. #26980 concerns time-window units, not percentile configuration.

Activity

  1. added this to the MO-202609 milestone on Sep 14, 2026
  2. added
    kind/bug
    on Sep 14, 2026
  3. added theissue type on Sep 14, 2026
  4. self-assigned this
    on Sep 14, 2026
  5. added a commit that references this issue on Sep 16, 2026
    8e90e41
  6. Ariznawlll commented on Sep 17, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:8e8e1998ef02b1f6233ddb1c2d3208f3b70d2d83
    • 部署:隔离的单 CN / 单 TN / 单 LogService 本地集群,通过 MySQL 协议执行。
    • 日期:2026-09-17

    原问题验证

    对 approx_percentile 和 percentile_cont 传入越界 percentile。均返回用户可读的 ERROR 20301,不再暴露内部错误;合法边界 0、0.5、1 分别返回 1、5、9。

    Happy Path 覆盖

    覆盖两个函数和 0/0.5/1 三个合法 percentile 边界。

    Unhappy Path 覆盖

    覆盖负数和大于 1 的 percentile;均验证为稳定的 20301 业务错误。

    白盒验证

    不适用:错误码、错误文本以及合法结果为该接口的可观察契约。

    回归测试

    已加入 MOTR PR #181:issue_28870_percentile_errors.test。本地连续 3 轮通过。

    测试证据

    motr --repeat 3 14_issue_regression.issue_28870_percentile_errors:3/3 通过,9 条 SQL/轮均成功。

    测试结论

    测试通过。

  7. added 2 commits that reference this issue on Sep 17, 2026
    a1b3447
    8e01061
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions