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

Commit9843841

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 parent6467661 commit9843841

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
@@ -602,6 +602,24 @@ SELECT t1."C 1", t2.c1, t3.c1 FROM "S 1"."T 1" t1 full join ft1 t2 full join ft2
602602

603603
RESET enable_hashjoin;
604604
RESET enable_nestloop;
605+
-- Test executing assertion in estimate_path_cost_size() that makes sure that
606+
-- retrieved_rows for foreign rel re-used to cost pre-sorted foreign paths is
607+
-- a sensible value even when the rel has tuples=0
608+
CREATE TABLE loct_empty (c1 int NOT NULL, c2 text);
609+
CREATE FOREIGN TABLE ft_empty (c1 int NOT NULL, c2 text)
610+
SERVER loopback OPTIONS (table_name 'loct_empty');
611+
INSERT INTO loct_empty
612+
SELECT id, 'AAA' || to_char(id, 'FM000') FROM generate_series(1, 100) id;
613+
DELETE FROM loct_empty;
614+
ANALYZE ft_empty;
615+
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft_empty ORDER BY c1;
616+
QUERY PLAN
617+
-------------------------------------------------------------------------------
618+
Foreign Scan on public.ft_empty
619+
Output: c1, c2
620+
Remote SQL: SELECT c1, c2 FROM public.loct_empty ORDER BY c1 ASC NULLS LAST
621+
(3 rows)
622+
605623
-- ===================================================================
606624
-- WHERE with remotely-executable conditions
607625
-- ===================================================================

‎contrib/postgres_fdw/postgres_fdw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2810,7 +2810,7 @@ estimate_path_cost_size(PlannerInfo *root,
28102810
*/
28112811
if (fpinfo->rel_startup_cost >=0&&fpinfo->rel_total_cost >=0)
28122812
{
2813-
Assert(fpinfo->retrieved_rows >=1);
2813+
Assert(fpinfo->retrieved_rows >=0);
28142814

28152815
rows=fpinfo->rows;
28162816
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
@@ -298,6 +298,18 @@ SELECT t1."C 1", t2.c1, t3.c1 FROM "S 1"."T 1" t1 full join ft1 t2 full join ft2
298298
RESET enable_hashjoin;
299299
RESET enable_nestloop;
300300

301+
-- Test executing assertion in estimate_path_cost_size() that makes sure that
302+
-- retrieved_rows for foreign rel re-used to cost pre-sorted foreign paths is
303+
-- a sensible value even when the rel has tuples=0
304+
CREATETABLEloct_empty (c1intNOT NULL, c2text);
305+
CREATE FOREIGN TABLE ft_empty (c1intNOT NULL, c2text)
306+
SERVER loopback OPTIONS (table_name'loct_empty');
307+
INSERT INTO loct_empty
308+
SELECT id,'AAA'|| to_char(id,'FM000')FROM generate_series(1,100) id;
309+
DELETEFROM loct_empty;
310+
ANALYZE ft_empty;
311+
EXPLAIN (VERBOSE, COSTS OFF)SELECT*FROM ft_emptyORDER BY c1;
312+
301313
-- ===================================================================
302314
-- WHERE with remotely-executable conditions
303315
-- ===================================================================

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp