Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit462bd95

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 partialindex's condition, when we are using an indexscan on that partial index.However, in SELECT FOR UPDATE we must include the "redundant" filtercondition in the plan so that it gets checked properly in an EvalPlanQualrecheck. The planner got this mostly right, but improperly omitted thefilter condition if the index in question was on an inheritance childtable. In READ COMMITTED mode, this could result in incorrectly returningjust-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 samemistake in contrib/postgres_fdw. It's currently harmless there (for lackof inheritance support) but wrong is wrong, and the incorrect code mightget copied to someplace where it's more significant.Report and fix by Kyotaro Horiguchi. Back-patch to all supported branches.
1 parent2db576b commit462bd95

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

‎contrib/postgres_fdw/postgres_fdw.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ postgresGetForeignPlan(PlannerInfo *root,
822822
}
823823
else
824824
{
825-
RowMarkClause*rc=get_parse_rowmark(root->parse,baserel->relid);
825+
PlanRowMark*rc=get_plan_rowmark(root->rowMarks,baserel->relid);
826826

827827
if (rc)
828828
{
@@ -835,15 +835,18 @@ postgresGetForeignPlan(PlannerInfo *root,
835835
* complete information about, and (b) it wouldn't work anyway on
836836
* older remote servers. Likewise, we don't worry about NOWAIT.
837837
*/
838-
switch (rc->strength)
838+
switch (rc->markType)
839839
{
840-
caseLCS_FORKEYSHARE:
841-
caseLCS_FORSHARE:
840+
caseROW_MARK_EXCLUSIVE:
841+
caseROW_MARK_NOKEYEXCLUSIVE:
842+
appendStringInfoString(&sql," FOR UPDATE");
843+
break;
844+
caseROW_MARK_SHARE:
845+
caseROW_MARK_KEYSHARE:
842846
appendStringInfoString(&sql," FOR SHARE");
843847
break;
844-
caseLCS_FORNOKEYUPDATE:
845-
caseLCS_FORUPDATE:
846-
appendStringInfoString(&sql," FOR UPDATE");
848+
default:
849+
/* nothing needed */
847850
break;
848851
}
849852
}

‎src/backend/optimizer/plan/createplan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include"optimizer/planmain.h"
3535
#include"optimizer/planner.h"
3636
#include"optimizer/predtest.h"
37+
#include"optimizer/prep.h"
3738
#include"optimizer/restrictinfo.h"
3839
#include"optimizer/subselect.h"
3940
#include"optimizer/tlist.h"
@@ -1231,7 +1232,7 @@ create_indexscan_plan(PlannerInfo *root,
12311232
if (best_path->indexinfo->indpred)
12321233
{
12331234
if (baserelid!=root->parse->resultRelation&&
1234-
get_parse_rowmark(root->parse,baserelid)==NULL)
1235+
get_plan_rowmark(root->rowMarks,baserelid)==NULL)
12351236
if (predicate_implied_by(clausel,
12361237
best_path->indexinfo->indpred))
12371238
continue;/* implied by index predicate */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp