ChenHuajun / pg_roaringbitmap

RoaringBitmap extension for PostgreSQL
Apache License 2.0
218 stars 37 forks source link

run roaringbitmap aggregate as windows function will cause postgres crash #5

Closed ChenHuajun closed 4 years ago

ChenHuajun commented 4 years ago

run such windows function SQL will cause postgres crash

sql

with t(id,bitmap) as(
 values(1,roaringbitmap('{1}')),(2,roaringbitmap('{2}'))
)
select id,rb_and_agg(bitmap) over(order by id) from t;

log:

*** Error in `postgres: postgres postgres [local] SELECT': double free or corruption (fasttop): 0x0000000000e75b20 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x81489)[0x7fe44e152489]
/usr/pgsql-10/lib/roaringbitmap.so(rb_serialize+0x7f)[0x7fe4388f2b3f]
postgres: postgres postgres [local] SELECT[0x617808]
postgres: postgres postgres [local] SELECT[0x619303]
postgres: postgres postgres [local] SELECT(standard_ExecutorRun+0x132)[0x5f1912]
postgres: postgres postgres [local] SELECT[0x71e55b]
postgres: postgres postgres [local] SELECT(PortalRun+0x28f)[0x71f90f]
postgres: postgres postgres [local] SELECT[0x71b883]
postgres: postgres postgres [local] SELECT(PostgresMain+0xf7c)[0x71cb7c]
postgres: postgres postgres [local] SELECT[0x47b396]
postgres: postgres postgres [local] SELECT(PostmasterMain+0xecd)[0x6b318d]
postgres: postgres postgres [local] SELECT(main+0x7bf)[0x47c1bf]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7fe44e0f33d5]
...

callstack:

(gdb) bt
#0  get_container_type (type=<optimized out>, container=<optimized out>) at roaring.h:3542
#1  ra_has_run_container (ra=ra@entry=0xe75780) at roaring.c:10202
#2  0x00007fe4388edcf9 in ra_portable_header_size (ra=ra@entry=0xe75780) at roaring.c:10210
#3  0x00007fe4388edd49 in ra_portable_size_in_bytes (ra=ra@entry=0xe75780) at roaring.c:10223
#4  0x00007fe4388ede05 in roaring_bitmap_portable_size_in_bytes (ra=ra@entry=0xe75780) at roaring.c:8502
#5  0x00007fe4388f2b1c in rb_serialize (fcinfo=<optimized out>) at roaringbitmap.c:1734
#6  0x0000000000617808 in finalize_windowaggregate (winstate=winstate@entry=0xecec58, peraggstate=peraggstate@entry=0xed4f48, result=result@entry=0xed5238, 
    isnull=isnull@entry=0xed5250 "", perfuncstate=<optimized out>) at nodeWindowAgg.c:624
#7  0x0000000000619303 in eval_windowaggregates (winstate=0xecec58) at nodeWindowAgg.c:976
#8  ExecWindowAgg (pstate=0xecec58) at nodeWindowAgg.c:1746
#9  0x00000000005f1912 in ExecProcNode (node=0xecec58) at ../../../src/include/executor/executor.h:250
#10 ExecutePlan (execute_once=<optimized out>, dest=0xeb68c8, direction=<optimized out>, numberTuples=0, sendTuples=1 '\001', operation=CMD_SELECT, 
    use_parallel_mode=<optimized out>, planstate=0xecec58, estate=0xece0e8) at execMain.c:1723
#11 standard_ExecutorRun (queryDesc=0xe75368, direction=<optimized out>, count=0, execute_once=<optimized out>) at execMain.c:364
#12 0x000000000071e55b in PortalRunSelect (portal=portal@entry=0xebc0c8, forward=forward@entry=1 '\001', count=0, count@entry=9223372036854775807, dest=dest@entry=0xeb68c8)
    at pquery.c:932
#13 0x000000000071f90f in PortalRun (portal=<optimized out>, count=9223372036854775807, isTopLevel=<optimized out>, run_once=<optimized out>, dest=0xeb68c8, altdest=0xeb68c8, 
    completionTag=0x7fff3bc83e00 "") at pquery.c:773
#14 0x000000000071b883 in exec_simple_query (query_string=<optimized out>) at postgres.c:1122
#15 0x000000000071cb7c in PostgresMain (argc=<optimized out>, argv=<optimized out>, dbname=<optimized out>, username=<optimized out>) at postgres.c:4117
#16 0x000000000047b396 in BackendRun (port=0xde2540) at postmaster.c:4402
---Type <return> to continue, or q <return> to quit---
#17 BackendStartup (port=0xde2540) at postmaster.c:4074
#18 ServerLoop () at postmaster.c:1756
#19 0x00000000006b318d in PostmasterMain (argc=argc@entry=3, argv=argv@entry=0xdb3a40) at postmaster.c:1364
#20 0x000000000047c1bf in main (argc=3, argv=0xdb3a40) at main.c:228

note: tested on pg_roaringbitmap 0.3 at PG10

ChenHuajun commented 4 years ago

had fixed by https://github.com/ChenHuajun/pg_roaringbitmap/commit/5505ec0425ca0ac4f23af0fc057871ae6568430c