BUG #16807: Assert failed in postgres_fdw/estimate_path_cost_size with an empty foreign table

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: exclusion(at)gmail(dot)com
Subject: BUG #16807: Assert failed in postgres_fdw/estimate_path_cost_size with an empty foreign table
Date: 2021-01-05 18:00:02
Message-ID: 16807-9fe4e08fbaa5c7ce@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16807
Logged by: Alexander Lakhin
Email address: exclusion(at)gmail(dot)com
PostgreSQL version: 13.1
Operating system: Ubuntu 20.04
Description:

When executing the following query:
CREATE EXTENSION postgres_fdw;

DO $d$
BEGIN
EXECUTE $$CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (dbname '$$||current_database()||$$',
port '$$||current_setting('port')||$$'
)$$;
END;
$d$;

CREATE USER MAPPING FOR CURRENT_USER SERVER loopback;
CREATE TABLE t1 (c1 int NOT NULL);
CREATE FOREIGN TABLE ft1 (c1 int NOT NULL) SERVER loopback OPTIONS
(schema_name 'public', table_name 't1');

INSERT INTO t1 SELECT id FROM generate_series(1, 100) id;
DELETE FROM t1;

ANALYZE ft1;

EXPLAIN
SELECT t1.c1, t2.c1 FROM ft1 t1 JOIN ft1 t2 ON (t1.c1 = t2.c1) ORDER BY
t1.c1, t2.c1;

The assert-enabled server crashes with the stacktrace:
Core was generated by `postgres: law contrib_regression [local] EXPLAIN
'.
Program terminated with signal SIGABRT, Aborted.
#0 __GI_raise (sig=sig(at)entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 __GI_raise (sig=sig(at)entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007efc3d7fa859 in __GI_abort () at abort.c:79
#2 0x000055d6c447c083 in ExceptionalCondition (
conditionName=conditionName(at)entry=0x7efc3dd795eb "fpinfo->retrieved_rows
>= 1",
errorType=errorType(at)entry=0x7efc3dd784e5 "FailedAssertion",
fileName=fileName(at)entry=0x7efc3dd7959c "postgres_fdw.c",
lineNumber=lineNumber(at)entry=2810) at assert.c:67
#3 0x00007efc3dd6e5e5 in estimate_path_cost_size
(root=root(at)entry=0x55d6c5e9b250,
foreignrel=foreignrel(at)entry=0x55d6c5e8b760,
param_join_conds=param_join_conds(at)entry=0x0,
pathkeys=pathkeys(at)entry=0x55d6c5e9e258, fpextra=fpextra(at)entry=0x0,
p_rows=p_rows(at)entry=0x7ffcc2b6d320,
p_width=0x7ffcc2b6d31c, p_startup_cost=0x7ffcc2b6d328,
p_total_cost=0x7ffcc2b6d330) at postgres_fdw.c:2810
#4 0x00007efc3dd6fdda in add_paths_with_pathkeys_for_rel
(root=root(at)entry=0x55d6c5e9b250,
rel=rel(at)entry=0x55d6c5e8b760, epq_path=epq_path(at)entry=0x0) at
postgres_fdw.c:5278
#5 0x00007efc3dd72c8e in postgresGetForeignPaths (root=0x55d6c5e9b250,
baserel=0x55d6c5e8b760,
foreigntableid=<optimized out>) at postgres_fdw.c:994
#6 0x000055d6c4247d1f in set_foreign_pathlist
(root=root(at)entry=0x55d6c5e9b250, rel=rel(at)entry=0x55d6c5e8b760,
rte=rte(at)entry=0x55d6c5d97bf0) at allpaths.c:927
#7 0x000055d6c424b78e in set_rel_pathlist (root=root(at)entry=0x55d6c5e9b250,
rel=0x55d6c5e8b760, rti=rti(at)entry=1,
rte=0x55d6c5d97bf0) at allpaths.c:490
#8 0x000055d6c424b8ad in set_base_rel_pathlists
(root=root(at)entry=0x55d6c5e9b250) at allpaths.c:352
#9 0x000055d6c424bf95 in make_one_rel (root=root(at)entry=0x55d6c5e9b250,
joinlist=joinlist(at)entry=0x55d6c5e9cbd0)
at allpaths.c:222
#10 0x000055d6c4272976 in query_planner (root=root(at)entry=0x55d6c5e9b250,
qp_callback=qp_callback(at)entry=0x55d6c42768fe <standard_qp_callback>,
qp_extra=qp_extra(at)entry=0x7ffcc2b6d5a0)
at planmain.c:269
#11 0x000055d6c4279aa4 in grouping_planner (root=root(at)entry=0x55d6c5e9b250,

inheritance_update=inheritance_update(at)entry=false,
tuple_fraction=<optimized out>, tuple_fraction(at)entry=0)
at planner.c:2058
#12 0x000055d6c427c041 in subquery_planner (glob=glob(at)entry=0x55d6c5e8b648,
parse=parse(at)entry=0x55d6c5d97ad8,
parent_root=parent_root(at)entry=0x0,
hasRecursion=hasRecursion(at)entry=false,
tuple_fraction=tuple_fraction(at)entry=0)
at planner.c:1015
#13 0x000055d6c427c6d7 in standard_planner (parse=0x55d6c5d97ad8,
query_string=<optimized out>, cursorOptions=256,
boundParams=<optimized out>) at planner.c:405
#14 0x000055d6c427cccb in planner (parse=parse(at)entry=0x55d6c5d97ad8,
query_string=query_string(at)entry=0x55d6c5d743d0 "EXPLAIN\nSELECT t1.c1,
t2.c1 FROM ft1 t1 JOIN ft1 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c1, t2.c1;",
cursorOptions=cursorOptions(at)entry=256, boundParams=boundParams(at)entry=0x0) at
planner.c:275
#15 0x000055d6c435685d in pg_plan_query
(querytree=querytree(at)entry=0x55d6c5d97ad8,
query_string=query_string(at)entry=0x55d6c5d743d0 "EXPLAIN\nSELECT t1.c1,
t2.c1 FROM ft1 t1 JOIN ft1 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c1, t2.c1;",
cursorOptions=cursorOptions(at)entry=256, boundParams=boundParams(at)entry=0x0)
at postgres.c:875
#16 0x000055d6c4145ed5 in ExplainOneQuery (query=0x55d6c5d97ad8,
cursorOptions=cursorOptions(at)entry=256,
into=into(at)entry=0x0, es=es(at)entry=0x55d6c5e681b0,
queryString=0x55d6c5d743d0 "EXPLAIN\nSELECT t1.c1, t2.c1 FROM ft1 t1
JOIN ft1 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c1, t2.c1;",
params=params(at)entry=0x0, queryEnv=0x0) at explain.c:391
#17 0x000055d6c41468d1 in ExplainQuery (pstate=pstate(at)entry=0x55d6c5e59f70,
stmt=stmt(at)entry=0x55d6c5d75b38,
params=params(at)entry=0x0, dest=dest(at)entry=0x55d6c5e59ed8) at
../../../src/include/nodes/nodes.h:594
#18 0x000055d6c435c84b in standard_ProcessUtility (pstmt=0x55d6c5d75be0,
queryString=0x55d6c5d743d0 "EXPLAIN\nSELECT t1.c1, t2.c1 FROM ft1 t1
JOIN ft1 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c1, t2.c1;",
context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
dest=0x55d6c5e59ed8, qc=0x7ffcc2b6da30)
at utility.c:829
#19 0x000055d6c435cdea in ProcessUtility (pstmt=pstmt(at)entry=0x55d6c5d75be0,
queryString=<optimized out>,
context=context(at)entry=PROCESS_UTILITY_TOPLEVEL, params=<optimized out>,
queryEnv=<optimized out>,
dest=dest(at)entry=0x55d6c5e59ed8, qc=0x7ffcc2b6da30) at utility.c:524
#20 0x000055d6c4359255 in PortalRunUtility
(portal=portal(at)entry=0x55d6c5dd7870, pstmt=0x55d6c5d75be0,
isTopLevel=<optimized out>, setHoldSnapshot=setHoldSnapshot(at)entry=true,
dest=dest(at)entry=0x55d6c5e59ed8,
qc=qc(at)entry=0x7ffcc2b6da30) at pquery.c:1157
#21 0x000055d6c435a069 in FillPortalStore
(portal=portal(at)entry=0x55d6c5dd7870, isTopLevel=isTopLevel(at)entry=true)
at ../../../src/include/nodes/nodes.h:594
#22 0x000055d6c435ac0f in PortalRun (portal=portal(at)entry=0x55d6c5dd7870,
count=count(at)entry=9223372036854775807,
isTopLevel=isTopLevel(at)entry=true, run_once=run_once(at)entry=true,
dest=dest(at)entry=0x55d6c5e71c50,
altdest=altdest(at)entry=0x55d6c5e71c50, qc=0x7ffcc2b6dc20) at
pquery.c:751
#23 0x000055d6c4356ed5 in exec_simple_query (
query_string=query_string(at)entry=0x55d6c5d743d0 "EXPLAIN\nSELECT t1.c1,
t2.c1 FROM ft1 t1 JOIN ft1 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c1, t2.c1;") at
postgres.c:1239
#24 0x000055d6c4358df1 in PostgresMain (argc=<optimized out>,
argv=argv(at)entry=0x55d6c5d9fb18, dbname=<optimized out>,
username=<optimized out>) at postgres.c:4315
#25 0x000055d6c42c4726 in BackendRun (port=port(at)entry=0x55d6c5d98400) at
postmaster.c:4526
#26 0x000055d6c42c7881 in BackendStartup (port=port(at)entry=0x55d6c5d98400) at
postmaster.c:4210
#27 0x000055d6c42c7ac8 in ServerLoop () at postmaster.c:1739
#28 0x000055d6c42c8ff1 in PostmasterMain (argc=8, argv=<optimized out>) at
postmaster.c:1412
#29 0x000055d6c4212224 in main (argc=8, argv=0x55d6c5d6ea40) at main.c:210

This can be reproduced also by `make check -C contrib/postgres_fdw` with the
following change in contrib/postgres_fdw/sql/postgres_fdw.sql:
-DELETE FROM "S 1"."T 4" WHERE c1 % 3 != 0; -- delete for outer join
tests
+DELETE FROM "S 1"."T 4"; -- delete for outer join tests

The first bad commit is 08d2d58a.
Without the Assert() that query executes successfully.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2021-01-06 02:02:16 Re: compiling error on OpenWrt
Previous Message Tom Lane 2021-01-05 15:49:33 Re: compiling error on OpenWrt