diff options
author | Etsuro Fujita <efujita@postgresql.org> | 2024-07-19 13:15:00 +0900 |
---|---|---|
committer | Etsuro Fujita <efujita@postgresql.org> | 2024-07-19 13:15:00 +0900 |
commit | 5c571a34d0e99bb7df7aedd26b90ff490cd6d9ee (patch) | |
tree | caa1ac08da91d4b7577ef084d47c579fb59b834c /contrib/postgres_fdw/sql/postgres_fdw.sql | |
parent | c145f321b681ab6c3636849071ff30d5c6f6353c (diff) | |
download | postgresql-5c571a34d0e99bb7df7aedd26b90ff490cd6d9ee.tar.gz postgresql-5c571a34d0e99bb7df7aedd26b90ff490cd6d9ee.zip |
postgres_fdw: Avoid "cursor can only scan forward" error.
Commit d844cd75a disallowed rewind in a non-scrollable cursor to resolve
anomalies arising from such a cursor operation. However, this failed to
take into account the assumption in postgres_fdw that when rescanning a
foreign relation, it can rewind the cursor created for scanning the
foreign relation without specifying the SCROLL option, regardless of its
scrollability, causing this error when it tried to do such a rewind in a
non-scrollable cursor. Fix by modifying postgres_fdw to instead
recreate the cursor, regardless of its scrollability, when rescanning
the foreign relation. (If we had a way to check its scrollability, we
could improve this by rewinding it if it is scrollable and recreating it
if not, but we do not have it, so this commit modifies it to recreate it
in any case.)
Per bug #17889 from Eric Cyr. Devrim Gunduz also reported this problem.
Back-patch to v15 where that commit enforced the prohibition.
Reviewed by Tom Lane.
Discussion: https://postgr.es/m/17889-e8c39a251d258dda%40postgresql.org
Discussion: https://postgr.es/m/b415ac3255f8352d1ea921cf3b7ba39e0587768a.camel%40gunduz.org
Diffstat (limited to 'contrib/postgres_fdw/sql/postgres_fdw.sql')
-rw-r--r-- | contrib/postgres_fdw/sql/postgres_fdw.sql | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql index b57f8cfda68..733c1037712 100644 --- a/contrib/postgres_fdw/sql/postgres_fdw.sql +++ b/contrib/postgres_fdw/sql/postgres_fdw.sql @@ -1647,6 +1647,31 @@ SELECT * FROM ft1 ORDER BY c6 DESC NULLS FIRST, c1 OFFSET 15 LIMIT 10; EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft1 ORDER BY c6 ASC NULLS FIRST, c1 OFFSET 15 LIMIT 10; SELECT * FROM ft1 ORDER BY c6 ASC NULLS FIRST, c1 OFFSET 15 LIMIT 10; +-- Test ReScan code path that recreates the cursor even when no parameters +-- change (bug #17889) +CREATE TABLE loct1 (c1 int); +CREATE TABLE loct2 (c1 int, c2 text); +INSERT INTO loct1 VALUES (1001); +INSERT INTO loct1 VALUES (1002); +INSERT INTO loct2 SELECT id, to_char(id, 'FM0000') FROM generate_series(1, 1000) id; +INSERT INTO loct2 VALUES (1001, 'foo'); +INSERT INTO loct2 VALUES (1002, 'bar'); +CREATE FOREIGN TABLE remt2 (c1 int, c2 text) SERVER loopback OPTIONS (table_name 'loct2'); +ANALYZE loct1; +ANALYZE remt2; +SET enable_mergejoin TO false; +SET enable_hashjoin TO false; +SET enable_material TO false; +EXPLAIN (VERBOSE, COSTS OFF) +UPDATE remt2 SET c2 = remt2.c2 || remt2.c2 FROM loct1 WHERE loct1.c1 = remt2.c1 RETURNING remt2.*; +UPDATE remt2 SET c2 = remt2.c2 || remt2.c2 FROM loct1 WHERE loct1.c1 = remt2.c1 RETURNING remt2.*; +RESET enable_mergejoin; +RESET enable_hashjoin; +RESET enable_material; +DROP FOREIGN TABLE remt2; +DROP TABLE loct1; +DROP TABLE loct2; + -- =================================================================== -- test check constraints -- =================================================================== |