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

Commit8ec8760

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 parent237a882 commit8ec8760

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
@@ -237,6 +237,39 @@ SELECT * FROM ft1 t1 WHERE t1.c1 = 101 AND t1.c6 = '1' AND t1.c7 >= '1';
237237
101 | 1 | 00101 | Fri Jan 02 00:00:00 1970 PST | Fri Jan 02 00:00:00 1970 | 1 | 1 | foo
238238
(1 row)
239239

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

‎contrib/postgres_fdw/postgres_fdw.c

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

827827
if (rc)
828828
{
@@ -835,18 +835,15 @@ 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->markType)
838+
switch (rc->strength)
839839
{
840-
caseROW_MARK_EXCLUSIVE:
841-
caseROW_MARK_NOKEYEXCLUSIVE:
842-
appendStringInfoString(&sql," FOR UPDATE");
843-
break;
844-
caseROW_MARK_SHARE:
845-
caseROW_MARK_KEYSHARE:
840+
caseLCS_FORKEYSHARE:
841+
caseLCS_FORSHARE:
846842
appendStringInfoString(&sql," FOR SHARE");
847843
break;
848-
default:
849-
/* nothing needed */
844+
caseLCS_FORNOKEYUPDATE:
845+
caseLCS_FORUPDATE:
846+
appendStringInfoString(&sql," FOR UPDATE");
850847
break;
851848
}
852849
}

‎contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ SELECT * FROM ft1 WHERE false;
151151
-- with WHERE clause
152152
EXPLAIN (VERBOSE, COSTS false)SELECT*FROM ft1 t1WHEREt1.c1=101ANDt1.c6='1'ANDt1.c7>='1';
153153
SELECT*FROM ft1 t1WHEREt1.c1=101ANDt1.c6='1'ANDt1.c7>='1';
154+
-- with FOR UPDATE/SHARE
155+
EXPLAIN (VERBOSE, COSTS false)SELECT*FROM ft1 t1WHERE c1=101 FORUPDATE;
156+
SELECT*FROM ft1 t1WHERE c1=101 FORUPDATE;
157+
EXPLAIN (VERBOSE, COSTS false)SELECT*FROM ft1 t1WHERE c1=102 FOR SHARE;
158+
SELECT*FROM ft1 t1WHERE c1=102 FOR SHARE;
154159
-- aggregate
155160
SELECTCOUNT(*)FROM ft1 t1;
156161
-- join two tables

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp