Repository navigation
Closed
Description
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
SELECTreturns2.5forpercentile_cont(0.5). - Pre-created-table
INSERT ... SELECTmaterializes2.5. median(v)in CTAS succeeds.- Both
percentile_contandpercentile_discare affected. - The failure occurs while CTAS executes its generated follow-up query. The stack reaches
compile.constructAggregateConfigfromcompile.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
fix: allow constant percentiles in CTAS (#28728)
Ariznawlll commentedon Sep 12, 2026
已在最新官方 main
efb2c5084957ac90273a3f625668fc6a784562c4验证。CREATE TABLE AS SELECT中percentile_cont(0.5)与percentile_disc(0.5)常量参数均可成功执行。10/20/30/40的 CTAS 结果分别为25.0与20,落表后可正常读取。issue_28247_28631_ddl;三轮复跑 12/12 case、252/252 statements 一致通过。测试通过。
fix: allow constant percentiles in CTAS (matrixorigin#28728)
fix: allow constant percentiles in CTAS (matrixorigin#28728)
fix: allow constant percentiles in CTAS (matrixorigin#28728)