@@ -7220,6 +7220,92 @@ select * from bar where f1 in (select f1 from foo) for share;
7220
7220
4 | 44
7221
7221
(4 rows)
7222
7222
7223
+ -- Now check SELECT FOR UPDATE/SHARE with an inherited source table,
7224
+ -- where the parent is itself a foreign table
7225
+ create table loct4 (f1 int, f2 int, f3 int);
7226
+ create foreign table foo2child (f3 int) inherits (foo2)
7227
+ server loopback options (table_name 'loct4');
7228
+ NOTICE: moving and merging column "f3" with inherited definition
7229
+ DETAIL: User-specified column moved to the position of the inherited column.
7230
+ explain (verbose, costs off)
7231
+ select * from bar where f1 in (select f1 from foo2) for share;
7232
+ QUERY PLAN
7233
+ --------------------------------------------------------------------------------------
7234
+ LockRows
7235
+ Output: bar.f1, bar.f2, bar.ctid, foo2.*, bar.*, bar.tableoid, foo2.tableoid
7236
+ -> Hash Join
7237
+ Output: bar.f1, bar.f2, bar.ctid, foo2.*, bar.*, bar.tableoid, foo2.tableoid
7238
+ Inner Unique: true
7239
+ Hash Cond: (bar.f1 = foo2.f1)
7240
+ -> Append
7241
+ -> Seq Scan on public.bar bar_1
7242
+ Output: bar_1.f1, bar_1.f2, bar_1.ctid, bar_1.*, bar_1.tableoid
7243
+ -> Foreign Scan on public.bar2 bar_2
7244
+ Output: bar_2.f1, bar_2.f2, bar_2.ctid, bar_2.*, bar_2.tableoid
7245
+ Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR SHARE
7246
+ -> Hash
7247
+ Output: foo2.*, foo2.f1, foo2.tableoid
7248
+ -> HashAggregate
7249
+ Output: foo2.*, foo2.f1, foo2.tableoid
7250
+ Group Key: foo2.f1
7251
+ -> Append
7252
+ -> Foreign Scan on public.foo2 foo2_1
7253
+ Output: foo2_1.*, foo2_1.f1, foo2_1.tableoid
7254
+ Remote SQL: SELECT f1, f2, f3 FROM public.loct1
7255
+ -> Foreign Scan on public.foo2child foo2_2
7256
+ Output: foo2_2.*, foo2_2.f1, foo2_2.tableoid
7257
+ Remote SQL: SELECT f1, f2, f3 FROM public.loct4
7258
+ (24 rows)
7259
+
7260
+ select * from bar where f1 in (select f1 from foo2) for share;
7261
+ f1 | f2
7262
+ ----+----
7263
+ 2 | 22
7264
+ 4 | 44
7265
+ (2 rows)
7266
+
7267
+ drop foreign table foo2child;
7268
+ -- And with a local child relation of the foreign table parent
7269
+ create table foo2child (f3 int) inherits (foo2);
7270
+ NOTICE: moving and merging column "f3" with inherited definition
7271
+ DETAIL: User-specified column moved to the position of the inherited column.
7272
+ explain (verbose, costs off)
7273
+ select * from bar where f1 in (select f1 from foo2) for share;
7274
+ QUERY PLAN
7275
+ -------------------------------------------------------------------------------------------------
7276
+ LockRows
7277
+ Output: bar.f1, bar.f2, bar.ctid, foo2.*, bar.*, bar.tableoid, foo2.ctid, foo2.tableoid
7278
+ -> Hash Join
7279
+ Output: bar.f1, bar.f2, bar.ctid, foo2.*, bar.*, bar.tableoid, foo2.ctid, foo2.tableoid
7280
+ Inner Unique: true
7281
+ Hash Cond: (bar.f1 = foo2.f1)
7282
+ -> Append
7283
+ -> Seq Scan on public.bar bar_1
7284
+ Output: bar_1.f1, bar_1.f2, bar_1.ctid, bar_1.*, bar_1.tableoid
7285
+ -> Foreign Scan on public.bar2 bar_2
7286
+ Output: bar_2.f1, bar_2.f2, bar_2.ctid, bar_2.*, bar_2.tableoid
7287
+ Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR SHARE
7288
+ -> Hash
7289
+ Output: foo2.*, foo2.f1, foo2.ctid, foo2.tableoid
7290
+ -> HashAggregate
7291
+ Output: foo2.*, foo2.f1, foo2.ctid, foo2.tableoid
7292
+ Group Key: foo2.f1
7293
+ -> Append
7294
+ -> Foreign Scan on public.foo2 foo2_1
7295
+ Output: foo2_1.*, foo2_1.f1, foo2_1.ctid, foo2_1.tableoid
7296
+ Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1
7297
+ -> Seq Scan on public.foo2child foo2_2
7298
+ Output: foo2_2.*, foo2_2.f1, foo2_2.ctid, foo2_2.tableoid
7299
+ (23 rows)
7300
+
7301
+ select * from bar where f1 in (select f1 from foo2) for share;
7302
+ f1 | f2
7303
+ ----+----
7304
+ 2 | 22
7305
+ 4 | 44
7306
+ (2 rows)
7307
+
7308
+ drop table foo2child;
7223
7309
-- Check UPDATE with inherited target and an inherited source table
7224
7310
explain (verbose, costs off)
7225
7311
update bar set f2 = f2 + 100 where f1 in (select f1 from foo);
0 commit comments