@@ -175,6 +175,22 @@ SELECT key FROM ft_sessions WHERE key = 'sess:rollback_test';
175175-----
176176(0 rows)
177177
178+ -- Nested Savepoint Rollback on MapTableFdw
179+ BEGIN;
180+ INSERT INTO ft_sessions (key, user_id, status, data)
181+ VALUES ('sess:sp_keep', 701, 'active', '{}');
182+ SAVEPOINT sp_map;
183+ INSERT INTO ft_sessions (key, user_id, status, data)
184+ VALUES ('sess:sp_abort', 702, 'transient', '{}');
185+ ROLLBACK TO SAVEPOINT sp_map;
186+ COMMIT;
187+ SELECT key, user_id, status FROM ft_sessions WHERE key IN ('sess:sp_keep', 'sess:sp_abort') ORDER BY key;
188+ key | user_id | status
189+ --------------+---------+--------
190+ sess:sp_keep | 701 | active
191+ (1 row)
192+
193+ DELETE FROM ft_sessions WHERE key = 'sess:sp_keep';
178194-- 11. Direct Modify Pushdown
179195CREATE SERVER test_dm_srv FOREIGN DATA WRAPPER pljs_fdw OPTIONS (wrapper 'MapTableFdw', direct_modify 'true');
180196CREATE FOREIGN TABLE ft_dm_sessions (
@@ -326,6 +342,38 @@ SELECT id, name FROM ft_temp_products WHERE id = 99;
326342----+------
327343(0 rows)
328344
345+ -- Nested Savepoint and Subtransaction Rollback Coordination
346+ BEGIN;
347+ INSERT INTO ft_temp_products (id, name, category, price, in_stock)
348+ VALUES (100, 'Tablet', 'electronics', 499.00, true);
349+ SAVEPOINT sp1;
350+ INSERT INTO ft_temp_products (id, name, category, price, in_stock)
351+ VALUES (101, 'Smartwatch', 'electronics', 249.00, true);
352+ SAVEPOINT sp2;
353+ INSERT INTO ft_temp_products (id, name, category, price, in_stock)
354+ VALUES (102, 'Fitness Band', 'electronics', 79.00, true);
355+ ROLLBACK TO SAVEPOINT sp2;
356+ SELECT id, name FROM ft_temp_products WHERE id IN (100, 101, 102) ORDER BY id;
357+ id | name
358+ -----+------------
359+ 100 | Tablet
360+ 101 | Smartwatch
361+ (2 rows)
362+
363+ ROLLBACK TO SAVEPOINT sp1;
364+ SELECT id, name FROM ft_temp_products WHERE id IN (100, 101, 102) ORDER BY id;
365+ id | name
366+ -----+--------
367+ 100 | Tablet
368+ (1 row)
369+
370+ COMMIT;
371+ SELECT id, name FROM ft_temp_products WHERE id IN (100, 101, 102) ORDER BY id;
372+ id | name
373+ -----+--------
374+ 100 | Tablet
375+ (1 row)
376+
329377-- 14. RandomPeopleFdw: Synthetic Personal Info Table with Limit Pushdown
330378CREATE SERVER test_rand_srv FOREIGN DATA WRAPPER pljs_fdw OPTIONS (wrapper 'RandomPeopleFdw');
331379CREATE FOREIGN TABLE ft_random_people (
@@ -381,6 +429,49 @@ SELECT id, first_name, last_name, email, age, city FROM ft_random_people WHERE i
381429 42 | Margaret | Martinez | margaret.martinez42@example.com | 24 | Indianapolis
382430(1 row)
383431
432+ -- Point ID lookup with additional non-matching predicate (must return 0 rows)
433+ SELECT id, first_name, city FROM ft_random_people WHERE id = 42 AND city = 'Atlantis';
434+ id | first_name | city
435+ ----+------------+------
436+ (0 rows)
437+
438+ -- Point ID lookup with matching predicate
439+ SELECT id, first_name, city FROM ft_random_people WHERE id = 42 AND city = 'Indianapolis';
440+ id | first_name | city
441+ ----+------------+--------------
442+ 42 | Margaret | Indianapolis
443+ (1 row)
444+
445+ -- Batch IN list ID lookup with limit pushdown
446+ SELECT id, first_name FROM ft_random_people WHERE id IN (1, 5, 9999) LIMIT 2;
447+ id | first_name
448+ ----+------------
449+ 1 | Margaret
450+ 5 | Anthony
451+ (2 rows)
452+
453+ -- Order by ID with pushed limit (sort elimination via pathkeys)
454+ EXPLAIN (VERBOSE, COSTS OFF)
455+ SELECT id, first_name FROM ft_random_people ORDER BY id ASC LIMIT 5;
456+ QUERY PLAN
457+ -----------------------------------------------
458+ Limit
459+ Output: id, first_name
460+ -> Foreign Scan on public.ft_random_people
461+ Output: id, first_name
462+ Pushed Limit: 5
463+ (5 rows)
464+
465+ SELECT id, first_name FROM ft_random_people ORDER BY id ASC LIMIT 5;
466+ id | first_name
467+ ----+------------
468+ 1 | Margaret
469+ 2 | Patricia
470+ 3 | Patricia
471+ 4 | James
472+ 5 | Anthony
473+ (5 rows)
474+
384475-- Zero limit test (must return 0 rows)
385476SELECT id FROM ft_random_people LIMIT 0;
386477 id
0 commit comments