pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix incorrect reinit of run-time pruning for EPQ rechecks 3+ messages / 1 participants [nested] [flat]
* pgsql: Fix incorrect reinit of run-time pruning for EPQ rechecks @ 2026-10-08 22:03 David Rowley <drowley@postgresql.org> 0 siblings, 0 replies; 3+ messages in thread From: David Rowley @ 2026-10-08 22:03 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix incorrect reinit of run-time pruning for EPQ rechecks For run-time partition pruning running during execution (rather than at executor startup), EvalPlanQualStart() reuses the es_part_prune_states from the parent EState. This could cause an issue when the EPQ recheck is finished, its EState is cleaned up and the es_query_cxt is deleted by FreeExecutorState(). That cleanup could free memory that was allocated again in InitExecPartitionPruneContexts() when it was called for the EPQ's EState, and naturally, those fields got allocated in the EPQ's es_query_cxt MemoryContext, which overwrote the ones for the parent EState. If pruning occurs again after the EPQ's EState was cleaned up, then we could have accessed free'd memory. This certainly caused issues in debug builds because we clobber freed memory, but may not have in production, depending on if the MemoryContext being deleted results in a free(). It may not if the allocation was on the context's init block and the context was pushed onto context_freelists[] for reuse. Here we fix this by adding an "initialized" field to PartitionPruneState and exit early in InitExecPartitionPruneContexts() when the state is already initialized. This was broken by bb3ec16e1, but the breakage there is slightly different as that commit neglected to do what was fixed in 8741e48e5 (which did get backpatched to v18 in 9a82a64ed). Reported-by: Vladimir Savin <vladimir@encord.com> Author: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com> Discussion: https://postgr.es/m/CAP2G_gGpV=rKMLuET4RW-qO41GvBvi6Czsjsj16eT9hAwHxG6w@mail.gmail.com Backpatch-through: 18 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/1b5dd3a24a48659e8413ef8ddd8adb6653507a9d Modified Files -------------- src/backend/executor/execPartition.c | 12 ++++++ src/include/executor/execPartition.h | 3 ++ .../expected/eval-plan-qual-partition-prune.out | 30 +++++++++++++++ src/test/isolation/isolation_schedule | 1 + .../specs/eval-plan-qual-partition-prune.spec | 43 ++++++++++++++++++++++ 5 files changed, 89 insertions(+) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix incorrect reinit of run-time pruning for EPQ rechecks @ 2026-10-08 22:04 David Rowley <drowley@postgresql.org> 0 siblings, 0 replies; 3+ messages in thread From: David Rowley @ 2026-10-08 22:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix incorrect reinit of run-time pruning for EPQ rechecks For run-time partition pruning running during execution (rather than at executor startup), EvalPlanQualStart() reuses the es_part_prune_states from the parent EState. This could cause an issue when the EPQ recheck is finished, its EState is cleaned up and the es_query_cxt is deleted by FreeExecutorState(). That cleanup could free memory that was allocated again in InitExecPartitionPruneContexts() when it was called for the EPQ's EState, and naturally, those fields got allocated in the EPQ's es_query_cxt MemoryContext, which overwrote the ones for the parent EState. If pruning occurs again after the EPQ's EState was cleaned up, then we could have accessed free'd memory. This certainly caused issues in debug builds because we clobber freed memory, but may not have in production, depending on if the MemoryContext being deleted results in a free(). It may not if the allocation was on the context's init block and the context was pushed onto context_freelists[] for reuse. Here we fix this by adding an "initialized" field to PartitionPruneState and exit early in InitExecPartitionPruneContexts() when the state is already initialized. This was broken by bb3ec16e1, but the breakage there is slightly different as that commit neglected to do what was fixed in 8741e48e5 (which did get backpatched to v18 in 9a82a64ed). Reported-by: Vladimir Savin <vladimir@encord.com> Author: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com> Discussion: https://postgr.es/m/CAP2G_gGpV=rKMLuET4RW-qO41GvBvi6Czsjsj16eT9hAwHxG6w@mail.gmail.com Backpatch-through: 18 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/2359968b449a0fd53cfc04d4a644ae02370adec6 Modified Files -------------- src/backend/executor/execPartition.c | 12 ++++++ src/include/executor/execPartition.h | 3 ++ .../expected/eval-plan-qual-partition-prune.out | 30 +++++++++++++++ src/test/isolation/isolation_schedule | 1 + .../specs/eval-plan-qual-partition-prune.spec | 43 ++++++++++++++++++++++ 5 files changed, 89 insertions(+) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix incorrect reinit of run-time pruning for EPQ rechecks @ 2026-10-08 22:04 David Rowley <drowley@postgresql.org> 0 siblings, 0 replies; 3+ messages in thread From: David Rowley @ 2026-10-08 22:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix incorrect reinit of run-time pruning for EPQ rechecks For run-time partition pruning running during execution (rather than at executor startup), EvalPlanQualStart() reuses the es_part_prune_states from the parent EState. This could cause an issue when the EPQ recheck is finished, its EState is cleaned up and the es_query_cxt is deleted by FreeExecutorState(). That cleanup could free memory that was allocated again in InitExecPartitionPruneContexts() when it was called for the EPQ's EState, and naturally, those fields got allocated in the EPQ's es_query_cxt MemoryContext, which overwrote the ones for the parent EState. If pruning occurs again after the EPQ's EState was cleaned up, then we could have accessed free'd memory. This certainly caused issues in debug builds because we clobber freed memory, but may not have in production, depending on if the MemoryContext being deleted results in a free(). It may not if the allocation was on the context's init block and the context was pushed onto context_freelists[] for reuse. Here we fix this by adding an "initialized" field to PartitionPruneState and exit early in InitExecPartitionPruneContexts() when the state is already initialized. This was broken by bb3ec16e1, but the breakage there is slightly different as that commit neglected to do what was fixed in 8741e48e5 (which did get backpatched to v18 in 9a82a64ed). Reported-by: Vladimir Savin <vladimir@encord.com> Author: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com> Discussion: https://postgr.es/m/CAP2G_gGpV=rKMLuET4RW-qO41GvBvi6Czsjsj16eT9hAwHxG6w@mail.gmail.com Backpatch-through: 18 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c7328770ba50f6250930cb023effe3354c49de32 Modified Files -------------- src/backend/executor/execPartition.c | 12 ++++++ src/include/executor/execPartition.h | 3 ++ .../expected/eval-plan-qual-partition-prune.out | 30 +++++++++++++++ src/test/isolation/isolation_schedule | 1 + .../specs/eval-plan-qual-partition-prune.spec | 43 ++++++++++++++++++++++ 5 files changed, 89 insertions(+) ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-10-08 22:04 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-08 22:03 pgsql: Fix incorrect reinit of run-time pruning for EPQ rechecks David Rowley <drowley@postgresql.org> 2026-10-08 22:04 pgsql: Fix incorrect reinit of run-time pruning for EPQ rechecks David Rowley <drowley@postgresql.org> 2026-10-08 22:04 pgsql: Fix incorrect reinit of run-time pruning for EPQ rechecks David Rowley <drowley@postgresql.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox