Skip to content

Server crashes when executing "select * from f2()" #730

@saygoodbyye

Description

@saygoodbyye

What happens?

postgresql:

CPPFLAGS="-Og -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=nonnull-attribute -fstack-protector" \
LDFLAGS='-fsanitize=address -fsanitize=undefined -static-libasan' \
./configure --enable-crash-info --enable-tap-tests --with-openssl --enable-debug --enable-cassert --with-icu --with-lz4 --with-libxml --quiet --prefix="$PGPREFIX"

To Reproduce

test:

CREATE EXTENSION pg_duckdb;

CREATE TEMP TABLE t_ddb(a int) USING duckdb;
INSERT INTO t_ddb VALUES (1);

CREATE OR REPLACE FUNCTION f2() RETURNS void
    LANGUAGE plpgsql
    RETURNS NULL ON NULL INPUT
    AS
$$
BEGIN
    CREATE TEMP TABLE t_ddb2(a int) USING duckdb;
    CREATE TEMP TABLE t_ddb3(a) USING duckdb AS SELECT 1;
    DROP TABLE t_ddb3;
    INSERT INTO t_ddb2 VALUES (1);
    ALTER TABLE t_ddb2 ADD COLUMN b int;
    ALTER TABLE t_ddb2 ADD COLUMN c int;
    ALTER TABLE t_ddb2 ADD COLUMN d int DEFAULT 100, ADD COLUMN e int DEFAULT 10;
    ALTER TABLE t_ddb2 RENAME COLUMN b TO f;
    ALTER TABLE t_ddb2 RENAME TO t_ddb4;
END;
$$;

SELECT * FROM f2();
SELECT * FROM f2();

backtrace:

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
#1  0x00007f4f5b2a9f4f in __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  0x00007f4f5b25afb2 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007f4f5b245472 in __GI_abort () at ./stdlib/abort.c:79
#4  0x0000564c1d7f551f in __sanitizer::Abort() ()
#5  0x0000564c1d801bb1 in __sanitizer::Die() ()
#6  0x0000564c1d7e0f6e in __asan::ScopedInErrorReport::~ScopedInErrorReport() ()
#7  0x0000564c1d7e04d6 in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) ()
#8  0x0000564c1d7e152c in __asan_report_load4 ()
#9  0x0000564c1e6fd26c in castNodeImpl (type=type@entry=T_Query, ptr=<optimized out>) at ../../../src/include/nodes/nodes.h:171
#10 0x0000564c1e6fe5b2 in UtilityContainsQuery (parsetree=<optimized out>) at utility.c:2195
#11 0x0000564c1eb1fa61 in AcquireExecutorLocks (stmt_list=0x6190000493d0, acquire=acquire@entry=true) at plancache.c:1790
#12 0x0000564c1eb23f76 in CheckCachedPlan (plansource=plansource@entry=0x619000038080) at plancache.c:856
#13 0x0000564c1eb24599 in GetCachedPlan (plansource=plansource@entry=0x619000038080, boundParams=0x0, owner=owner@entry=0x62d0000e7ef8, queryEnv=0x0) at plancache.c:1190
#14 0x0000564c1e0b6d68 in _SPI_execute_plan (plan=plan@entry=0x619000048980, options=options@entry=0x7fff1b28fb20, snapshot=snapshot@entry=0x0, crosscheck_snapshot=crosscheck_snapshot@entry=0x0, fire_triggers=fire_triggers@entry=true)
    at spi.c:2577
#15 0x0000564c1e0b7a6a in SPI_execute_plan_with_paramlist (plan=0x619000048980, params=<optimized out>, read_only=read_only@entry=false, tcount=0) at spi.c:751
#16 0x00007f4f4a61acaf in exec_stmt_execsql (estate=estate@entry=0x7fff1b28ff30, stmt=stmt@entry=0x625000178808) at pl_exec.c:4295
#17 0x00007f4f4a620cd5 in exec_stmts (estate=estate@entry=0x7fff1b28ff30, stmts=0x625000178618) at pl_exec.c:2092
#18 0x00007f4f4a622738 in exec_stmt_block (estate=estate@entry=0x7fff1b28ff30, block=block@entry=0x6250005f5598) at pl_exec.c:1943
#19 0x00007f4f4a62299b in exec_toplevel_block (estate=estate@entry=0x7fff1b28ff30, block=0x6250005f5598) at pl_exec.c:1634
#20 0x00007f4f4a6236ff in plpgsql_exec_function (func=func@entry=0x62d0000e7ae8, fcinfo=fcinfo@entry=0x625000078200, simple_eval_estate=simple_eval_estate@entry=0x0, simple_eval_resowner=simple_eval_resowner@entry=0x0,
    procedure_resowner=procedure_resowner@entry=0x0, atomic=<optimized out>) at pl_exec.c:623
#21 0x00007f4f4a64c925 in plpgsql_call_handler (fcinfo=<optimized out>) at pl_handler.c:277
#22 0x0000564c1dfafa01 in ExecMakeTableFunctionResult (setexpr=0x625000140768, econtext=0x625000140638, argContext=<optimized out>, expectedDesc=<optimized out>, randomAccess=<optimized out>) at execSRF.c:234
#23 0x0000564c1e0031d6 in FunctionNext (node=0x625000140428) at nodeFunctionscan.c:94
#24 0x0000564c1dfb2dbc in ExecScanFetch (node=node@entry=0x625000140428, accessMtd=accessMtd@entry=0x564c1e002df1 <FunctionNext>, recheckMtd=recheckMtd@entry=0x564c1e002c6c <FunctionRecheck>) at execScan.c:131
#25 0x0000564c1dfb2f68 in ExecScan (node=0x625000140428, accessMtd=accessMtd@entry=0x564c1e002df1 <FunctionNext>, recheckMtd=recheckMtd@entry=0x564c1e002c6c <FunctionRecheck>) at execScan.c:180
#26 0x0000564c1e002d10 in ExecFunctionScan (pstate=<optimized out>) at nodeFunctionscan.c:269
#27 0x0000564c1dfa706c in ExecProcNodeFirst (node=0x625000140428) at execProcnode.c:464
#28 0x0000564c1df83065 in ExecProcNode (node=node@entry=0x625000140428) at ../../../src/include/executor/executor.h:274
#29 0x0000564c1df84884 in ExecutePlan (queryDesc=queryDesc@entry=0x619000042080, operation=operation@entry=CMD_SELECT, sendTuples=sendTuples@entry=true, numberTuples=numberTuples@entry=0, direction=direction@entry=ForwardScanDirection,
    dest=dest@entry=0x62500066e400) at execMain.c:1649
#30 0x0000564c1df87170 in standard_ExecutorRun (queryDesc=0x619000042080, direction=ForwardScanDirection, count=0, execute_once=execute_once@entry=false) at execMain.c:361
#31 0x0000564c1df871f4 in ExecutorRun (queryDesc=queryDesc@entry=0x619000042080, direction=direction@entry=ForwardScanDirection, count=count@entry=0, execute_once=execute_once@entry=false) at execMain.c:307
#32 0x0000564c1e6f6661 in PortalRunSelect (portal=portal@entry=0x625000034a00, forward=forward@entry=true, count=0, count@entry=9223372036854775807, dest=dest@entry=0x62500066e400) at pquery.c:922
#33 0x0000564c1e6fc235 in PortalRun (portal=portal@entry=0x625000034a00, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x62500066e400,
    altdest=altdest@entry=0x62500066e400, qc=<optimized out>) at pquery.c:766
#34 0x0000564c1e6f06fb in exec_simple_query (query_string=query_string@entry=0x625000007a00 "SELECT * FROM f2();") at postgres.c:1278
#35 0x0000564c1e6f5180 in PostgresMain (dbname=dbname@entry=0x62900001b3f0 "test", username=username@entry=0x62900001b3d8 "test") at postgres.c:4767
#36 0x0000564c1e6e42dd in BackendMain (startup_data=startup_data@entry=0x7fff1b290c30 "", startup_data_len=startup_data_len@entry=4) at backend_startup.c:105
#37 0x0000564c1e4962f4 in postmaster_child_launch (child_type=child_type@entry=B_BACKEND, startup_data=startup_data@entry=0x7fff1b290c30 "", startup_data_len=startup_data_len@entry=4, client_sock=client_sock@entry=0x7fff1b291360)
    at launch_backend.c:277
#38 0x0000564c1e49fd7c in BackendStartup (client_sock=client_sock@entry=0x7fff1b291360) at postmaster.c:3594
#39 0x0000564c1e4a077e in ServerLoop () at postmaster.c:1676
#40 0x0000564c1e4a2da1 in PostmasterMain (argc=argc@entry=3, argv=argv@entry=0x603000000310) at postmaster.c:1374
#41 0x0000564c1e102bee in main (argc=3, argv=0x603000000310) at main.c:199

OS:

debian-12

pg_duckdb Version (if built from source use commit hash):

5f2524e

Postgres Version (if built from source use commit hash):

05676d87e2e69a889abf75ce4f0c1bedde9ed71f

Hardware:

No response

Full Name:

Egor Chindyaskin

Affiliation:

Postgres Professional

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a source build

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Labels

    CRASHPostgres crashesbugSomething isn't working

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions