Repository navigation
Description
Is there an existing issue for the same bug?
- I searched for RIGHT DEDUP, query budget, and processLimitationSize. [Bug]: SF1000 seed order_line INSERT exhausts HashBuild memory budget #29497 concerns Cartesian cardinality underestimation; this additional defect is the existing resident-map guard ignoring the query cap, and remains after that estimate is fixed.
Branch Name
PR #29527, branch codex/issue29497 (based on main).
Commit ID
59b5b981447ddbdd589050c2181944970998b3e6.
Other Environment Information
Linux/amd64, one CN, Go 1.26.4, max_dop=2, join_spill_mem=0 (automatic), frontend processLimitationSize=67108864. The CN has substantially more memory than the query cap.
Actual Behavior
With accurate source statistics, the 1,200,000-row composite-primary-key seed INSERT selects RIGHT DEDUP and fails with error 3015: resource exhausted: hash build memory budget exceeded; reduce query width or concurrency, or increase processLimitationSize. The failed statement leaves zero rows and SELECT 1 succeeds. The equivalent no-primary-key INSERT succeeds.
With the same binary, actual data, SQL and budget, default unknown leaf estimates instead accumulate to 1e15, disable resident RIGHT DEDUP, and select ordinary hash-shuffle DEDUP. That path spills and inserts all rows. Success must not depend on statistical overestimation.
Expected Behavior
Existing RIGHT DEDUP map admission should honor the query's hard memory cap as well as configured row/byte spill thresholds. If its resident maps cannot fit, select the existing eligible ordinary DEDUP shuffle/spill path. Keep the small resident fast path when it fits; do not enlarge or bypass the runtime budget.
Steps to Reproduce
Start a fresh test-owned service with frontend processLimitationSize=67108864. Create/use a dedicated database, replace <database> below with its name, and run:
set max_dop=2;
set join_spill_mem=0;
create table n10(n int primary key);
insert into n10 values(0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table n100(n int primary key);
insert into n100 select a.n*10+b.n from n10 a cross join n10 b;
create table n1000(n int primary key);
insert into n1000 select a.n*10+b.n from n100 a cross join n10 b;
create table n3(n int primary key);
insert into n3 values(0),(1),(2);
create table nw(w int primary key);
insert into nw values(1),(2),(3),(4);
create table order_line (
ol_o_id int, ol_d_id int, ol_w_id int, ol_number int,
ol_i_id int, ol_supply_w_id int, ol_delivery_d datetime null,
ol_quantity int, ol_amount decimal(12,2), ol_dist_info varchar(32),
primary key(ol_w_id,ol_d_id,ol_o_id,ol_number)
);
select table_cnt from table_stats('<database>.nw','patch','{"table_cnt":4,"block_number":1,"accurate_object_number":1}') g;
select table_cnt from table_stats('<database>.n10','patch','{"table_cnt":10,"block_number":1,"accurate_object_number":1}') g;
select table_cnt from table_stats('<database>.n3','patch','{"table_cnt":3,"block_number":1,"accurate_object_number":1}') g;
select table_cnt from table_stats('<database>.n1000','patch','{"table_cnt":1000,"block_number":1,"accurate_object_number":1}') g;
select table_cnt from table_stats('<database>.order_line','patch','{"table_cnt":0,"block_number":1,"accurate_object_number":1}') g;
insert into order_line
select c2.n*1000+c1.n+1,d.n+1,w.w,l.n+1,
((c1.n*10+l.n)%100000)+1,w.w,NULL,5,
((c1.n+l.n)%500)+1,'dist_info'
from nw w cross join n10 d cross join n3 c2
cross join n1000 c1 cross join n10 l;
select count(*),sum(ol_o_id),sum(ol_i_id),sum(ol_amount) from order_line;
-- Expected: 1200000, 1800600000, 6000600000, 300600000.00For the nearest successful control, omit the statistics-patch statements; for the no-PK control omit the primary key. Actual data and the process budget remain unchanged.
Additional information
Root cause: disableMemoryUnsafeRightDedup computes the coexisting resident map bytes correctly, but its automatic budget is derived from CN memory; explicit thresholds similarly ignore Process.Lim.Size. GetExecutionResourceBudget uses that positive limit to narrow the actual query cap. Ordinary RIGHT DEDUP cannot spill the map of incoming keys. A six-case existing-fixture unit regression also demonstrates this gap in auto, row-threshold, byte-threshold and mixed lookup-only/ordinary map accounting, with exact-fit/no-override controls passing on the reported commit. Fix planned in #29527, within the existing planner guard and threshold owner.
Activity
Fix Cartesian DML memory planning and transient statistics reuse (#29527
Ariznawlll commentedon Oct 2, 2026
测试版本
maind50a2d475a406829f67127fef7b2ad4abc1c1d3d原问题验证
在上述 commit 运行 issue 对应的定向回归。RIGHT DEDUP admission 把 lookup-only/ordinary map 纳入同一 query memory limit,超预算会回退安全计划。
Happy Path 覆盖
覆盖预算内 right dedup 与准确统计。
Unhappy Path 覆盖
覆盖超预算、未知 cardinality、size overflow 和多 map 合并;均保守回退。
白盒验证
关联修复 #29527 已进入当前
main。直接执行并检查的定向测试为:pkg/sql/plan/right_dedup_memory_test.go的 query-limit、combined-map、unknown-cardinality tests。回归测试
本问题依赖内部故障注入、并发时序、catalog/optimizer 状态或多组件协议边界,无法由普通 SQL golden 稳定构造,因此不放入 MOTR;回归保留在 MatrixOne UT/BVT 层。对应定向测试在精确 commit 上通过,且未修改用户工作区。
测试证据
d50a2d475a406829f67127fef7b2ad4abc1c1d3dpkg/sql/plan/right_dedup_memory_test.go的 query-limit、combined-map、unknown-cardinality tests测试结论
测试通过。