Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit5e7fa18

Browse files
author
Etsuro Fujita
committed
postgres_fdw: Fix assertion in estimate_path_cost_size().
Commit08d2d58 added an assertion assuming that the retrieved_rowsestimate for a foreign relation, which is re-used to cost pre-sortedforeign paths with local stats, is set to at least one row inestimate_path_cost_size(), which isn't correct because if the relationis a foreign table with tuples=0, the estimate would be set to 0 therewhen not using remote estimates.Per bug #16807 from Alexander Lakhin. Back-patch to v13 where theaforementioned commit went in.Author: Etsuro FujitaReviewed-by: Kyotaro HoriguchiDiscussion:https://postgr.es/m/16807-9fe4e08fbaa5c7ce%40postgresql.org
1 parent0ff865f commit5e7fa18

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

‎contrib/postgres_fdw/expected/postgres_fdw.out

Lines 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

Lines 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

Lines 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+
CREATETABLEloct_empty (c1intNOT NULL, c2text);
316+
CREATE FOREIGN TABLE ft_empty (c1intNOT NULL, c2text)
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+
DELETEFROM loct_empty;
321+
ANALYZE ft_empty;
322+
EXPLAIN (VERBOSE, COSTS OFF)SELECT*FROM ft_emptyORDER BY c1;
323+
312324
-- ===================================================================
313325
-- WHERE with remotely-executable conditions
314326
-- ===================================================================

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp