[Bug] Window Sort above ROLLUP gets a larger memory quota and runs slower after "Reserve memory for one partition at a time"

未关闭
#2,446 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 2 天内回复

@Alena0704 已经在做这个了。

开始于 2026年11月30日。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
c, postgresql, sql

调研方向

Start by reading the memory quota change in #2035/#2216 and trace how Append branches and group roots contribute to operator memory limits. The issue identifies the window Sort above ROLLUP as the affected operator; inspect the relevant quota calculation and its tests. Done when memory-intensive operators sum concurrent branch memory while non-memory-intensive operators retain the largest-branch behavior, with the reported quota regression addressed.

由索引模型根据 Issue 内容生成。

描述

type: Bug
Apache Cloudberry version

main and REL_2_STABLE, after "Reserve memory for one partition at a time" (#2035 on REL_2_STABLE, #2216 on main).

What happened

With gp_resqueue_memory_policy = eager_free, the window Sort above a ROLLUP now gets about 2.2x the operatorMem it got before that commit, with the same statement_mem. When the sort spills anyway, the larger quota makes it slower: fewer but bigger in-memory runs, and a bigger last run sorted after all input has arrived.

ORCA turns ROLLUP into an Append of HashAggregates. The commit counts only the largest Append branch, so the window Sort's group counts 1 HashAggregate instead of all of them. But an Agg keeps its hash table until ExecEndAgg() and Append does not release finished branches, so these HashAggregates hold their memory at the same time. Counting one branch is right for the 100kB per partition scan, but not for memory-intensive operators.

TPC-DS 1TB Q67, 64 segments, same plan and settings:

before the commit after the commit
window Sort operatorMem 1532457kB 3320324kB
spilled 39152864kB 39152352kB
Q67 execution time 388 s 413 s
What you think should happen instead

Take the largest branch only for non-memory-intensive operators, and keep summing memory-intensive ones (including group roots counted in the parent group). That keeps the fix for many partitions and gives the window Sort its old quota back.

How to reproduce
create table seed (s int) distributed by (s);
insert into seed select generate_series(0, 63);
create table sales (cat int, a int, b int, c int, k int, amt numeric(12,2)) distributed by (k);
insert into sales
select k % 2, k / 1000, k / 100, k / 10, k, (k % 9973) / 100.0
from (select s * 1562500 + g as k from seed, generate_series(1, 1562500) g) x;  -- 100M rows
analyze sales;

set optimizer = on;
set statement_mem = '4GB';
set gp_resqueue_print_operator_memory_limits = on;
-- look at the Sort with "Sort Key: cat, (sum(amt)) DESC"
explain (costs off)
select count(*), max(rk)
from (select cat, k, s, rank() over (partition by cat order by s desc) rk
      from (select cat, a, b, c, k, sum(amt) s from sales group by rollup (cat, a, b, c, k)) t1) t2;

On 64 segments, the window Sort quota goes from 599086kB to 1397868kB, and the query from about 154 s to 167 s. With statement_mem = 1755MB the quota is back to 598806kB and the time to 157 s.

Operating System

Linux x86_64

Anything else

No response

Are you willing to submit PR?
  • Yes, I am willing to submit a PR!
主要语言
C
星标
1.5k
派生
280
平均合并
4 天 21 小时
30 天内合并 PR
122

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/cloudberry 的其他 Issue

查看 apache/cloudberry 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。