[Bug] Split Update silently skips BEFORE UPDATE triggers on a leaf partition

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

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start by locating the existing check that rejects Split Update on relations with UPDATE triggers, then trace how it handles partition leaves during partial partition expansion. Use the reproduction SQL in the issue on a three-segment cluster and verify the statement either fails clearly before changing data or applies the trigger to all 20 rows. The issue does not name source files or tests, so finding the check and its regression test will require reading around the planner and executor code.

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

描述

type: Bug
Apache Cloudberry version

Reported on PR #2374, commit 482abcb657191a4cb2c53bc5c85eebc6f6df3760, with the PostgreSQL planner and assertions enabled, on a three-segment cluster.

What happened

After partial partition expansion, updating a partition key produces a Split Update plan. A BEFORE UPDATE trigger defined on the second leaf partition is silently skipped: the statement succeeds and updates 20 rows, but the trigger's assignment is not applied.

In the PR discussion, the author in PR referred to the Greenplum documentation stating that user-defined triggers are unsupported. This issue tracks the silent acceptance of an unsupported operation: Cloudberry already has a check intended to reject split updates on relations with UPDATE triggers, but this case bypasses it.

What you think should happen instead

No response

How to reproduce

Run on a cluster with three primary segments:

SET optimizer = off;

CREATE EXTENSION IF NOT EXISTS gp_debug_numsegments;
SELECT gp_debug_set_create_table_default_numsegments(2);

CREATE TABLE tr (a int, b int, c int)
DISTRIBUTED BY (a)
PARTITION BY RANGE (b);

CREATE TABLE tr1 PARTITION OF tr
FOR VALUES FROM (0) TO (10);

CREATE TABLE tr2 PARTITION OF tr
FOR VALUES FROM (10) TO (20);

INSERT INTO tr
SELECT i, 15, 0 FROM generate_series(1, 20) i;

CREATE FUNCTION tr_before() RETURNS trigger AS $$
BEGIN
    NEW.c := 999;
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER tr_before
BEFORE UPDATE ON tr2
FOR EACH ROW EXECUTE FUNCTION tr_before();

ALTER TABLE tr EXPAND PARTITION PREPARE;
ALTER TABLE tr1 SET WITH (REORGANIZE = TRUE) DISTRIBUTED BY (a);

EXPLAIN (COSTS OFF) UPDATE tr SET b = b + 1;
UPDATE tr SET b = b + 1;

SELECT b, c, count(*)
FROM tr
GROUP BY b, c
ORDER BY b, c;

Actual output

The following output is taken from the original PR report.

                          QUERY PLAN
---------------------------------------------------------------
 Update on tr
   Update on tr1 tr_1
   Update on tr2 tr_2
   ->  Explicit Redistribute Motion 3:3  (slice1; segments: 3)
         ->  Split Update
               ->  Append
                     ->  Seq Scan on tr1 tr_1
                     ->  Seq Scan on tr2 tr_2
 Optimizer: Postgres query optimizer
(9 rows)

UPDATE 20

 b  | c | count
----+---+-------
 16 | 0 |    20
(1 row)

If UPDATE triggers are unsupported for this execution path, reject the statement with a clear error before modifying data. The restriction should apply consistently to all affected leaf partitions.

If the statement is allowed, the trigger must execute, producing b = 16, c = 999 for all 20 rows. Successful execution with the trigger silently skipped should not occur.

Operating System

any

Are you willing to submit PR?
  • Yes, I am willing to submit a PR!
Code of Conduct
主要语言
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 摘要。