Skip to content

Commit 662eebd

Browse files
committed
Fix planning of SELECT FOR UPDATE on child table with partial index.
Ordinarily we can omit checking of a WHERE condition that matches a partial index's condition, when we are using an indexscan on that partial index. However, in SELECT FOR UPDATE we must include the "redundant" filter condition in the plan so that it gets checked properly in an EvalPlanQual recheck. The planner got this mostly right, but improperly omitted the filter condition if the index in question was on an inheritance child table. In READ COMMITTED mode, this could result in incorrectly returning just-updated rows that no longer satisfy the filter condition. The cause of the error is using get_parse_rowmark() when get_plan_rowmark() is what should be used during planning. In 9.3 and up, also fix the same mistake in contrib/postgres_fdw. It's currently harmless there (for lack of inheritance support) but wrong is wrong, and the incorrect code might get copied to someplace where it's more significant. Report and fix by Kyotaro Horiguchi. Back-patch to all supported branches.
1 parent f5e4e92 commit 662eebd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/backend/optimizer/plan/createplan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "optimizer/plancat.h"
2828
#include "optimizer/planmain.h"
2929
#include "optimizer/predtest.h"
30+
#include "optimizer/prep.h"
3031
#include "optimizer/restrictinfo.h"
3132
#include "optimizer/tlist.h"
3233
#include "optimizer/var.h"
@@ -960,7 +961,7 @@ create_indexscan_plan(PlannerInfo *root,
960961
if (best_path->indexinfo->indpred)
961962
{
962963
if (baserelid != root->parse->resultRelation &&
963-
get_parse_rowmark(root->parse, baserelid) == NULL)
964+
get_plan_rowmark(root->rowMarks, baserelid) == NULL)
964965
if (predicate_implied_by(clausel,
965966
best_path->indexinfo->indpred))
966967
continue;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy