Skip to content

Commit 8ec8760

Browse files
committed
Revert misguided change to postgres_fdw FOR UPDATE/SHARE code.
In commit 462bd95, I changed postgres_fdw to rely on get_plan_rowmark() instead of get_parse_rowmark(). I still think 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 have markType = ROW_MARK_COPY for all foreign tables. There's no urgent reason to change this in the back branches, so let's just revert that part of yesterday's commit rather than trying to design a better solution under time pressure. Also, add a regression test case showing what postgres_fdw does with FOR UPDATE/SHARE. I'd blithely assumed there was one already, else I'd have realized yesterday that this code didn't work.
1 parent 237a882 commit 8ec8760

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-
case ROW_MARK_EXCLUSIVE:
841-
case ROW_MARK_NOKEYEXCLUSIVE:
842-
appendStringInfoString(&sql, " FOR UPDATE");
843-
break;
844-
case ROW_MARK_SHARE:
845-
case ROW_MARK_KEYSHARE:
840+
case LCS_FORKEYSHARE:
841+
case LCS_FORSHARE:
846842
appendStringInfoString(&sql, " FOR SHARE");
847843
break;
848-
default:
849-
/* nothing needed */
844+
case LCS_FORNOKEYUPDATE:
845+
case LCS_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 t1 WHERE t1.c1 = 101 AND t1.c6 = '1' AND t1.c7 >= '1';
153153
SELECT * FROM ft1 t1 WHERE t1.c1 = 101 AND t1.c6 = '1' AND t1.c7 >= '1';
154+
-- with FOR UPDATE/SHARE
155+
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c1 = 101 FOR UPDATE;
156+
SELECT * FROM ft1 t1 WHERE c1 = 101 FOR UPDATE;
157+
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c1 = 102 FOR SHARE;
158+
SELECT * FROM ft1 t1 WHERE c1 = 102 FOR SHARE;
154159
-- aggregate
155160
SELECT COUNT(*) FROM ft1 t1;
156161
-- join two tables

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