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

Commitcfc878a

Browse files
committed
Revert misguided change to postgres_fdw FOR UPDATE/SHARE code.
In commit462bd95, I changed postgres_fdwto rely on get_plan_rowmark() instead of get_parse_rowmark(). I stillthink that's a good idea in the long run, but as Etsuro Fujita pointed out,it doesn't work today because planner.c forces PlanRowMarks to havemarkType = ROW_MARK_COPY for all foreign tables. There's no urgent reasonto change this in the back branches, so let's just revert that part ofyesterday's commit rather than trying to design a better solution undertime pressure.Also, add a regression test case showing what postgres_fdw does with FORUPDATE/SHARE. I'd blithely assumed there was one already, else I'd haverealized yesterday that this code didn't work.
1 parent2ae8a01 commitcfc878a

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

‎contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,39 @@ SELECT * FROM ft1 t1 WHERE t1.c1 = 101 AND t1.c6 = '1' AND t1.c7 >= '1';
231231
101 | 1 | 00101 | Fri Jan 02 00:00:00 1970 PST | Fri Jan 02 00:00:00 1970 | 1 | 1 | foo
232232
(1 row)
233233

234+
-- with FOR UPDATE/SHARE
235+
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c1 = 101 FOR UPDATE;
236+
QUERY PLAN
237+
----------------------------------------------------------------------------------------------------------------
238+
LockRows
239+
Output: c1, c2, c3, c4, c5, c6, c7, c8, t1.*
240+
-> Foreign Scan on public.ft1 t1
241+
Output: c1, c2, c3, c4, c5, c6, c7, c8, t1.*
242+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (("C 1" = 101)) FOR UPDATE
243+
(5 rows)
244+
245+
SELECT * FROM ft1 t1 WHERE c1 = 101 FOR UPDATE;
246+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
247+
-----+----+-------+------------------------------+--------------------------+----+------------+-----
248+
101 | 1 | 00101 | Fri Jan 02 00:00:00 1970 PST | Fri Jan 02 00:00:00 1970 | 1 | 1 | foo
249+
(1 row)
250+
251+
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c1 = 102 FOR SHARE;
252+
QUERY PLAN
253+
---------------------------------------------------------------------------------------------------------------
254+
LockRows
255+
Output: c1, c2, c3, c4, c5, c6, c7, c8, t1.*
256+
-> Foreign Scan on public.ft1 t1
257+
Output: c1, c2, c3, c4, c5, c6, c7, c8, t1.*
258+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (("C 1" = 102)) FOR SHARE
259+
(5 rows)
260+
261+
SELECT * FROM ft1 t1 WHERE c1 = 102 FOR SHARE;
262+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
263+
-----+----+-------+------------------------------+--------------------------+----+------------+-----
264+
102 | 2 | 00102 | Sat Jan 03 00:00:00 1970 PST | Sat Jan 03 00:00:00 1970 | 2 | 2 | foo
265+
(1 row)
266+
234267
-- aggregate
235268
SELECT COUNT(*) FROM ft1 t1;
236269
count

‎contrib/postgres_fdw/postgres_fdw.c

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

824824
if (rc)
825825
{
@@ -832,18 +832,15 @@ postgresGetForeignPlan(PlannerInfo *root,
832832
* complete information about, and (b) it wouldn't work anyway on
833833
* older remote servers. Likewise, we don't worry about NOWAIT.
834834
*/
835-
switch (rc->markType)
835+
switch (rc->strength)
836836
{
837-
case ROW_MARK_EXCLUSIVE:
838-
case ROW_MARK_NOKEYEXCLUSIVE:
839-
appendStringInfoString(&sql, " FOR UPDATE");
840-
break;
841-
case ROW_MARK_SHARE:
842-
case ROW_MARK_KEYSHARE:
837+
case LCS_FORKEYSHARE:
838+
case LCS_FORSHARE:
843839
appendStringInfoString(&sql, " FOR SHARE");
844840
break;
845-
default:
846-
/* nothing needed */
841+
case LCS_FORNOKEYUPDATE:
842+
case LCS_FORUPDATE:
843+
appendStringInfoString(&sql, " FOR UPDATE");
847844
break;
848845
}
849846
}

‎contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ SELECT * FROM ft1 WHERE false;
145145
-- with WHERE clause
146146
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE t1.c1 = 101 AND t1.c6 = '1' AND t1.c7 >= '1';
147147
SELECT * FROM ft1 t1 WHERE t1.c1 = 101 AND t1.c6 = '1' AND t1.c7 >= '1';
148+
-- with FOR UPDATE/SHARE
149+
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c1 = 101 FOR UPDATE;
150+
SELECT * FROM ft1 t1 WHERE c1 = 101 FOR UPDATE;
151+
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c1 = 102 FOR SHARE;
152+
SELECT * FROM ft1 t1 WHERE c1 = 102 FOR SHARE;
148153
-- aggregate
149154
SELECT COUNT(*) FROM ft1 t1;
150155
-- join two tables

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp