Server crashes when executing SELECT BSONLASTNONSORTED(NULL, 3) FROM ... · Issue #466 · documentdb/documentdb · GitHub
Skip to content

Server crashes when executing SELECT BSONLASTNONSORTED(NULL, 3) FROM ... #466

Closed

Description

@yehoto

Describe the bug

Server crashes when executing the attached test.sql script.

Environment

  • Operating system and version: Ubuntu2404
  • PostgreSQL version: 17
  • Architecture: x86_64 (64-bit)

Reproduction Steps
(Run build_documentdb.sh to build DocumentDB)

  1. Start the server using start_oss_server.sh:
PG_VERSION_USED=17 ./start_oss_server.sh -d /tmp/pgsql/data -p 5432
  1. Execute test.sql:
psql -h 127.0.0.1 -d postgres -p 5432 -f test.sql

Content of test.sql:

SET search_path TO documentdb_api,documentdb_api_catalog,documentdb_api_internal,properties;
SELECT BSONLASTNONSORTED(NULL, 3) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash'); 

Expected behavior
Expected ERROR to be shown or sql query to be successfully executed

Actual behavior
Segmentation Fault
Bactrace:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  pg_detoast_datum (datum=0x0) at fmgr.c:1834
1834            if (VARATT_IS_EXTENDED(datum))
(gdb) bt
#0  pg_detoast_datum (datum=0x0) at fmgr.c:1834
#1  0x0000767bdcec3323 in BsonOrderFinalOnSorted (fcinfo=0x7ffd14a5ef80, isSingle=false) at src/aggregation/bson_sorted_accumulator.c:1171
#2  0x00005ae0dff813a6 in finalize_aggregate (aggstate=aggstate@entry=0x5ae0e1368e50, peragg=peragg@entry=0x5ae0e136aa58, pergroupstate=<optimized out>,
    resultVal=resultVal@entry=0x5ae0e139b348, resultIsNull=resultIsNull@entry=0x5ae0e139b358) at nodeAgg.c:1119
#3  0x00005ae0dff82901 in finalize_aggregates (aggstate=aggstate@entry=0x5ae0e1368e50, peraggs=peraggs@entry=0x5ae0e136aa58, pergroup=0x5ae0e136ab28) at nodeAgg.c:1360
#4  0x00005ae0dff8383e in agg_retrieve_direct (aggstate=0x5ae0e1368e50) at nodeAgg.c:2519
#5  ExecAgg (pstate=0x5ae0e1368e50) at nodeAgg.c:2179
#6  0x00005ae0dff70d6b in ExecProcNode (node=0x5ae0e1368e50) at ../../../src/include/executor/executor.h:275
#7  ExecutePlan (dest=0x5ae0e1376f48, direction=<optimized out>, numberTuples=0, sendTuples=true, operation=CMD_SELECT, queryDesc=0x5ae0e1381bd8) at execMain.c:1648
#8  standard_ExecutorRun (queryDesc=0x5ae0e1381bd8, direction=<optimized out>, count=0, execute_once=<optimized out>) at execMain.c:360
#9  0x00005ae0e0117f8a in PortalRunSelect (portal=portal@entry=0x5ae0e1305c28, forward=forward@entry=true, count=0, count@entry=9223372036854775807,
    dest=dest@entry=0x5ae0e1376f48) at pquery.c:922
#10 0x00005ae0e0119426 in PortalRun (portal=portal@entry=0x5ae0e1305c28, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true,
    run_once=run_once@entry=true, dest=dest@entry=0x5ae0e1376f48, altdest=altdest@entry=0x5ae0e1376f48, qc=0x7ffd14a5f9f0) at pquery.c:766
#11 0x00005ae0e011585c in exec_simple_query (query_string=0x5ae0e125d148 "SELECT BSONLASTNONSORTED(NULL, 3) FROM documentdb_api.collection('db', 'bsonFirstNLastNCrash');")
    at postgres.c:1278
#12 0x00005ae0e0116c0b in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:4767
#13 0x00005ae0e0111e55 in BackendMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at backend_startup.c:105
#14 0x00005ae0e00825cf in postmaster_child_launch (child_type=child_type@entry=B_BACKEND, startup_data=startup_data@entry=0x7ffd14a5fe20 "",
    startup_data_len=startup_data_len@entry=4, client_sock=client_sock@entry=0x7ffd14a5fe40) at launch_backend.c:277
#15 0x00005ae0e0086099 in BackendStartup (client_sock=0x7ffd14a5fe40) at postmaster.c:3594
#16 ServerLoop () at postmaster.c:1676
#17 0x00005ae0e0087e31 in PostmasterMain (argc=argc@entry=5, argv=argv@entry=0x5ae0e12170f0) at postmaster.c:1374
#18 0x00005ae0dfdc5ab2 in main (argc=5, argv=0x5ae0e12170f0) at main.c:199

Best regards,
Anna Likhtinfeld
Postgres Professional (http://postgrespro.com/)

Activity

  1. visridha commented on Feb 19, 2026

    @visridha
    Contributor

    @niupre could you assign to yourself and take a look please?

  2. added theissue type on Feb 19, 2026
  3. niupre commented on Feb 20, 2026

    @niupre
    Contributor

    Ack.

  4. linked a pull request that will close this issueDocumentDB Sync 20260217 #459on Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions