Fix EPQ crash from missing partition pruning state in EState
authorAmit Langote <amitlan@postgresql.org>
Fri, 19 Sep 2025 02:39:06 +0000 (11:39 +0900)
committerAmit Langote <amitlan@postgresql.org>
Fri, 19 Sep 2025 02:39:06 +0000 (11:39 +0900)
commit9a82a64edcd8615cf16eae64bf1572d4156cb912
tree48dc876bcdbe288d91cdf4c92efb34a6cc5a7a9e
parent144de0341bde9cab7a6b629a3d9041be54486d96
Fix EPQ crash from missing partition pruning state in EState

Commit bb3ec16e14 moved partition pruning metadata into PlannedStmt.
At executor startup this metadata is used to initialize the EState
fields es_part_prune_infos, es_part_prune_states, and
es_part_prune_results.  EvalPlanQualStart() failed to copy those
fields into the child EState, causing NULL dereference when Append
ran partition pruning during a recheck. This can occur with DELETE
or UPDATE on partitioned tables that use runtime pruning, e.g. with
generic plans.

Fix by copying all partition pruning state into the EPQ estate.

Add an isolation test that reproduces the crash with concurrent
UPDATE and DELETE on a partitioned table, where the DELETE session
hits the crash during its EPQ recheck after the UPDATE commits.

Bug: #19056
Reported-by: Fei Changhong <feichanghong@qq.com>
Diagnozed-by: Fei Changhong <feichanghong@qq.com>
Author: David Rowley <dgrowleyml@gmail.com>
Co-authored-by: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/19056-a677cef9b54d76a0%40postgresql.org
src/backend/executor/execMain.c
src/test/isolation/expected/eval-plan-qual.out
src/test/isolation/specs/eval-plan-qual.spec