Thread

  1. Re: Making jsonb_agg() faster

    Alexander Lakhin <exclusion@gmail.com> — 2025-12-13T11:00:00Z

    Hello Tom,
    
    07.12.2025 18:58, Tom Lane wrote:
    >> That’s even better than resolving my comment.
    > Cool, done like that then.
    
    I and SQLsmith have discovered that the following query:
    select jsonb_object_agg_unique_strict(i, null) over (order by i) from
               (select i from generate_series(1, 20) g(i));
    
    triggers SIGSEGV:
    Core was generated by `postgres: law regression [local] SELECT                                       '.
    Program terminated with signal SIGSEGV, Segmentation fault.
    #0  MemoryChunkGetValue (chunk=0x5af800000001) at ../../../../src/include/utils/memutils_memorychunk.h:224
    224             Assert(!HdrMaskIsExternal(chunk->hdrmask));
    (gdb) bt
    #0  MemoryChunkGetValue (chunk=0x5af800000001) at ../../../../src/include/utils/memutils_memorychunk.h:224
    #1  AllocSetAlloc (context=0x5af8d6709330, size=8, flags=<optimized out>) at aset.c:1056
    #2  0x00005af8b9b5db40 in palloc (size=size@entry=8) at mcxt.c:1386
    #3  0x00005af8b9a177e1 in datumCopy (value=100024796075024, typByVal=typByVal@entry=false, typLen=<optimized out>) at 
    datum.c:162
    #4  0x00005af8b98071a3 in eval_windowaggregates (winstate=0x5af8d66f8b00) at nodeWindowAgg.c:1053
    #5  ExecWindowAgg (pstate=0x5af8d66f8b00) at nodeWindowAgg.c:2367
    #6  0x00005af8b97c0465 in ExecProcNode (node=0x5af8d66f8b00) at ../../../src/include/executor/executor.h:319
    #7  ExecutePlan (dest=0x5af8d67025c8, direction=<optimized out>, numberTuples=0, sendTuples=true, operation=CMD_SELECT, 
    queryDesc=0x5af8d6638620)
         at execMain.c:1707
    ...
    starting from b61aa76e4.
    
    Best regards,
    Alexander