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

Appearance settings

Commit 5e7fa18

Browse filesBrowse files
author
Etsuro Fujita
committed
postgres_fdw: Fix assertion in estimate_path_cost_size().
Commit 08d2d58 added an assertion assuming that the retrieved_rows estimate for a foreign relation, which is re-used to cost pre-sorted foreign paths with local stats, is set to at least one row in estimate_path_cost_size(), which isn't correct because if the relation is a foreign table with tuples=0, the estimate would be set to 0 there when not using remote estimates. Per bug #16807 from Alexander Lakhin. Back-patch to v13 where the aforementioned commit went in. Author: Etsuro Fujita Reviewed-by: Kyotaro Horiguchi Discussion: https://postgr.es/m/16807-9fe4e08fbaa5c7ce%40postgresql.org
1 parent 0ff865f commit 5e7fa18
Copy full SHA for 5e7fa18

File tree

Expand file treeCollapse file tree

3 files changed

+31
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+31
-1
lines changed

‎contrib/postgres_fdw/expected/postgres_fdw.out

Copy file name to clipboardExpand all lines: contrib/postgres_fdw/expected/postgres_fdw.out
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,24 @@ SELECT t1."C 1", t2.c1, t3.c1 FROM "S 1"."T 1" t1 full join ft1 t2 full join ft2
613613

614614
RESET enable_hashjoin;
615615
RESET enable_nestloop;
616+
-- Test executing assertion in estimate_path_cost_size() that makes sure that
617+
-- retrieved_rows for foreign rel re-used to cost pre-sorted foreign paths is
618+
-- a sensible value even when the rel has tuples=0
619+
CREATE TABLE loct_empty (c1 int NOT NULL, c2 text);
620+
CREATE FOREIGN TABLE ft_empty (c1 int NOT NULL, c2 text)
621+
SERVER loopback OPTIONS (table_name 'loct_empty');
622+
INSERT INTO loct_empty
623+
SELECT id, 'AAA' || to_char(id, 'FM000') FROM generate_series(1, 100) id;
624+
DELETE FROM loct_empty;
625+
ANALYZE ft_empty;
626+
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft_empty ORDER BY c1;
627+
QUERY PLAN
628+
-------------------------------------------------------------------------------
629+
Foreign Scan on public.ft_empty
630+
Output: c1, c2
631+
Remote SQL: SELECT c1, c2 FROM public.loct_empty ORDER BY c1 ASC NULLS LAST
632+
(3 rows)
633+
616634
-- ===================================================================
617635
-- WHERE with remotely-executable conditions
618636
-- ===================================================================

‎contrib/postgres_fdw/postgres_fdw.c

Copy file name to clipboardExpand all lines: contrib/postgres_fdw/postgres_fdw.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2923,7 +2923,7 @@ estimate_path_cost_size(PlannerInfo *root,
29232923
*/
29242924
if (fpinfo->rel_startup_cost >= 0 && fpinfo->rel_total_cost >= 0)
29252925
{
2926-
Assert(fpinfo->retrieved_rows >= 1);
2926+
Assert(fpinfo->retrieved_rows >= 0);
29272927

29282928
rows = fpinfo->rows;
29292929
retrieved_rows = fpinfo->retrieved_rows;

‎contrib/postgres_fdw/sql/postgres_fdw.sql

Copy file name to clipboardExpand all lines: contrib/postgres_fdw/sql/postgres_fdw.sql
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ SELECT t1."C 1", t2.c1, t3.c1 FROM "S 1"."T 1" t1 full join ft1 t2 full join ft2
309309
RESET enable_hashjoin;
310310
RESET enable_nestloop;
311311

312+
-- Test executing assertion in estimate_path_cost_size() that makes sure that
313+
-- retrieved_rows for foreign rel re-used to cost pre-sorted foreign paths is
314+
-- a sensible value even when the rel has tuples=0
315+
CREATE TABLE loct_empty (c1 int NOT NULL, c2 text);
316+
CREATE FOREIGN TABLE ft_empty (c1 int NOT NULL, c2 text)
317+
SERVER loopback OPTIONS (table_name 'loct_empty');
318+
INSERT INTO loct_empty
319+
SELECT id, 'AAA' || to_char(id, 'FM000') FROM generate_series(1, 100) id;
320+
DELETE FROM loct_empty;
321+
ANALYZE ft_empty;
322+
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft_empty ORDER BY c1;
323+
312324
-- ===================================================================
313325
-- WHERE with remotely-executable conditions
314326
-- ===================================================================

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.