Skip to content

[Bug]: CTAS rejects constant percentile_cont and percentile_disc arguments #28631

Closed

Description

@Ariznawlll

Problem

On latest main (9a07655c54efdd1b5d24f801f701602b7231d013), exact ordered-set percentile aggregates accept a literal percentile in a direct SELECT and in INSERT ... SELECT, but the same query inside CREATE TABLE ... AS SELECT is rejected as though the literal were not constant.

Reproduction

DROP DATABASE IF EXISTS ctas_percentile_regression;
CREATE DATABASE ctas_percentile_regression;
USE ctas_percentile_regression;

CREATE TABLE src(g INT, v INT);
INSERT INTO src VALUES (1,1),(1,2),(1,3),(1,4);

-- Valid control: returns 1, 2.5.
SELECT g, percentile_cont(0.5) WITHIN GROUP (ORDER BY v) AS p
FROM src GROUP BY g;

-- Invalid result: ERROR 20301, even though 0.5 is a literal constant.
CREATE TABLE ctas_cont AS
SELECT g, percentile_cont(0.5) WITHIN GROUP (ORDER BY v) AS p
FROM src GROUP BY g;

-- The discrete variant has the same problem.
CREATE TABLE ctas_disc AS
SELECT g, percentile_disc(0.5) WITHIN GROUP (ORDER BY v) AS p
FROM src GROUP BY g;

-- Valid control: materializing through INSERT ... SELECT works.
CREATE TABLE insert_cont(g INT, p DOUBLE);
INSERT INTO insert_cont
SELECT g, percentile_cont(0.5) WITHIN GROUP (ORDER BY v)
FROM src GROUP BY g;
SELECT * FROM insert_cont;

Actual result

Both CTAS statements return:

ERROR 20301 (HY000): invalid input: percentile argument of percentile_cont/percentile_disc must be a constant

The percentile_cont CTAS reproduction was repeated three times and returned the same error each time.

Expected result

CTAS should accept the same literal percentile expression as direct SELECT and INSERT ... SELECT, create the table, and materialize the ordered-set aggregate result.

Scope and controls

  • A direct SELECT returns 2.5 for percentile_cont(0.5).
  • Pre-created-table INSERT ... SELECT materializes 2.5.
  • median(v) in CTAS succeeds.
  • Both percentile_cont and percentile_disc are affected.
  • The failure occurs while CTAS executes its generated follow-up query. The stack reaches compile.constructAggregateConfig from compile.populateCreatedTable; this suggests the CTAS reparse/lowering path no longer presents the direct percentile argument as a constant.

Impact

Queries using exact percentile aggregates cannot be materialized with CTAS even though the aggregate expression itself is valid and executable through other statement forms.

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added theissue type on Sep 10, 2026
  3. self-assigned this
    on Sep 10, 2026
  4. Ariznawlll commented on Sep 12, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新官方 main efb2c5084957ac90273a3f625668fc6a784562c4 验证。

    • 原始场景:CREATE TABLE AS SELECT 中 percentile_cont(0.5) 与 percentile_disc(0.5) 常量参数均可成功执行。
    • Happy path:四行 10/20/30/40 的 CTAS 结果分别为 25.0 与 20,落表后可正常读取。
    • 边界控制:同一库内的表达式默认值异常引用会被拒绝且不留下表;会话与清理流程正常。
    • 自动化:已加入 MOTR PR (aoe)[daily-update]: correct the memory node size #165,issue_28247_28631_ddl;三轮复跑 12/12 case、252/252 statements 一致通过。

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/optimizerkind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions