Registry Mirror
Skip to content

Conversation

@reshke

@reshke reshke commented Feb 28, 2025

Copy link
Copy Markdown
Owner

This commit adds pg_attribute_encoding entries for root partitions, During create statement, we add attribute encoding entries to catalog If the table has a parent partition, and no options or encodings are specified, we copy the parent partition's encoding entries

For partitioned table create statement, we pick
the explicitly defined column encoding for the parent over the table-level option defined for the child partition.

The storage encoding clause for a column is picked as follows:

    1. An explicit encoding clause in the ColumnDef of self/parent
    1. A column reference storage directive for this column
    1. A default column encoding in the statement
    1. Parent partition's column encoding values
    1. A default for the type.

Add attribute encodings to d+ description for root partitions

Added tests to check comlumn encoding inheritance priority

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


This commit adds pg_attribute_encoding entries for root partitions,
During create statement, we add attribute encoding entries to catalog
If the table has a parent partition, and no options or encodings are
specified, we copy the parent partition's encoding entries

For partitioned table create statement, we pick
the explicitly defined column encoding for the parent
over the table-level option defined for the child partition.

The storage encoding clause for a column is picked as follows:
 * 1. An explicit encoding clause in the ColumnDef of self/parent
 * 2. A column reference storage directive for this column
 * 3. A default column encoding in the statement
 * 4. Parent partition's column encoding values
 * 5. A default for the type.

Add attribute encodings to d+ description for root partitions

Added tests to check comlumn encoding inheritance priority
reshke added a commit that referenced this pull request Oct 26, 2026
UBSan reported an unaligned uint64_t load in GpMurmurHash64A.
Read each word with memcpy so input need not have uint64_t alignment,
while preserving the little-endian hash computation.

Sanitizer report (UBSan, instrumented build, ANALYZE on a table with
short text values):
  gp_hyperloglog.c:897:11: runtime error: load of misaligned address
  0x529000093515 for type 'uint64_t', which requires 8 byte alignment
  #0 GpMurmurHash64A gp_hyperloglog.c:897
  #1 gp_hll_add_element gp_hyperloglog.c:471
  #2 gp_hyperloglog_add_item gp_hyperloglog.c:788
  #3 compute_scalar_stats commands/analyze.c:3968
  #4 do_analyze_rel commands/analyze.c:971
  #5 analyze_rel_internal commands/analyze.c:429
Triggered by ordinary ndistinct estimation during ANALYZE: short varlena
values hashed via VARDATA_ANY have a payload offset that is not a
multiple of 8. Benign on x86_64, but undefined behavior on strictly
aligned targets.
reshke added a commit that referenced this pull request Oct 26, 2026
UBSan reported an unaligned uint16 load while parsing tuple chunks.
Copy the length into an aligned local with memcpy before adding the
header size, preserving the existing native-endian interpretation.

Sanitizer report (UBSan, instrumented build, distributed query with
Motion traffic over UDP):
  ic_udpifc.c:4572:39: runtime error: load of misaligned address
  0x52500016fa59 for type 'uint16', which requires 2 byte alignment
  #0 RecvTupleChunkUDPIFC ic_udpifc.c:4572
  #1 receiveChunksUDPIFCLoop ic_udpifc.c:4462
  #2 receiveChunksUDPIFC ic_udpifc.c:4406
  #3 RecvTupleChunkFromAnyUDPIFC ic_udpifc.c:4739
  #4 processIncomingChunks cdb/cdbmotion.c:653
  #5 RecvTupleFrom cdbmotion.c:607
  #6 execMotionUnsortedReceiver executor/nodeMotion.c:356
Reached whenever bytesProcessed walks the receive buffer past an
even offset while splitting a message into tuple chunks. Benign on
x86_64, but undefined behavior on strictly aligned targets.
tuhaihe pushed a commit that referenced this pull request Oct 28, 2026
UBSan reported an unaligned uint16 load while parsing tuple chunks.
Copy the length into an aligned local with memcpy before adding the
header size, preserving the existing native-endian interpretation.

Sanitizer report (UBSan, instrumented build, distributed query with
Motion traffic over UDP):
  ic_udpifc.c:4572:39: runtime error: load of misaligned address
  0x52500016fa59 for type 'uint16', which requires 2 byte alignment
  #0 RecvTupleChunkUDPIFC ic_udpifc.c:4572
  #1 receiveChunksUDPIFCLoop ic_udpifc.c:4462
  #2 receiveChunksUDPIFC ic_udpifc.c:4406
  #3 RecvTupleChunkFromAnyUDPIFC ic_udpifc.c:4739
  #4 processIncomingChunks cdb/cdbmotion.c:653
  #5 RecvTupleFrom cdbmotion.c:607
  #6 execMotionUnsortedReceiver executor/nodeMotion.c:356
Reached whenever bytesProcessed walks the receive buffer past an
even offset while splitting a message into tuple chunks. Benign on
x86_64, but undefined behavior on strictly aligned targets.
reshke added a commit that referenced this pull request Oct 28, 2026
UBSan reported an unaligned uint16 load while parsing tuple chunks.
Copy the length into an aligned local with memcpy before adding the
header size, preserving the existing native-endian interpretation.

Sanitizer report (UBSan, instrumented build, distributed query with
Motion traffic over UDP):
  ic_udpifc.c:4572:39: runtime error: load of misaligned address
  0x52500016fa59 for type 'uint16', which requires 2 byte alignment
  #0 RecvTupleChunkUDPIFC ic_udpifc.c:4572
  #1 receiveChunksUDPIFCLoop ic_udpifc.c:4462
  #2 receiveChunksUDPIFC ic_udpifc.c:4406
  #3 RecvTupleChunkFromAnyUDPIFC ic_udpifc.c:4739
  #4 processIncomingChunks cdb/cdbmotion.c:653
  #5 RecvTupleFrom cdbmotion.c:607
  #6 execMotionUnsortedReceiver executor/nodeMotion.c:356
Reached whenever bytesProcessed walks the receive buffer past an
even offset while splitting a message into tuple chunks. Benign on
x86_64, but undefined behavior on strictly aligned targets.
yjhjstz pushed a commit that referenced this pull request Oct 29, 2026
UBSan reported an unaligned uint64_t load in GpMurmurHash64A.
Read each word with memcpy so input need not have uint64_t alignment,
while preserving the little-endian hash computation.

Sanitizer report (UBSan, instrumented build, ANALYZE on a table with
short text values):
  gp_hyperloglog.c:897:11: runtime error: load of misaligned address
  0x529000093515 for type 'uint64_t', which requires 8 byte alignment
  #0 GpMurmurHash64A gp_hyperloglog.c:897
  #1 gp_hll_add_element gp_hyperloglog.c:471
  #2 gp_hyperloglog_add_item gp_hyperloglog.c:788
  #3 compute_scalar_stats commands/analyze.c:3968
  #4 do_analyze_rel commands/analyze.c:971
  #5 analyze_rel_internal commands/analyze.c:429
Triggered by ordinary ndistinct estimation during ANALYZE: short varlena
values hashed via VARDATA_ANY have a payload offset that is not a
multiple of 8. Benign on x86_64, but undefined behavior on strictly
aligned targets.
reshke added a commit that referenced this pull request Nov 14, 2026
A replicated data-modifying CTE with ORDER BY reaches the sorted receiver with motionType GATHER_SINGLE, sendSorted set, and a non-NULL merge heap. It tripped the nodeMotion.c:441 assertion, which only allowed GATHER. Permit GATHER_SINGLE while retaining the sendSorted and heap checks.

GDB backtrace (verbatim):
#0  0x000079fa0d69ebec in pthread_kill () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x000079fa0d64527e in raise () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x000079fa0d6288ff in abort () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x0000646474bc5726 in ExceptionalCondition (conditionName=conditionName@entry=0x6464754da9a0 "motion->motionType == MOTIONTYPE_GATHER && motion->sendSorted && hp != NULL", fileName=fileName@entry=0x646475445062 "nodeMotion.c", lineNumber=lineNumber@entry=441) at assert.c:42
#4  0x0000646474ef5260 in execMotionSortedReceiver (node=0x6464a0549f48) at nodeMotion.c:441
#5  ExecMotion (pstate=0x6464a0549f48) at nodeMotion.c:152
#6  0x0000646474e9cd8d in ExecProcNodeGPDB (node=0x6464a0549f48) at execProcnode.c:672
apache#7  ExecProcNodeFirst (node=0x6464a0549f48) at execProcnode.c:633
apache#8  0x0000646474e91e6a in ExecProcNode (node=0x6464a0549f48) at ../../../src/include/executor/executor.h:305
apache#9  ExecutePlan (queryDesc=queryDesc@entry=0x6464a0453610, use_parallel_mode=<optimized out>, use_parallel_mode@entry=false, operation=operation@entry=CMD_SELECT, sendTuples=sendTuples@entry=true, numberTuples=numberTuples@entry=0, direction=direction@entry=ForwardScanDirection, dest=0x6464a0453580, execute_once=true) at execMain.c:2899
#10 0x0000646474e928a3 in standard_ExecutorRun (queryDesc=0x6464a0453610, direction=ForwardScanDirection, count=0, execute_once=true) at execMain.c:1037
apache#11 0x0000646474e92ffd in ExecutorRun (queryDesc=queryDesc@entry=0x6464a0453610, direction=direction@entry=ForwardScanDirection, count=count@entry=0, execute_once=execute_once@entry=true) at execMain.c:845
apache#12 0x00006464751738a8 in ProcessQuery (portal=portal@entry=0x6464a04ad358, stmt=stmt@entry=0x6464a05671f8, params=<optimized out>, queryEnv=0x0, dest=dest@entry=0x6464a0453580, qc=qc@entry=0x7fff171201c0, sourceText=<optimized out>) at pquery.c:251
apache#13 0x0000646475174022 in PortalRunMulti (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=true, dest=dest@entry=0x6464a0453580, altdest=0x6464757f90a0 <donothingDR>, qc=qc@entry=0x7fff171201c0) at pquery.c:1497
apache#14 0x0000646475174247 in FillPortalStore (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true) at pquery.c:1241
apache#15 0x00006464751759dd in PortalRun (portal=portal@entry=0x6464a04ad358, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x6464a0567308, altdest=altdest@entry=0x6464a0567308, qc=0x7fff171203e0) at pquery.c:975
apache#16 0x000064647517025e in exec_simple_query (query_string=0x6464a04138c8 "WITH ins AS (INSERT INTO rep_order_assert VALUES (1),(1) RETURNING v) SELECT v FROM ins ORDER BY v;") at postgres.c:2008
apache#17 0x0000646475172a87 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:5933
apache#18 0x00006464750a4aab in BackendRun (port=0x6464a044eec0) at postmaster.c:5095
apache#19 BackendStartup (port=0x6464a044eec0) at postmaster.c:4805
apache#20 ServerLoop () at postmaster.c:2107
apache#21 0x00006464750a5a8b in PostmasterMain (argc=argc@entry=7, argv=argv@entry=0x6464a040cee0) at postmaster.c:1750
apache#22 0x0000646474bd9f3d in main (argc=7, argv=0x6464a040cee0) at main.c:260
reshke added a commit that referenced this pull request Nov 14, 2026
A replicated data-modifying CTE with ORDER BY reaches the sorted receiver with motionType GATHER_SINGLE, sendSorted set, and a non-NULL merge heap. It tripped the nodeMotion.c:441 assertion, which only allowed GATHER. Permit GATHER_SINGLE while retaining the sendSorted and heap checks.

GDB backtrace (verbatim):
#0  0x000079fa0d69ebec in pthread_kill () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x000079fa0d64527e in raise () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x000079fa0d6288ff in abort () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x0000646474bc5726 in ExceptionalCondition (conditionName=conditionName@entry=0x6464754da9a0 "motion->motionType == MOTIONTYPE_GATHER && motion->sendSorted && hp != NULL", fileName=fileName@entry=0x646475445062 "nodeMotion.c", lineNumber=lineNumber@entry=441) at assert.c:42
#4  0x0000646474ef5260 in execMotionSortedReceiver (node=0x6464a0549f48) at nodeMotion.c:441
#5  ExecMotion (pstate=0x6464a0549f48) at nodeMotion.c:152
#6  0x0000646474e9cd8d in ExecProcNodeGPDB (node=0x6464a0549f48) at execProcnode.c:672
apache#7  ExecProcNodeFirst (node=0x6464a0549f48) at execProcnode.c:633
apache#8  0x0000646474e91e6a in ExecProcNode (node=0x6464a0549f48) at ../../../src/include/executor/executor.h:305
apache#9  ExecutePlan (queryDesc=queryDesc@entry=0x6464a0453610, use_parallel_mode=<optimized out>, use_parallel_mode@entry=false, operation=operation@entry=CMD_SELECT, sendTuples=sendTuples@entry=true, numberTuples=numberTuples@entry=0, direction=direction@entry=ForwardScanDirection, dest=0x6464a0453580, execute_once=true) at execMain.c:2899
#10 0x0000646474e928a3 in standard_ExecutorRun (queryDesc=0x6464a0453610, direction=ForwardScanDirection, count=0, execute_once=true) at execMain.c:1037
apache#11 0x0000646474e92ffd in ExecutorRun (queryDesc=queryDesc@entry=0x6464a0453610, direction=direction@entry=ForwardScanDirection, count=count@entry=0, execute_once=execute_once@entry=true) at execMain.c:845
apache#12 0x00006464751738a8 in ProcessQuery (portal=portal@entry=0x6464a04ad358, stmt=stmt@entry=0x6464a05671f8, params=<optimized out>, queryEnv=0x0, dest=dest@entry=0x6464a0453580, qc=qc@entry=0x7fff171201c0, sourceText=<optimized out>) at pquery.c:251
apache#13 0x0000646475174022 in PortalRunMulti (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=true, dest=dest@entry=0x6464a0453580, altdest=0x6464757f90a0 <donothingDR>, qc=qc@entry=0x7fff171201c0) at pquery.c:1497
apache#14 0x0000646475174247 in FillPortalStore (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true) at pquery.c:1241
apache#15 0x00006464751759dd in PortalRun (portal=portal@entry=0x6464a04ad358, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x6464a0567308, altdest=altdest@entry=0x6464a0567308, qc=0x7fff171203e0) at pquery.c:975
apache#16 0x000064647517025e in exec_simple_query (query_string=0x6464a04138c8 "WITH ins AS (INSERT INTO rep_order_assert VALUES (1),(1) RETURNING v) SELECT v FROM ins ORDER BY v;") at postgres.c:2008
apache#17 0x0000646475172a87 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:5933
apache#18 0x00006464750a4aab in BackendRun (port=0x6464a044eec0) at postmaster.c:5095
apache#19 BackendStartup (port=0x6464a044eec0) at postmaster.c:4805
apache#20 ServerLoop () at postmaster.c:2107
apache#21 0x00006464750a5a8b in PostmasterMain (argc=argc@entry=7, argv=argv@entry=0x6464a040cee0) at postmaster.c:1750
apache#22 0x0000646474bd9f3d in main (argc=7, argv=0x6464a040cee0) at main.c:260
reshke pushed a commit that referenced this pull request Nov 16, 2026
1. TruncateMultiXact() performs the SLRU truncations in a critical
section. Deleting the SLRU segments calls ForwardSyncRequest(), which
will try to compact the request queue if it's full
(CompactCheckpointerRequestQueue()). That in turn allocates memory,
which is not allowed in a critical section. Backtrace:

    TRAP: failed Assert("CritSectionCount == 0 || (context)->allowInCritSection"), File: "../src/backend/utils/mmgr/mcxt.c", Line: 1353, PID: 920981
    postgres: autovacuum worker template0(ExceptionalCondition+0x6e)[0x560a501e866e]
    postgres: autovacuum worker template0(+0x5dce3d)[0x560a50217e3d]
    postgres: autovacuum worker template0(ForwardSyncRequest+0x8e)[0x560a4ffec95e]
    postgres: autovacuum worker template0(RegisterSyncRequest+0x2b)[0x560a50091eeb]
    postgres: autovacuum worker template0(+0x187b0a)[0x560a4fdc2b0a]
    postgres: autovacuum worker template0(SlruDeleteSegment+0x101)[0x560a4fdc2ab1]
    postgres: autovacuum worker template0(TruncateMultiXact+0x2fb)[0x560a4fdbde1b]
    postgres: autovacuum worker template0(vac_update_datfrozenxid+0x4b3)[0x560a4febd2f3]
    postgres: autovacuum worker template0(+0x3adf66)[0x560a4ffe8f66]
    postgres: autovacuum worker template0(AutoVacWorkerMain+0x3ed)[0x560a4ffe7c2d]
    postgres: autovacuum worker template0(+0x3b1ead)[0x560a4ffecead]
    postgres: autovacuum worker template0(+0x3b620e)[0x560a4fff120e]
    postgres: autovacuum worker template0(+0x3b3fbb)[0x560a4ffeefbb]
    postgres: autovacuum worker template0(+0x2f724e)[0x560a4ff3224e]
    /lib/x86_64-linux-gnu/libc.so.6(+0x27c8a)[0x7f62cc642c8a]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85)[0x7f62cc642d45]
    postgres: autovacuum worker template0(_start+0x21)[0x560a4fd16f31]

To fix, bail out in CompactCheckpointerRequestQueue() without doing
anything, if it's called in a critical section. That covers the above
call path, as well as any other similar cases where
RegisterSyncRequest might be called in a critical section.

2. After fixing that, another problem became apparent: Autovacuum
process doing that truncation can deadlock with the checkpointer
process. TruncateMultiXact() sets "MyProc->delayChkptFlags |=
DELAY_CHKPT_START". If the sync request queue is full and cannot be
compacted, the process will repeatedly sleep and retry, until there is
room in the queue. However, if the checkpointer is trying to start a
checkpoint at the same time, and is waiting for the DELAY_CHKPT_START
processes to finish, the queue will never shrink.

More concretely, the autovacuum process is stuck here:

    #0  0x00007fc934926dc3 in epoll_wait () from /lib/x86_64-linux-gnu/libc.so.6
    #1  0x000056220b24348b in WaitEventSetWaitBlock (set=0x56220c2e4b50, occurred_events=0x7ffe7856d040, nevents=1, cur_timeout=<optimized out>) at ../src/backend/storage/ipc/latch.c:1570
    #2  WaitEventSetWait (set=0x56220c2e4b50, timeout=timeout@entry=10, occurred_events=<optimized out>, occurred_events@entry=0x7ffe7856d040, nevents=nevents@entry=1,
        wait_event_info=wait_event_info@entry=150994949) at ../src/backend/storage/ipc/latch.c:1516
    #3  0x000056220b243224 in WaitLatch (latch=<optimized out>, latch@entry=0x0, wakeEvents=wakeEvents@entry=40, timeout=timeout@entry=10, wait_event_info=wait_event_info@entry=150994949)
        at ../src/backend/storage/ipc/latch.c:538
    #4  0x000056220b26cf46 in RegisterSyncRequest (ftag=ftag@entry=0x7ffe7856d0a0, type=type@entry=SYNC_FORGET_REQUEST, retryOnError=true) at ../src/backend/storage/sync/sync.c:614
    #5  0x000056220af9db0a in SlruInternalDeleteSegment (ctl=ctl@entry=0x56220b7beb60 <MultiXactMemberCtlData>, segno=segno@entry=11350) at ../src/backend/access/transam/slru.c:1495
    #6  0x000056220af9dab1 in SlruDeleteSegment (ctl=ctl@entry=0x56220b7beb60 <MultiXactMemberCtlData>, segno=segno@entry=11350) at ../src/backend/access/transam/slru.c:1566
    apache#7  0x000056220af98e1b in PerformMembersTruncation (oldestOffset=<optimized out>, newOldestOffset=<optimized out>) at ../src/backend/access/transam/multixact.c:3006
    apache#8  TruncateMultiXact (newOldestMulti=newOldestMulti@entry=3221225472, newOldestMultiDB=newOldestMultiDB@entry=4) at ../src/backend/access/transam/multixact.c:3201
    apache#9  0x000056220b098303 in vac_truncate_clog (frozenXID=749, minMulti=<optimized out>, lastSaneFrozenXid=749, lastSaneMinMulti=3221225472) at ../src/backend/commands/vacuum.c:1917
    #10 vac_update_datfrozenxid () at ../src/backend/commands/vacuum.c:1760
    apache#11 0x000056220b1c3f76 in do_autovacuum () at ../src/backend/postmaster/autovacuum.c:2550
    apache#12 0x000056220b1c2c3d in AutoVacWorkerMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at ../src/backend/postmaster/autovacuum.c:1569

and the checkpointer is stuck here:

    #0  0x00007fc9348ebf93 in clock_nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
    #1  0x00007fc9348fe353 in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
    #2  0x000056220b40ecb4 in pg_usleep (microsec=microsec@entry=10000) at ../src/port/pgsleep.c:50
    #3  0x000056220afb43c3 in CreateCheckPoint (flags=flags@entry=108) at ../src/backend/access/transam/xlog.c:7098
    #4  0x000056220b1c6e86 in CheckpointerMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at ../src/backend/postmaster/checkpointer.c:464

To fix, add AbsorbSyncRequests() to the loops where the checkpointer
waits for DELAY_CHKPT_START or DELAY_CHKPT_COMPLETE operations to
finish.

Backpatch to v14. Before that, SLRU deletion didn't call
RegisterSyncRequest, which avoided this failure. I'm not sure if there
are other similar scenarios on older versions, but we haven't had
any such reports.

Discussion: https://www.postgresql.org/message-id/ccc66933-31c1-4f6a-bf4b-45fef0d4f22e@iki.fi
reshke pushed a commit that referenced this pull request Nov 17, 2026
1. TruncateMultiXact() performs the SLRU truncations in a critical
section. Deleting the SLRU segments calls ForwardSyncRequest(), which
will try to compact the request queue if it's full
(CompactCheckpointerRequestQueue()). That in turn allocates memory,
which is not allowed in a critical section. Backtrace:

    TRAP: failed Assert("CritSectionCount == 0 || (context)->allowInCritSection"), File: "../src/backend/utils/mmgr/mcxt.c", Line: 1353, PID: 920981
    postgres: autovacuum worker template0(ExceptionalCondition+0x6e)[0x560a501e866e]
    postgres: autovacuum worker template0(+0x5dce3d)[0x560a50217e3d]
    postgres: autovacuum worker template0(ForwardSyncRequest+0x8e)[0x560a4ffec95e]
    postgres: autovacuum worker template0(RegisterSyncRequest+0x2b)[0x560a50091eeb]
    postgres: autovacuum worker template0(+0x187b0a)[0x560a4fdc2b0a]
    postgres: autovacuum worker template0(SlruDeleteSegment+0x101)[0x560a4fdc2ab1]
    postgres: autovacuum worker template0(TruncateMultiXact+0x2fb)[0x560a4fdbde1b]
    postgres: autovacuum worker template0(vac_update_datfrozenxid+0x4b3)[0x560a4febd2f3]
    postgres: autovacuum worker template0(+0x3adf66)[0x560a4ffe8f66]
    postgres: autovacuum worker template0(AutoVacWorkerMain+0x3ed)[0x560a4ffe7c2d]
    postgres: autovacuum worker template0(+0x3b1ead)[0x560a4ffecead]
    postgres: autovacuum worker template0(+0x3b620e)[0x560a4fff120e]
    postgres: autovacuum worker template0(+0x3b3fbb)[0x560a4ffeefbb]
    postgres: autovacuum worker template0(+0x2f724e)[0x560a4ff3224e]
    /lib/x86_64-linux-gnu/libc.so.6(+0x27c8a)[0x7f62cc642c8a]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85)[0x7f62cc642d45]
    postgres: autovacuum worker template0(_start+0x21)[0x560a4fd16f31]

To fix, bail out in CompactCheckpointerRequestQueue() without doing
anything, if it's called in a critical section. That covers the above
call path, as well as any other similar cases where
RegisterSyncRequest might be called in a critical section.

2. After fixing that, another problem became apparent: Autovacuum
process doing that truncation can deadlock with the checkpointer
process. TruncateMultiXact() sets "MyProc->delayChkptFlags |=
DELAY_CHKPT_START". If the sync request queue is full and cannot be
compacted, the process will repeatedly sleep and retry, until there is
room in the queue. However, if the checkpointer is trying to start a
checkpoint at the same time, and is waiting for the DELAY_CHKPT_START
processes to finish, the queue will never shrink.

More concretely, the autovacuum process is stuck here:

    #0  0x00007fc934926dc3 in epoll_wait () from /lib/x86_64-linux-gnu/libc.so.6
    #1  0x000056220b24348b in WaitEventSetWaitBlock (set=0x56220c2e4b50, occurred_events=0x7ffe7856d040, nevents=1, cur_timeout=<optimized out>) at ../src/backend/storage/ipc/latch.c:1570
    #2  WaitEventSetWait (set=0x56220c2e4b50, timeout=timeout@entry=10, occurred_events=<optimized out>, occurred_events@entry=0x7ffe7856d040, nevents=nevents@entry=1,
        wait_event_info=wait_event_info@entry=150994949) at ../src/backend/storage/ipc/latch.c:1516
    #3  0x000056220b243224 in WaitLatch (latch=<optimized out>, latch@entry=0x0, wakeEvents=wakeEvents@entry=40, timeout=timeout@entry=10, wait_event_info=wait_event_info@entry=150994949)
        at ../src/backend/storage/ipc/latch.c:538
    #4  0x000056220b26cf46 in RegisterSyncRequest (ftag=ftag@entry=0x7ffe7856d0a0, type=type@entry=SYNC_FORGET_REQUEST, retryOnError=true) at ../src/backend/storage/sync/sync.c:614
    #5  0x000056220af9db0a in SlruInternalDeleteSegment (ctl=ctl@entry=0x56220b7beb60 <MultiXactMemberCtlData>, segno=segno@entry=11350) at ../src/backend/access/transam/slru.c:1495
    #6  0x000056220af9dab1 in SlruDeleteSegment (ctl=ctl@entry=0x56220b7beb60 <MultiXactMemberCtlData>, segno=segno@entry=11350) at ../src/backend/access/transam/slru.c:1566
    apache#7  0x000056220af98e1b in PerformMembersTruncation (oldestOffset=<optimized out>, newOldestOffset=<optimized out>) at ../src/backend/access/transam/multixact.c:3006
    apache#8  TruncateMultiXact (newOldestMulti=newOldestMulti@entry=3221225472, newOldestMultiDB=newOldestMultiDB@entry=4) at ../src/backend/access/transam/multixact.c:3201
    apache#9  0x000056220b098303 in vac_truncate_clog (frozenXID=749, minMulti=<optimized out>, lastSaneFrozenXid=749, lastSaneMinMulti=3221225472) at ../src/backend/commands/vacuum.c:1917
    #10 vac_update_datfrozenxid () at ../src/backend/commands/vacuum.c:1760
    apache#11 0x000056220b1c3f76 in do_autovacuum () at ../src/backend/postmaster/autovacuum.c:2550
    apache#12 0x000056220b1c2c3d in AutoVacWorkerMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at ../src/backend/postmaster/autovacuum.c:1569

and the checkpointer is stuck here:

    #0  0x00007fc9348ebf93 in clock_nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
    #1  0x00007fc9348fe353 in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
    #2  0x000056220b40ecb4 in pg_usleep (microsec=microsec@entry=10000) at ../src/port/pgsleep.c:50
    #3  0x000056220afb43c3 in CreateCheckPoint (flags=flags@entry=108) at ../src/backend/access/transam/xlog.c:7098
    #4  0x000056220b1c6e86 in CheckpointerMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at ../src/backend/postmaster/checkpointer.c:464

To fix, add AbsorbSyncRequests() to the loops where the checkpointer
waits for DELAY_CHKPT_START or DELAY_CHKPT_COMPLETE operations to
finish.

Backpatch to v14. Before that, SLRU deletion didn't call
RegisterSyncRequest, which avoided this failure. I'm not sure if there
are other similar scenarios on older versions, but we haven't had
any such reports.

Discussion: https://www.postgresql.org/message-id/ccc66933-31c1-4f6a-bf4b-45fef0d4f22e@iki.fi
reshke pushed a commit that referenced this pull request Nov 18, 2026
(cherry picked from commit c0730c2f0c58af4a7b12d626c21596e8b4f35864)

Sampling a CO table walks every projected column to the target row using
one shared logical counter, which assumes each column has a datum for
every row.  Missing-mode ADD COLUMN breaks that: the new column's file
starts after its lastrownum, so the walk overshoots and runs off the end
of the segfile.  Take the row number the anchor column produced and fetch
the other columns at that same physical row instead of recomputing a
target per column.

This is the hazard docs/gp7-avoid-table-rewrite-commit-correlation.md
flagged as the easiest one to miss, and it is real: ANALYZE on an AOCO
table whose added column is *partially* present crashes the segment.

  CREATE TABLE t(a int, b int) USING ao_column;   -- 200000 rows
  ALTER TABLE t ADD COLUMN c int DEFAULT 7;
  INSERT INTO t SELECT i, i%100, i FROM generate_series(200001,210000) i;
  ANALYZE t;                                      -- QE dies

The core shows exactly the coordinate mismatch, at the pg_unreachable()
in aocs_gettuple():

  #2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  #3 aocs_get_target_tuple
  #4 aoco_acquire_sample_rows
  (gdb) p startrow                                        -> 69893
  (gdb) p phyrow                                          -> 69944
  (gdb) p scan->columnScanInfo.ds[2]->blockFirstRowNum     -> 66701
  (gdb) p attnum_to_rownum[2 * 128 + segno]                -> 66700

startrow/targrow are logical positions driven by the anchor, phyrow is a
physical row number, and column c's file only begins at row 66701 -- so
walking c by the logical counter looks for a row 66700 rows past its end.

The case upstream's own test covers -- a column added and never written
to afterwards -- does not crash, because then every row is missing and
the check added by 3986f92616 returns the missing value before any walk
happens.  It takes a *partially* present column to reach the walk.

Ported to the PG16 kernel:
- aocs_gettuple_column() keeps cbdb's AOTupleId-by-value local (that
  difference predates this commit); only upstream's rowstoprocess
  initialisation is taken, which the new branch needs.
- the two restructured call sites in aocs_gettuple() take upstream's
  shape, with cbdb's "goto out" restored -- it has to update the scan's
  tracking variables before returning.
- pgstat_count_buffer_read_ao() was dropped from all three places the
  merge reintroduced it; it belongs to 67da2c369b, which cbdb does not
  carry.

The test additions needed one cbdb-specific correction:
gp_acquire_sample_rows() has NUM_SAMPLE_FIXED_COLS = 4 here, not 3 --
cbdb returns an extra stadistinct_array column -- so every
"as (totalrows, totaldeadrows, oversized_cols_length, ...)" list in the
file gains it.  Without that even a plain three-column ao_row table fails
with "Returned row contains 7 attributes, but query expects 6".  The
output template was rebuilt from an ao_row run and verified against both
the _row and _column variants.

Verified: AO/AOCS regression 24/24, AO isolation2 136/136 plus
ao_partial_scan.  ANALYZE on the reproducer above now reports
reltuples = 210000 exactly, and pg_stats for the text column added the
same way has n_distinct = 2, matching the data.
tuhaihe pushed a commit that referenced this pull request Nov 20, 2026
A replicated data-modifying CTE with ORDER BY reaches the sorted receiver with motionType GATHER_SINGLE, sendSorted set, and a non-NULL merge heap. It tripped the nodeMotion.c:441 assertion, which only allowed GATHER. Permit GATHER_SINGLE while retaining the sendSorted and heap checks.

GDB backtrace (verbatim):
#0  0x000079fa0d69ebec in pthread_kill () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x000079fa0d64527e in raise () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x000079fa0d6288ff in abort () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x0000646474bc5726 in ExceptionalCondition (conditionName=conditionName@entry=0x6464754da9a0 "motion->motionType == MOTIONTYPE_GATHER && motion->sendSorted && hp != NULL", fileName=fileName@entry=0x646475445062 "nodeMotion.c", lineNumber=lineNumber@entry=441) at assert.c:42
#4  0x0000646474ef5260 in execMotionSortedReceiver (node=0x6464a0549f48) at nodeMotion.c:441
#5  ExecMotion (pstate=0x6464a0549f48) at nodeMotion.c:152
#6  0x0000646474e9cd8d in ExecProcNodeGPDB (node=0x6464a0549f48) at execProcnode.c:672
apache#7  ExecProcNodeFirst (node=0x6464a0549f48) at execProcnode.c:633
apache#8  0x0000646474e91e6a in ExecProcNode (node=0x6464a0549f48) at ../../../src/include/executor/executor.h:305
apache#9  ExecutePlan (queryDesc=queryDesc@entry=0x6464a0453610, use_parallel_mode=<optimized out>, use_parallel_mode@entry=false, operation=operation@entry=CMD_SELECT, sendTuples=sendTuples@entry=true, numberTuples=numberTuples@entry=0, direction=direction@entry=ForwardScanDirection, dest=0x6464a0453580, execute_once=true) at execMain.c:2899
#10 0x0000646474e928a3 in standard_ExecutorRun (queryDesc=0x6464a0453610, direction=ForwardScanDirection, count=0, execute_once=true) at execMain.c:1037
apache#11 0x0000646474e92ffd in ExecutorRun (queryDesc=queryDesc@entry=0x6464a0453610, direction=direction@entry=ForwardScanDirection, count=count@entry=0, execute_once=execute_once@entry=true) at execMain.c:845
apache#12 0x00006464751738a8 in ProcessQuery (portal=portal@entry=0x6464a04ad358, stmt=stmt@entry=0x6464a05671f8, params=<optimized out>, queryEnv=0x0, dest=dest@entry=0x6464a0453580, qc=qc@entry=0x7fff171201c0, sourceText=<optimized out>) at pquery.c:251
apache#13 0x0000646475174022 in PortalRunMulti (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=true, dest=dest@entry=0x6464a0453580, altdest=0x6464757f90a0 <donothingDR>, qc=qc@entry=0x7fff171201c0) at pquery.c:1497
apache#14 0x0000646475174247 in FillPortalStore (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true) at pquery.c:1241
apache#15 0x00006464751759dd in PortalRun (portal=portal@entry=0x6464a04ad358, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x6464a0567308, altdest=altdest@entry=0x6464a0567308, qc=0x7fff171203e0) at pquery.c:975
apache#16 0x000064647517025e in exec_simple_query (query_string=0x6464a04138c8 "WITH ins AS (INSERT INTO rep_order_assert VALUES (1),(1) RETURNING v) SELECT v FROM ins ORDER BY v;") at postgres.c:2008
apache#17 0x0000646475172a87 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:5933
apache#18 0x00006464750a4aab in BackendRun (port=0x6464a044eec0) at postmaster.c:5095
apache#19 BackendStartup (port=0x6464a044eec0) at postmaster.c:4805
apache#20 ServerLoop () at postmaster.c:2107
apache#21 0x00006464750a5a8b in PostmasterMain (argc=argc@entry=7, argv=argv@entry=0x6464a040cee0) at postmaster.c:1750
apache#22 0x0000646474bd9f3d in main (argc=7, argv=0x6464a040cee0) at main.c:260
tuhaihe pushed a commit that referenced this pull request Nov 21, 2026
A replicated data-modifying CTE with ORDER BY reaches the sorted receiver with motionType GATHER_SINGLE, sendSorted set, and a non-NULL merge heap. It tripped the nodeMotion.c:441 assertion, which only allowed GATHER. Permit GATHER_SINGLE while retaining the sendSorted and heap checks.

GDB backtrace (verbatim):
#0  0x000079fa0d69ebec in pthread_kill () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x000079fa0d64527e in raise () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x000079fa0d6288ff in abort () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x0000646474bc5726 in ExceptionalCondition (conditionName=conditionName@entry=0x6464754da9a0 "motion->motionType == MOTIONTYPE_GATHER && motion->sendSorted && hp != NULL", fileName=fileName@entry=0x646475445062 "nodeMotion.c", lineNumber=lineNumber@entry=441) at assert.c:42
#4  0x0000646474ef5260 in execMotionSortedReceiver (node=0x6464a0549f48) at nodeMotion.c:441
#5  ExecMotion (pstate=0x6464a0549f48) at nodeMotion.c:152
#6  0x0000646474e9cd8d in ExecProcNodeGPDB (node=0x6464a0549f48) at execProcnode.c:672
apache#7  ExecProcNodeFirst (node=0x6464a0549f48) at execProcnode.c:633
apache#8  0x0000646474e91e6a in ExecProcNode (node=0x6464a0549f48) at ../../../src/include/executor/executor.h:305
apache#9  ExecutePlan (queryDesc=queryDesc@entry=0x6464a0453610, use_parallel_mode=<optimized out>, use_parallel_mode@entry=false, operation=operation@entry=CMD_SELECT, sendTuples=sendTuples@entry=true, numberTuples=numberTuples@entry=0, direction=direction@entry=ForwardScanDirection, dest=0x6464a0453580, execute_once=true) at execMain.c:2899
#10 0x0000646474e928a3 in standard_ExecutorRun (queryDesc=0x6464a0453610, direction=ForwardScanDirection, count=0, execute_once=true) at execMain.c:1037
apache#11 0x0000646474e92ffd in ExecutorRun (queryDesc=queryDesc@entry=0x6464a0453610, direction=direction@entry=ForwardScanDirection, count=count@entry=0, execute_once=execute_once@entry=true) at execMain.c:845
apache#12 0x00006464751738a8 in ProcessQuery (portal=portal@entry=0x6464a04ad358, stmt=stmt@entry=0x6464a05671f8, params=<optimized out>, queryEnv=0x0, dest=dest@entry=0x6464a0453580, qc=qc@entry=0x7fff171201c0, sourceText=<optimized out>) at pquery.c:251
apache#13 0x0000646475174022 in PortalRunMulti (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=true, dest=dest@entry=0x6464a0453580, altdest=0x6464757f90a0 <donothingDR>, qc=qc@entry=0x7fff171201c0) at pquery.c:1497
apache#14 0x0000646475174247 in FillPortalStore (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true) at pquery.c:1241
apache#15 0x00006464751759dd in PortalRun (portal=portal@entry=0x6464a04ad358, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x6464a0567308, altdest=altdest@entry=0x6464a0567308, qc=0x7fff171203e0) at pquery.c:975
apache#16 0x000064647517025e in exec_simple_query (query_string=0x6464a04138c8 "WITH ins AS (INSERT INTO rep_order_assert VALUES (1),(1) RETURNING v) SELECT v FROM ins ORDER BY v;") at postgres.c:2008
apache#17 0x0000646475172a87 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:5933
apache#18 0x00006464750a4aab in BackendRun (port=0x6464a044eec0) at postmaster.c:5095
apache#19 BackendStartup (port=0x6464a044eec0) at postmaster.c:4805
apache#20 ServerLoop () at postmaster.c:2107
apache#21 0x00006464750a5a8b in PostmasterMain (argc=argc@entry=7, argv=argv@entry=0x6464a040cee0) at postmaster.c:1750
apache#22 0x0000646474bd9f3d in main (argc=7, argv=0x6464a040cee0) at main.c:260
reshke added a commit that referenced this pull request Nov 21, 2026
* Allow sorted GatherSingle motion receivers

A replicated data-modifying CTE with ORDER BY reaches the sorted receiver with motionType GATHER_SINGLE, sendSorted set, and a non-NULL merge heap. It tripped the nodeMotion.c:441 assertion, which only allowed GATHER. Permit GATHER_SINGLE while retaining the sendSorted and heap checks.

GDB backtrace (verbatim):
#0  0x000079fa0d69ebec in pthread_kill () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x000079fa0d64527e in raise () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x000079fa0d6288ff in abort () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x0000646474bc5726 in ExceptionalCondition (conditionName=conditionName@entry=0x6464754da9a0 "motion->motionType == MOTIONTYPE_GATHER && motion->sendSorted && hp != NULL", fileName=fileName@entry=0x646475445062 "nodeMotion.c", lineNumber=lineNumber@entry=441) at assert.c:42
#4  0x0000646474ef5260 in execMotionSortedReceiver (node=0x6464a0549f48) at nodeMotion.c:441
#5  ExecMotion (pstate=0x6464a0549f48) at nodeMotion.c:152
#6  0x0000646474e9cd8d in ExecProcNodeGPDB (node=0x6464a0549f48) at execProcnode.c:672
apache#7  ExecProcNodeFirst (node=0x6464a0549f48) at execProcnode.c:633
apache#8  0x0000646474e91e6a in ExecProcNode (node=0x6464a0549f48) at ../../../src/include/executor/executor.h:305
apache#9  ExecutePlan (queryDesc=queryDesc@entry=0x6464a0453610, use_parallel_mode=<optimized out>, use_parallel_mode@entry=false, operation=operation@entry=CMD_SELECT, sendTuples=sendTuples@entry=true, numberTuples=numberTuples@entry=0, direction=direction@entry=ForwardScanDirection, dest=0x6464a0453580, execute_once=true) at execMain.c:2899
#10 0x0000646474e928a3 in standard_ExecutorRun (queryDesc=0x6464a0453610, direction=ForwardScanDirection, count=0, execute_once=true) at execMain.c:1037
apache#11 0x0000646474e92ffd in ExecutorRun (queryDesc=queryDesc@entry=0x6464a0453610, direction=direction@entry=ForwardScanDirection, count=count@entry=0, execute_once=execute_once@entry=true) at execMain.c:845
apache#12 0x00006464751738a8 in ProcessQuery (portal=portal@entry=0x6464a04ad358, stmt=stmt@entry=0x6464a05671f8, params=<optimized out>, queryEnv=0x0, dest=dest@entry=0x6464a0453580, qc=qc@entry=0x7fff171201c0, sourceText=<optimized out>) at pquery.c:251
apache#13 0x0000646475174022 in PortalRunMulti (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=true, dest=dest@entry=0x6464a0453580, altdest=0x6464757f90a0 <donothingDR>, qc=qc@entry=0x7fff171201c0) at pquery.c:1497
apache#14 0x0000646475174247 in FillPortalStore (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true) at pquery.c:1241
apache#15 0x00006464751759dd in PortalRun (portal=portal@entry=0x6464a04ad358, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x6464a0567308, altdest=altdest@entry=0x6464a0567308, qc=0x7fff171203e0) at pquery.c:975
apache#16 0x000064647517025e in exec_simple_query (query_string=0x6464a04138c8 "WITH ins AS (INSERT INTO rep_order_assert VALUES (1),(1) RETURNING v) SELECT v FROM ins ORDER BY v;") at postgres.c:2008
apache#17 0x0000646475172a87 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:5933
apache#18 0x00006464750a4aab in BackendRun (port=0x6464a044eec0) at postmaster.c:5095
apache#19 BackendStartup (port=0x6464a044eec0) at postmaster.c:4805
apache#20 ServerLoop () at postmaster.c:2107
apache#21 0x00006464750a5a8b in PostmasterMain (argc=argc@entry=7, argv=argv@entry=0x6464a040cee0) at postmaster.c:1750
apache#22 0x0000646474bd9f3d in main (argc=7, argv=0x6464a040cee0) at main.c:260

* Cover sorted GatherSingle in the WITH regression

Move the replicated writable-CTE case into the existing WITH test and
reuse its replicated table. Add one EXPLAIN (COSTS OFF) with captured
expected output, retaining both the ordered result and unsorted control.
Remove the standalone test and its separate serial schedule entry.

The tested query path is:
  WITH ins AS (INSERT INTO t_w_cte_relp VALUES (1),(1) RETURNING a)
  SELECT a FROM ins ORDER BY a;

Validation: the extracted block passed pg_regress (1/1), and its output
matched the new block in a full WITH run byte for byte. Existing fixture
and resource-output differences in that full run are left unchanged.

* Update optimizer expected output for sorted GatherSingle CTE

The optimizer regression runs the same with.sql against with_optimizer.out.
Its newly added replicated-CTE block explicitly sets optimizer=off, so this
variant must contain the captured PostgreSQL plan and result rows too.
Add that missing block without adding another SQL case or EXPLAIN.

The existing regression query is:
  WITH ins AS (INSERT INTO t_w_cte_relp VALUES (1),(1) RETURNING a)
  SELECT a FROM ins ORDER BY a;

Validation: the added block matches the previously captured and passing
pg_regress result byte for byte; expected-file selection and the optimizer
GUC gate were checked in the harness/planner sources. diff --check passes.
reshke pushed a commit that referenced this pull request Nov 21, 2026
1. TruncateMultiXact() performs the SLRU truncations in a critical
section. Deleting the SLRU segments calls ForwardSyncRequest(), which
will try to compact the request queue if it's full
(CompactCheckpointerRequestQueue()). That in turn allocates memory,
which is not allowed in a critical section. Backtrace:

    TRAP: failed Assert("CritSectionCount == 0 || (context)->allowInCritSection"), File: "../src/backend/utils/mmgr/mcxt.c", Line: 1353, PID: 920981
    postgres: autovacuum worker template0(ExceptionalCondition+0x6e)[0x560a501e866e]
    postgres: autovacuum worker template0(+0x5dce3d)[0x560a50217e3d]
    postgres: autovacuum worker template0(ForwardSyncRequest+0x8e)[0x560a4ffec95e]
    postgres: autovacuum worker template0(RegisterSyncRequest+0x2b)[0x560a50091eeb]
    postgres: autovacuum worker template0(+0x187b0a)[0x560a4fdc2b0a]
    postgres: autovacuum worker template0(SlruDeleteSegment+0x101)[0x560a4fdc2ab1]
    postgres: autovacuum worker template0(TruncateMultiXact+0x2fb)[0x560a4fdbde1b]
    postgres: autovacuum worker template0(vac_update_datfrozenxid+0x4b3)[0x560a4febd2f3]
    postgres: autovacuum worker template0(+0x3adf66)[0x560a4ffe8f66]
    postgres: autovacuum worker template0(AutoVacWorkerMain+0x3ed)[0x560a4ffe7c2d]
    postgres: autovacuum worker template0(+0x3b1ead)[0x560a4ffecead]
    postgres: autovacuum worker template0(+0x3b620e)[0x560a4fff120e]
    postgres: autovacuum worker template0(+0x3b3fbb)[0x560a4ffeefbb]
    postgres: autovacuum worker template0(+0x2f724e)[0x560a4ff3224e]
    /lib/x86_64-linux-gnu/libc.so.6(+0x27c8a)[0x7f62cc642c8a]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85)[0x7f62cc642d45]
    postgres: autovacuum worker template0(_start+0x21)[0x560a4fd16f31]

To fix, bail out in CompactCheckpointerRequestQueue() without doing
anything, if it's called in a critical section. That covers the above
call path, as well as any other similar cases where
RegisterSyncRequest might be called in a critical section.

2. After fixing that, another problem became apparent: Autovacuum
process doing that truncation can deadlock with the checkpointer
process. TruncateMultiXact() sets "MyProc->delayChkptFlags |=
DELAY_CHKPT_START". If the sync request queue is full and cannot be
compacted, the process will repeatedly sleep and retry, until there is
room in the queue. However, if the checkpointer is trying to start a
checkpoint at the same time, and is waiting for the DELAY_CHKPT_START
processes to finish, the queue will never shrink.

More concretely, the autovacuum process is stuck here:

    #0  0x00007fc934926dc3 in epoll_wait () from /lib/x86_64-linux-gnu/libc.so.6
    #1  0x000056220b24348b in WaitEventSetWaitBlock (set=0x56220c2e4b50, occurred_events=0x7ffe7856d040, nevents=1, cur_timeout=<optimized out>) at ../src/backend/storage/ipc/latch.c:1570
    #2  WaitEventSetWait (set=0x56220c2e4b50, timeout=timeout@entry=10, occurred_events=<optimized out>, occurred_events@entry=0x7ffe7856d040, nevents=nevents@entry=1,
        wait_event_info=wait_event_info@entry=150994949) at ../src/backend/storage/ipc/latch.c:1516
    #3  0x000056220b243224 in WaitLatch (latch=<optimized out>, latch@entry=0x0, wakeEvents=wakeEvents@entry=40, timeout=timeout@entry=10, wait_event_info=wait_event_info@entry=150994949)
        at ../src/backend/storage/ipc/latch.c:538
    #4  0x000056220b26cf46 in RegisterSyncRequest (ftag=ftag@entry=0x7ffe7856d0a0, type=type@entry=SYNC_FORGET_REQUEST, retryOnError=true) at ../src/backend/storage/sync/sync.c:614
    #5  0x000056220af9db0a in SlruInternalDeleteSegment (ctl=ctl@entry=0x56220b7beb60 <MultiXactMemberCtlData>, segno=segno@entry=11350) at ../src/backend/access/transam/slru.c:1495
    #6  0x000056220af9dab1 in SlruDeleteSegment (ctl=ctl@entry=0x56220b7beb60 <MultiXactMemberCtlData>, segno=segno@entry=11350) at ../src/backend/access/transam/slru.c:1566
    apache#7  0x000056220af98e1b in PerformMembersTruncation (oldestOffset=<optimized out>, newOldestOffset=<optimized out>) at ../src/backend/access/transam/multixact.c:3006
    apache#8  TruncateMultiXact (newOldestMulti=newOldestMulti@entry=3221225472, newOldestMultiDB=newOldestMultiDB@entry=4) at ../src/backend/access/transam/multixact.c:3201
    apache#9  0x000056220b098303 in vac_truncate_clog (frozenXID=749, minMulti=<optimized out>, lastSaneFrozenXid=749, lastSaneMinMulti=3221225472) at ../src/backend/commands/vacuum.c:1917
    #10 vac_update_datfrozenxid () at ../src/backend/commands/vacuum.c:1760
    apache#11 0x000056220b1c3f76 in do_autovacuum () at ../src/backend/postmaster/autovacuum.c:2550
    apache#12 0x000056220b1c2c3d in AutoVacWorkerMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at ../src/backend/postmaster/autovacuum.c:1569

and the checkpointer is stuck here:

    #0  0x00007fc9348ebf93 in clock_nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
    #1  0x00007fc9348fe353 in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
    #2  0x000056220b40ecb4 in pg_usleep (microsec=microsec@entry=10000) at ../src/port/pgsleep.c:50
    #3  0x000056220afb43c3 in CreateCheckPoint (flags=flags@entry=108) at ../src/backend/access/transam/xlog.c:7098
    #4  0x000056220b1c6e86 in CheckpointerMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at ../src/backend/postmaster/checkpointer.c:464

To fix, add AbsorbSyncRequests() to the loops where the checkpointer
waits for DELAY_CHKPT_START or DELAY_CHKPT_COMPLETE operations to
finish.

Backpatch to v14. Before that, SLRU deletion didn't call
RegisterSyncRequest, which avoided this failure. I'm not sure if there
are other similar scenarios on older versions, but we haven't had
any such reports.

Discussion: https://www.postgresql.org/message-id/ccc66933-31c1-4f6a-bf4b-45fef0d4f22e@iki.fi
reshke pushed a commit that referenced this pull request Nov 21, 2026
1. TruncateMultiXact() performs the SLRU truncations in a critical
section. Deleting the SLRU segments calls ForwardSyncRequest(), which
will try to compact the request queue if it's full
(CompactCheckpointerRequestQueue()). That in turn allocates memory,
which is not allowed in a critical section. Backtrace:

    TRAP: failed Assert("CritSectionCount == 0 || (context)->allowInCritSection"), File: "../src/backend/utils/mmgr/mcxt.c", Line: 1353, PID: 920981
    postgres: autovacuum worker template0(ExceptionalCondition+0x6e)[0x560a501e866e]
    postgres: autovacuum worker template0(+0x5dce3d)[0x560a50217e3d]
    postgres: autovacuum worker template0(ForwardSyncRequest+0x8e)[0x560a4ffec95e]
    postgres: autovacuum worker template0(RegisterSyncRequest+0x2b)[0x560a50091eeb]
    postgres: autovacuum worker template0(+0x187b0a)[0x560a4fdc2b0a]
    postgres: autovacuum worker template0(SlruDeleteSegment+0x101)[0x560a4fdc2ab1]
    postgres: autovacuum worker template0(TruncateMultiXact+0x2fb)[0x560a4fdbde1b]
    postgres: autovacuum worker template0(vac_update_datfrozenxid+0x4b3)[0x560a4febd2f3]
    postgres: autovacuum worker template0(+0x3adf66)[0x560a4ffe8f66]
    postgres: autovacuum worker template0(AutoVacWorkerMain+0x3ed)[0x560a4ffe7c2d]
    postgres: autovacuum worker template0(+0x3b1ead)[0x560a4ffecead]
    postgres: autovacuum worker template0(+0x3b620e)[0x560a4fff120e]
    postgres: autovacuum worker template0(+0x3b3fbb)[0x560a4ffeefbb]
    postgres: autovacuum worker template0(+0x2f724e)[0x560a4ff3224e]
    /lib/x86_64-linux-gnu/libc.so.6(+0x27c8a)[0x7f62cc642c8a]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85)[0x7f62cc642d45]
    postgres: autovacuum worker template0(_start+0x21)[0x560a4fd16f31]

To fix, bail out in CompactCheckpointerRequestQueue() without doing
anything, if it's called in a critical section. That covers the above
call path, as well as any other similar cases where
RegisterSyncRequest might be called in a critical section.

2. After fixing that, another problem became apparent: Autovacuum
process doing that truncation can deadlock with the checkpointer
process. TruncateMultiXact() sets "MyProc->delayChkptFlags |=
DELAY_CHKPT_START". If the sync request queue is full and cannot be
compacted, the process will repeatedly sleep and retry, until there is
room in the queue. However, if the checkpointer is trying to start a
checkpoint at the same time, and is waiting for the DELAY_CHKPT_START
processes to finish, the queue will never shrink.

More concretely, the autovacuum process is stuck here:

    #0  0x00007fc934926dc3 in epoll_wait () from /lib/x86_64-linux-gnu/libc.so.6
    #1  0x000056220b24348b in WaitEventSetWaitBlock (set=0x56220c2e4b50, occurred_events=0x7ffe7856d040, nevents=1, cur_timeout=<optimized out>) at ../src/backend/storage/ipc/latch.c:1570
    #2  WaitEventSetWait (set=0x56220c2e4b50, timeout=timeout@entry=10, occurred_events=<optimized out>, occurred_events@entry=0x7ffe7856d040, nevents=nevents@entry=1,
        wait_event_info=wait_event_info@entry=150994949) at ../src/backend/storage/ipc/latch.c:1516
    #3  0x000056220b243224 in WaitLatch (latch=<optimized out>, latch@entry=0x0, wakeEvents=wakeEvents@entry=40, timeout=timeout@entry=10, wait_event_info=wait_event_info@entry=150994949)
        at ../src/backend/storage/ipc/latch.c:538
    #4  0x000056220b26cf46 in RegisterSyncRequest (ftag=ftag@entry=0x7ffe7856d0a0, type=type@entry=SYNC_FORGET_REQUEST, retryOnError=true) at ../src/backend/storage/sync/sync.c:614
    #5  0x000056220af9db0a in SlruInternalDeleteSegment (ctl=ctl@entry=0x56220b7beb60 <MultiXactMemberCtlData>, segno=segno@entry=11350) at ../src/backend/access/transam/slru.c:1495
    #6  0x000056220af9dab1 in SlruDeleteSegment (ctl=ctl@entry=0x56220b7beb60 <MultiXactMemberCtlData>, segno=segno@entry=11350) at ../src/backend/access/transam/slru.c:1566
    apache#7  0x000056220af98e1b in PerformMembersTruncation (oldestOffset=<optimized out>, newOldestOffset=<optimized out>) at ../src/backend/access/transam/multixact.c:3006
    apache#8  TruncateMultiXact (newOldestMulti=newOldestMulti@entry=3221225472, newOldestMultiDB=newOldestMultiDB@entry=4) at ../src/backend/access/transam/multixact.c:3201
    apache#9  0x000056220b098303 in vac_truncate_clog (frozenXID=749, minMulti=<optimized out>, lastSaneFrozenXid=749, lastSaneMinMulti=3221225472) at ../src/backend/commands/vacuum.c:1917
    #10 vac_update_datfrozenxid () at ../src/backend/commands/vacuum.c:1760
    apache#11 0x000056220b1c3f76 in do_autovacuum () at ../src/backend/postmaster/autovacuum.c:2550
    apache#12 0x000056220b1c2c3d in AutoVacWorkerMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at ../src/backend/postmaster/autovacuum.c:1569

and the checkpointer is stuck here:

    #0  0x00007fc9348ebf93 in clock_nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
    #1  0x00007fc9348fe353 in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
    #2  0x000056220b40ecb4 in pg_usleep (microsec=microsec@entry=10000) at ../src/port/pgsleep.c:50
    #3  0x000056220afb43c3 in CreateCheckPoint (flags=flags@entry=108) at ../src/backend/access/transam/xlog.c:7098
    #4  0x000056220b1c6e86 in CheckpointerMain (startup_data=<optimized out>, startup_data_len=<optimized out>) at ../src/backend/postmaster/checkpointer.c:464

To fix, add AbsorbSyncRequests() to the loops where the checkpointer
waits for DELAY_CHKPT_START or DELAY_CHKPT_COMPLETE operations to
finish.

Backpatch to v14. Before that, SLRU deletion didn't call
RegisterSyncRequest, which avoided this failure. I'm not sure if there
are other similar scenarios on older versions, but we haven't had
any such reports.

Discussion: https://www.postgresql.org/message-id/ccc66933-31c1-4f6a-bf4b-45fef0d4f22e@iki.fi
reshke added a commit that referenced this pull request Nov 29, 2026
UBSan reported an unaligned uint16 load while parsing tuple chunks.
Copy the length into an aligned local with memcpy before adding the
header size, preserving the existing native-endian interpretation.

Sanitizer report (UBSan, instrumented build, distributed query with
Motion traffic over UDP):
  ic_udpifc.c:4572:39: runtime error: load of misaligned address
  0x52500016fa59 for type 'uint16', which requires 2 byte alignment
  #0 RecvTupleChunkUDPIFC ic_udpifc.c:4572
  #1 receiveChunksUDPIFCLoop ic_udpifc.c:4462
  #2 receiveChunksUDPIFC ic_udpifc.c:4406
  #3 RecvTupleChunkFromAnyUDPIFC ic_udpifc.c:4739
  #4 processIncomingChunks cdb/cdbmotion.c:653
  #5 RecvTupleFrom cdbmotion.c:607
  #6 execMotionUnsortedReceiver executor/nodeMotion.c:356
Reached whenever bytesProcessed walks the receive buffer past an
even offset while splitting a message into tuple chunks. Benign on
x86_64, but undefined behavior on strictly aligned targets.

(cherry picked from commit 4fe6095)
reshke added a commit that referenced this pull request Nov 29, 2026
UBSan reported an unaligned uint64_t load in GpMurmurHash64A.
Read each word with memcpy so input need not have uint64_t alignment,
while preserving the little-endian hash computation.

Sanitizer report (UBSan, instrumented build, ANALYZE on a table with
short text values):
  gp_hyperloglog.c:897:11: runtime error: load of misaligned address
  0x529000093515 for type 'uint64_t', which requires 8 byte alignment
  #0 GpMurmurHash64A gp_hyperloglog.c:897
  #1 gp_hll_add_element gp_hyperloglog.c:471
  #2 gp_hyperloglog_add_item gp_hyperloglog.c:788
  #3 compute_scalar_stats commands/analyze.c:3968
  #4 do_analyze_rel commands/analyze.c:971
  #5 analyze_rel_internal commands/analyze.c:429
Triggered by ordinary ndistinct estimation during ANALYZE: short varlena
values hashed via VARDATA_ANY have a payload offset that is not a
multiple of 8. Benign on x86_64, but undefined behavior on strictly
aligned targets.

(cherry picked from commit b6104f7)
reshke added a commit that referenced this pull request Dec 1, 2026
Mark float8arr_eq STRICT so SQL NULL arguments are handled by the executor
before the C implementation dereferences them. Add a 1.0.3 upgrade path for
existing installations, correct fresh-install scripts, and add NULL regression
coverage for installation and upgrades from 1.0.1 and 1.0.2.

SQL reproduction as a non-superuser before the fix:

    SELECT sparse_vector.float8arr_eq(NULL::float8[], ARRAY[1]::float8[]);

For the backtrace run, the same call was executed through this prepared
statement:

    PREPARE q(float8[], float8[]) AS
        SELECT sparse_vector.float8arr_eq($1, $2);
    EXECUTE q(NULL::float8[], ARRAY[1]::float8[]);

Verbatim server log:

    2026-12-01 12:28:32.427106 MSK,,,p395704,th123456,,,2026-12-01 12:27:33 MSK,0,,cmd4,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,
    2026-12-01 12:28:32.427211 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 395704) was terminated by signal 11: Segmentation fault","Failed process was running: EXECUTE q(NULL::float8[], ARRAY[1]::float8[]);",,,,,,0,,"postmaster.c",4278,
    2026-12-01 12:28:32.427218 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","terminating any other active server processes",,,,,,,0,,"postmaster.c",4071,
    2026-12-01 12:28:32.428219 MSK,"sqltester","postgres",p415572,th-153823424,"[local]",,2026-12-01 12:28:32 MSK,0,,,seg-1,,,,sx1,"FATAL","57P03","the database system is resetting",,,,,,,0,,"postmaster.c",2833,
    2026-12-01 12:28:32.428731 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","all server processes terminated; reinitializing",,,,,,,0,,"postmaster.c",4551,

Verbatim gdb backtrace:

    Program received signal SIGSEGV, Segmentation fault.
    0x000055a9c94fcca4 in pg_detoast_datum ()
    #0  0x000055a9c94fcca4 in pg_detoast_datum ()
    #1  0x00007f02eb0727c2 in float8arr_equals () from /home/reshke/.ya/tmp/1795466526.3735447.62efjlaq/opencode/cbdb-install/lib/postgresql/gp_svec.so
    #2  0x000055a9c90daaae in ExecInterpExpr ()
    #3  0x000055a9c9280558 in evaluate_expr ()
    #4  0x000055a9c9280da4 in simplify_function ()
    #5  0x000055a9c9281dad in eval_const_expressions_mutator ()
    #6  0x000055a9c9185714 in expression_tree_mutator_impl ()
    apache#7  0x000055a9c91864d2 in expression_tree_mutator_impl ()
    apache#8  0x000055a9c9282949 in eval_const_expressions ()
    apache#9  0x000055a9c925c918 in preprocess_expression.constprop ()
    #10 0x000055a9c9264954 in subquery_planner ()
    apache#11 0x000055a9c926557a in standard_planner ()
    apache#12 0x000055a9c9266064 in planner ()
    apache#13 0x000055a9c9367086 in pg_plan_query ()
    apache#14 0x000055a9c9367183 in pg_plan_queries ()
    apache#15 0x000055a9c94cfa73 in BuildCachedPlan ()
    apache#16 0x000055a9c94cfdc8 in GetCachedPlan ()
    apache#17 0x000055a9c907270b in ExecuteQuery ()
    apache#18 0x000055a9c9370313 in standard_ProcessUtility ()
    apache#19 0x000055a9c9370c5d in ProcessUtility ()
    apache#20 0x000055a9c936e183 in PortalRunUtility ()
    apache#21 0x000055a9c936e857 in FillPortalStore ()
    apache#22 0x000055a9c936ebad in PortalRun ()
    apache#23 0x000055a9c93678e0 in exec_simple_query ()
    apache#24 0x000055a9c936c104 in PostgresMain ()
    apache#25 0x000055a9c92b8004 in ServerLoop.isra.0 ()
    apache#26 0x000055a9c92b926a in PostmasterMain ()
    apache#27 0x000055a9c8e7a548 in main ()
    [Inferior 1 (process 395704) detached]
reshke added a commit that referenced this pull request Dec 1, 2026
Mark float8arr_eq(float8[], float8[]), l2norm(float8[]), and unnest(svec)
STRICT so whole-argument SQL NULLs are handled before their C entry points.
Update install scripts and version migrations, plus fresh-install and upgrade
regression coverage. Keep the 1.0.2 default install script and provide a small
explicit 1.0.2-to-1.0.3 migration, avoiding a copied full 1.0.3 install file.

SQL reproductions and pre-fix evidence
=======================================

float8arr_eq:

SQL reproduction as a non-superuser before the fix:

    SELECT sparse_vector.float8arr_eq(NULL::float8[], ARRAY[1]::float8[]);

For the backtrace run, the same call was executed through this prepared
statement:

    PREPARE q(float8[], float8[]) AS
        SELECT sparse_vector.float8arr_eq($1, $2);
    EXECUTE q(NULL::float8[], ARRAY[1]::float8[]);

Verbatim server log:

    2026-12-01 12:28:32.427106 MSK,,,p395704,th123456,,,2026-12-01 12:27:33 MSK,0,,cmd4,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,
    2026-12-01 12:28:32.427211 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 395704) was terminated by signal 11: Segmentation fault","Failed process was running: EXECUTE q(NULL::float8[], ARRAY[1]::float8[]);",,,,,,0,,"postmaster.c",4278,
    2026-12-01 12:28:32.427218 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","terminating any other active server processes",,,,,,,0,,"postmaster.c",4071,
    2026-12-01 12:28:32.428219 MSK,"sqltester","postgres",p415572,th-153823424,"[local]",,2026-12-01 12:28:32 MSK,0,,,seg-1,,,,sx1,"FATAL","57P03","the database system is resetting",,,,,,,0,,"postmaster.c",2833,
    2026-12-01 12:28:32.428731 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","all server processes terminated; reinitializing",,,,,,,0,,"postmaster.c",4551,

Verbatim gdb backtrace:

    Program received signal SIGSEGV, Segmentation fault.
    0x000055a9c94fcca4 in pg_detoast_datum ()
    #0  0x000055a9c94fcca4 in pg_detoast_datum ()
    #1  0x00007f02eb0727c2 in float8arr_equals () from /home/reshke/.ya/tmp/1795466526.3735447.62efjlaq/opencode/cbdb-install/lib/postgresql/gp_svec.so
    #2  0x000055a9c90daaae in ExecInterpExpr ()
    #3  0x000055a9c9280558 in evaluate_expr ()
    #4  0x000055a9c9280da4 in simplify_function ()
    #5  0x000055a9c9281dad in eval_const_expressions_mutator ()
    #6  0x000055a9c9185714 in expression_tree_mutator_impl ()
    apache#7  0x000055a9c91864d2 in expression_tree_mutator_impl ()
    apache#8  0x000055a9c9282949 in eval_const_expressions ()
    apache#9  0x000055a9c925c918 in preprocess_expression.constprop ()
    #10 0x000055a9c9264954 in subquery_planner ()
    apache#11 0x000055a9c926557a in standard_planner ()
    apache#12 0x000055a9c9266064 in planner ()
    apache#13 0x000055a9c9367086 in pg_plan_query ()
    apache#14 0x000055a9c9367183 in pg_plan_queries ()
    apache#15 0x000055a9c94cfa73 in BuildCachedPlan ()
    apache#16 0x000055a9c94cfdc8 in GetCachedPlan ()
    apache#17 0x000055a9c907270b in ExecuteQuery ()
    apache#18 0x000055a9c9370313 in standard_ProcessUtility ()
    apache#19 0x000055a9c9370c5d in ProcessUtility ()
    apache#20 0x000055a9c936e183 in PortalRunUtility ()
    apache#21 0x000055a9c936e857 in FillPortalStore ()
    apache#22 0x000055a9c936ebad in PortalRun ()
    apache#23 0x000055a9c93678e0 in exec_simple_query ()
    apache#24 0x000055a9c936c104 in PostgresMain ()
    apache#25 0x000055a9c92b8004 in ServerLoop.isra.0 ()
    apache#26 0x000055a9c92b926a in PostmasterMain ()
    apache#27 0x000055a9c8e7a548 in main ()
    [Inferior 1 (process 395704) detached]

l2norm:

Triggering SQL as a non-superuser:

    SELECT sparse_vector.l2norm(NULL::float8[]);

Verbatim log from the pre-fix disposable Cloudberry 16.9 cluster:

    2026-12-01 12:19:45.412720 MSK,,,p229290,th123456,,,2026-12-01 12:19:45 MSK,0,,cmd1,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,
    2026-12-01 12:19:45.413579 MSK,,,p220887,th2071603008,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 229290) was terminated by signal 11: Segmentation fault","Failed process was running: SELECT sparse_vector.l2norm(NULL::float8[]);",,,,,,0,,"postmaster.c",4278,
    2026-12-01 12:19:45.413587 MSK,,,p220887,th2071603008,,,,0,,,seg-1,,,,,"LOG","00000","terminating any other active server processes",,,,,,,0,,"postmaster.c",4071,
    2026-12-01 12:19:45.414588 MSK,,,p220887,th2071603008,,,,0,,,seg-1,,,,,"LOG","00000","all server processes terminated; reinitializing",,,,,,,0,,"postmaster.c",4551,

Backtrace captured with gdb on the pre-fix backend:

    #0  0x000055b0ed991ca4 in pg_detoast_datum ()
    #1  0x00007f8e49aa4a64 in float8arr_l2norm ()
       from /home/reshke/.ya/tmp/1795466526.3735447.62efjlaq/opencode/cbdb-install/lib/postgresql/gp_svec.so
    #2  0x000055b0ed56faae in ExecInterpExpr ()
    #3  0x000055b0ed715558 in evaluate_expr ()
    #4  0x000055b0ed715da4 in simplify_function ()
    #5  0x000055b0ed716dad in eval_const_expressions_mutator ()
    #6  0x000055b0ed61a714 in expression_tree_mutator_impl ()
    apache#7  0x000055b0ed61b4d2 in expression_tree_mutator_impl ()
    apache#8  0x000055b0ed717949 in eval_const_expressions ()
    apache#9  0x000055b0ed6f1918 in preprocess_expression.constprop ()
    #10 0x000055b0ed6f9954 in subquery_planner ()
    apache#11 0x000055b0ed6fa57a in standard_planner ()
    apache#12 0x000055b0ed6fb064 in planner ()
    apache#13 0x000055b0ed7fc086 in pg_plan_query ()
    apache#14 0x000055b0ed7fc183 in pg_plan_queries ()
    apache#15 0x000055b0ed7fcb77 in exec_simple_query ()
    apache#16 0x000055b0ed801104 in PostgresMain ()
    apache#17 0x000055b0ed74d004 in ServerLoop.isra.0 ()
    apache#18 0x000055b0ed74e26a in PostmasterMain ()
    apache#19 0x000055b0ed30f548 in main ()

After applying the catalog change in the disposable cluster, the same
non-superuser SQL returned NULL and a following SELECT 1 succeeded.

unnest:

Reproducer before the fix, run as non-superuser sqltester:

    SELECT * FROM sparse_vector.unnest(NULL::sparse_vector.svec);

Verbatim backend log before the fix:

    2026-12-01 12:27:30.062505 MSK,,,p363547,th123456,,,2026-12-01 12:26:04 MSK,0,,cmd4,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,
    2026-12-01 12:27:50.458365 MSK,,,p354590,th-73722048,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 363547) was terminated by signal 11: Segmentation fault","Failed process was running: SELECT * FROM sparse_vector.unnest(NULL::sparse_vector.svec);",,,,,,0,,"postmaster.c",4278,
    2026-12-01 12:27:50.458393 MSK,,,p354590,th-73722048,,,,0,,,seg-1,,,,,"LOG","00000","terminating any other active server processes",,,,,,,0,,"postmaster.c",4071,
    2026-12-01 12:27:50.459466 MSK,,,p354590,th-73722048,,,,0,,,seg-1,,,,,"LOG","00000","all server processes terminated; reinitializing",,,,,,,0,,"postmaster.c",4551,

GDB backtrace at SIGSEGV:

    #0  0x00005611c942eca4 in pg_detoast_datum ()
    #1  0x00007f54efdab31a in svec_unnest () from /home/reshke/.ya/tmp/1795466526.3735447.62efjlaq/opencode/cbdb-install/lib/postgresql/gp_svec.so
    #2  0x00005611c901de14 in ExecMakeTableFunctionResult ()
    #3  0x00005611c9034ec6 in FunctionNext ()
    #4  0x00005611c901ab72 in ExecProcNodeFirst ()
    #5  0x00005611c9010cda in ExecutePlan ()
    #6  0x00005611c9011adb in standard_ExecutorRun ()
    apache#7  0x00005611c9011ce5 in ExecutorRun ()
    apache#8  0x00005611c929ed3a in PortalRunSelect ()
    apache#9  0x00005611c92a0afa in PortalRun ()
    #10 0x00005611c92998e0 in exec_simple_query ()
    apache#11 0x00005611c929e104 in PostgresMain ()
    apache#12 0x00005611c91ea004 in ServerLoop.isra.0 ()
    apache#13 0x00005611c91eb26a in PostmasterMain ()
    apache#14 0x00005611c8dac548 in main ()

Tests: added the exact SQL case to gp_svec and upgrade coverage for 1.0.1 ->
1.0.2 and 1.0.2 -> 1.0.3. In a disposable cluster, after applying STRICT,
the same query returned zero rows and the backend stayed available. The full
multi-segment installcheck suite was not run in the utility-mode test cluster.
reshke added a commit that referenced this pull request Dec 1, 2026
Mark float8arr_eq STRICT so SQL NULL arguments are handled by the executor
before the C implementation dereferences them. Add a 1.0.3 upgrade path for
existing installations, correct fresh-install scripts, and add NULL regression
coverage for installation and upgrades from 1.0.1 and 1.0.2.

SQL reproduction as a non-superuser before the fix:

    SELECT sparse_vector.float8arr_eq(NULL::float8[], ARRAY[1]::float8[]);

For the backtrace run, the same call was executed through this prepared
statement:

    PREPARE q(float8[], float8[]) AS
        SELECT sparse_vector.float8arr_eq($1, $2);
    EXECUTE q(NULL::float8[], ARRAY[1]::float8[]);

Verbatim server log:

    2026-12-01 12:28:32.427106 MSK,,,p395704,th123456,,,2026-12-01 12:27:33 MSK,0,,cmd4,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,
    2026-12-01 12:28:32.427211 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 395704) was terminated by signal 11: Segmentation fault","Failed process was running: EXECUTE q(NULL::float8[], ARRAY[1]::float8[]);",,,,,,0,,"postmaster.c",4278,
    2026-12-01 12:28:32.427218 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","terminating any other active server processes",,,,,,,0,,"postmaster.c",4071,
    2026-12-01 12:28:32.428219 MSK,"sqltester","postgres",p415572,th-153823424,"[local]",,2026-12-01 12:28:32 MSK,0,,,seg-1,,,,sx1,"FATAL","57P03","the database system is resetting",,,,,,,0,,"postmaster.c",2833,
    2026-12-01 12:28:32.428731 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","all server processes terminated; reinitializing",,,,,,,0,,"postmaster.c",4551,

Verbatim gdb backtrace:

    Program received signal SIGSEGV, Segmentation fault.
    0x000055a9c94fcca4 in pg_detoast_datum ()
    #0  0x000055a9c94fcca4 in pg_detoast_datum ()
    #1  0x00007f02eb0727c2 in float8arr_equals () from /home/reshke/.ya/tmp/1795466526.3735447.62efjlaq/opencode/cbdb-install/lib/postgresql/gp_svec.so
    #2  0x000055a9c90daaae in ExecInterpExpr ()
    #3  0x000055a9c9280558 in evaluate_expr ()
    #4  0x000055a9c9280da4 in simplify_function ()
    #5  0x000055a9c9281dad in eval_const_expressions_mutator ()
    #6  0x000055a9c9185714 in expression_tree_mutator_impl ()
    apache#7  0x000055a9c91864d2 in expression_tree_mutator_impl ()
    apache#8  0x000055a9c9282949 in eval_const_expressions ()
    apache#9  0x000055a9c925c918 in preprocess_expression.constprop ()
    #10 0x000055a9c9264954 in subquery_planner ()
    apache#11 0x000055a9c926557a in standard_planner ()
    apache#12 0x000055a9c9266064 in planner ()
    apache#13 0x000055a9c9367086 in pg_plan_query ()
    apache#14 0x000055a9c9367183 in pg_plan_queries ()
    apache#15 0x000055a9c94cfa73 in BuildCachedPlan ()
    apache#16 0x000055a9c94cfdc8 in GetCachedPlan ()
    apache#17 0x000055a9c907270b in ExecuteQuery ()
    apache#18 0x000055a9c9370313 in standard_ProcessUtility ()
    apache#19 0x000055a9c9370c5d in ProcessUtility ()
    apache#20 0x000055a9c936e183 in PortalRunUtility ()
    apache#21 0x000055a9c936e857 in FillPortalStore ()
    apache#22 0x000055a9c936ebad in PortalRun ()
    apache#23 0x000055a9c93678e0 in exec_simple_query ()
    apache#24 0x000055a9c936c104 in PostgresMain ()
    apache#25 0x000055a9c92b8004 in ServerLoop.isra.0 ()
    apache#26 0x000055a9c92b926a in PostmasterMain ()
    apache#27 0x000055a9c8e7a548 in main ()
    [Inferior 1 (process 395704) detached]
reshke added a commit that referenced this pull request Dec 1, 2026
Mark float8arr_eq(float8[], float8[]), l2norm(float8[]), and unnest(svec)
STRICT so whole-argument SQL NULLs are handled before their C entry points.
Update install scripts and version migrations, plus fresh-install and upgrade
regression coverage. Keep the 1.0.2 default install script and provide a small
explicit 1.0.2-to-1.0.3 migration, avoiding a copied full 1.0.3 install file.

SQL reproductions and pre-fix evidence
=======================================

float8arr_eq:

SQL reproduction as a non-superuser before the fix:

    SELECT sparse_vector.float8arr_eq(NULL::float8[], ARRAY[1]::float8[]);

For the backtrace run, the same call was executed through this prepared
statement:

    PREPARE q(float8[], float8[]) AS
        SELECT sparse_vector.float8arr_eq($1, $2);
    EXECUTE q(NULL::float8[], ARRAY[1]::float8[]);

Verbatim server log:

    2026-12-01 12:28:32.427106 MSK,,,p395704,th123456,,,2026-12-01 12:27:33 MSK,0,,cmd4,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,
    2026-12-01 12:28:32.427211 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 395704) was terminated by signal 11: Segmentation fault","Failed process was running: EXECUTE q(NULL::float8[], ARRAY[1]::float8[]);",,,,,,0,,"postmaster.c",4278,
    2026-12-01 12:28:32.427218 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","terminating any other active server processes",,,,,,,0,,"postmaster.c",4071,
    2026-12-01 12:28:32.428219 MSK,"sqltester","postgres",p415572,th-153823424,"[local]",,2026-12-01 12:28:32 MSK,0,,,seg-1,,,,sx1,"FATAL","57P03","the database system is resetting",,,,,,,0,,"postmaster.c",2833,
    2026-12-01 12:28:32.428731 MSK,,,p263623,th-153823424,,,,0,,,seg-1,,,,,"LOG","00000","all server processes terminated; reinitializing",,,,,,,0,,"postmaster.c",4551,

Verbatim gdb backtrace:

    Program received signal SIGSEGV, Segmentation fault.
    0x000055a9c94fcca4 in pg_detoast_datum ()
    #0  0x000055a9c94fcca4 in pg_detoast_datum ()
    #1  0x00007f02eb0727c2 in float8arr_equals () from /home/reshke/.ya/tmp/1795466526.3735447.62efjlaq/opencode/cbdb-install/lib/postgresql/gp_svec.so
    #2  0x000055a9c90daaae in ExecInterpExpr ()
    #3  0x000055a9c9280558 in evaluate_expr ()
    #4  0x000055a9c9280da4 in simplify_function ()
    #5  0x000055a9c9281dad in eval_const_expressions_mutator ()
    #6  0x000055a9c9185714 in expression_tree_mutator_impl ()
    apache#7  0x000055a9c91864d2 in expression_tree_mutator_impl ()
    apache#8  0x000055a9c9282949 in eval_const_expressions ()
    apache#9  0x000055a9c925c918 in preprocess_expression.constprop ()
    #10 0x000055a9c9264954 in subquery_planner ()
    apache#11 0x000055a9c926557a in standard_planner ()
    apache#12 0x000055a9c9266064 in planner ()
    apache#13 0x000055a9c9367086 in pg_plan_query ()
    apache#14 0x000055a9c9367183 in pg_plan_queries ()
    apache#15 0x000055a9c94cfa73 in BuildCachedPlan ()
    apache#16 0x000055a9c94cfdc8 in GetCachedPlan ()
    apache#17 0x000055a9c907270b in ExecuteQuery ()
    apache#18 0x000055a9c9370313 in standard_ProcessUtility ()
    apache#19 0x000055a9c9370c5d in ProcessUtility ()
    apache#20 0x000055a9c936e183 in PortalRunUtility ()
    apache#21 0x000055a9c936e857 in FillPortalStore ()
    apache#22 0x000055a9c936ebad in PortalRun ()
    apache#23 0x000055a9c93678e0 in exec_simple_query ()
    apache#24 0x000055a9c936c104 in PostgresMain ()
    apache#25 0x000055a9c92b8004 in ServerLoop.isra.0 ()
    apache#26 0x000055a9c92b926a in PostmasterMain ()
    apache#27 0x000055a9c8e7a548 in main ()
    [Inferior 1 (process 395704) detached]

l2norm:

Triggering SQL as a non-superuser:

    SELECT sparse_vector.l2norm(NULL::float8[]);

Verbatim log from the pre-fix disposable Cloudberry 16.9 cluster:

    2026-12-01 12:19:45.412720 MSK,,,p229290,th123456,,,2026-12-01 12:19:45 MSK,0,,cmd1,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,
    2026-12-01 12:19:45.413579 MSK,,,p220887,th2071603008,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 229290) was terminated by signal 11: Segmentation fault","Failed process was running: SELECT sparse_vector.l2norm(NULL::float8[]);",,,,,,0,,"postmaster.c",4278,
    2026-12-01 12:19:45.413587 MSK,,,p220887,th2071603008,,,,0,,,seg-1,,,,,"LOG","00000","terminating any other active server processes",,,,,,,0,,"postmaster.c",4071,
    2026-12-01 12:19:45.414588 MSK,,,p220887,th2071603008,,,,0,,,seg-1,,,,,"LOG","00000","all server processes terminated; reinitializing",,,,,,,0,,"postmaster.c",4551,

Backtrace captured with gdb on the pre-fix backend:

    #0  0x000055b0ed991ca4 in pg_detoast_datum ()
    #1  0x00007f8e49aa4a64 in float8arr_l2norm ()
       from /home/reshke/.ya/tmp/1795466526.3735447.62efjlaq/opencode/cbdb-install/lib/postgresql/gp_svec.so
    #2  0x000055b0ed56faae in ExecInterpExpr ()
    #3  0x000055b0ed715558 in evaluate_expr ()
    #4  0x000055b0ed715da4 in simplify_function ()
    #5  0x000055b0ed716dad in eval_const_expressions_mutator ()
    #6  0x000055b0ed61a714 in expression_tree_mutator_impl ()
    apache#7  0x000055b0ed61b4d2 in expression_tree_mutator_impl ()
    apache#8  0x000055b0ed717949 in eval_const_expressions ()
    apache#9  0x000055b0ed6f1918 in preprocess_expression.constprop ()
    #10 0x000055b0ed6f9954 in subquery_planner ()
    apache#11 0x000055b0ed6fa57a in standard_planner ()
    apache#12 0x000055b0ed6fb064 in planner ()
    apache#13 0x000055b0ed7fc086 in pg_plan_query ()
    apache#14 0x000055b0ed7fc183 in pg_plan_queries ()
    apache#15 0x000055b0ed7fcb77 in exec_simple_query ()
    apache#16 0x000055b0ed801104 in PostgresMain ()
    apache#17 0x000055b0ed74d004 in ServerLoop.isra.0 ()
    apache#18 0x000055b0ed74e26a in PostmasterMain ()
    apache#19 0x000055b0ed30f548 in main ()

After applying the catalog change in the disposable cluster, the same
non-superuser SQL returned NULL and a following SELECT 1 succeeded.

unnest:

Reproducer before the fix, run as non-superuser sqltester:

    SELECT * FROM sparse_vector.unnest(NULL::sparse_vector.svec);

Verbatim backend log before the fix:

    2026-12-01 12:27:30.062505 MSK,,,p363547,th123456,,,2026-12-01 12:26:04 MSK,0,,cmd4,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,
    2026-12-01 12:27:50.458365 MSK,,,p354590,th-73722048,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 363547) was terminated by signal 11: Segmentation fault","Failed process was running: SELECT * FROM sparse_vector.unnest(NULL::sparse_vector.svec);",,,,,,0,,"postmaster.c",4278,
    2026-12-01 12:27:50.458393 MSK,,,p354590,th-73722048,,,,0,,,seg-1,,,,,"LOG","00000","terminating any other active server processes",,,,,,,0,,"postmaster.c",4071,
    2026-12-01 12:27:50.459466 MSK,,,p354590,th-73722048,,,,0,,,seg-1,,,,,"LOG","00000","all server processes terminated; reinitializing",,,,,,,0,,"postmaster.c",4551,

GDB backtrace at SIGSEGV:

    #0  0x00005611c942eca4 in pg_detoast_datum ()
    #1  0x00007f54efdab31a in svec_unnest () from /home/reshke/.ya/tmp/1795466526.3735447.62efjlaq/opencode/cbdb-install/lib/postgresql/gp_svec.so
    #2  0x00005611c901de14 in ExecMakeTableFunctionResult ()
    #3  0x00005611c9034ec6 in FunctionNext ()
    #4  0x00005611c901ab72 in ExecProcNodeFirst ()
    #5  0x00005611c9010cda in ExecutePlan ()
    #6  0x00005611c9011adb in standard_ExecutorRun ()
    apache#7  0x00005611c9011ce5 in ExecutorRun ()
    apache#8  0x00005611c929ed3a in PortalRunSelect ()
    apache#9  0x00005611c92a0afa in PortalRun ()
    #10 0x00005611c92998e0 in exec_simple_query ()
    apache#11 0x00005611c929e104 in PostgresMain ()
    apache#12 0x00005611c91ea004 in ServerLoop.isra.0 ()
    apache#13 0x00005611c91eb26a in PostmasterMain ()
    apache#14 0x00005611c8dac548 in main ()

Tests: added the exact SQL case to gp_svec and upgrade coverage for 1.0.1 ->
1.0.2 and 1.0.2 -> 1.0.3. In a disposable cluster, after applying STRICT,
the same query returned zero rows and the backend stayed available. The full
multi-segment installcheck suite was not run in the utility-mode test cluster.
reshke added a commit that referenced this pull request Dec 1, 2026
ivm_visible_in_prestate is callable by PUBLIC, but assumes that an
incremental materialized view maintenance trigger has populated
mv_trigger_info. A regular SQL user can invoke the helper outside that
context; the NULL hash table is dereferenced and the server process receives
SIGSEGV. Validate required arguments and maintenance state before accessing
the hash entry, and reject missing entries or nonparticipating tables with
SQL errors instead of Assert() or unchecked dereferences.

SQL repro (before; sqlscan is a nonsuperuser with PUBLIC EXECUTE):
SET ROLE sqlscan;
SELECT pg_catalog.ivm_visible_in_prestate(0::oid, '(0,1)'::tid, 0::oid, 0::integer);

Verbatim server log and backtrace (before):
2026-12-02 01:53:33.829973 MSK,,,p3500294,th123456,,,2026-12-02 01:53:33 MSK,0,,cmd2,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,"1    0x55fe240ca3f7 postgres StandardHandlerForSigillSigsegvSigbus_OnMainThread + 0x177
2    0x7fe5346c6330 libc.so.6 <symbol not found> + 0x346c6330
3    0x55fe23c3c20f postgres ivm_visible_in_prestate + 0x4f
4    0x55fe23cac925 postgres <symbol not found> + 0x23cac925
5    0x55fe23cf2572 postgres <symbol not found> + 0x23cf2572
6    0x55fe23cba2a2 postgres <symbol not found> + 0x23cba2a2
7    0x55fe23cb040a postgres <symbol not found> + 0x23cb040a
8    0x55fe23cb120b postgres standard_ExecutorRun + 0x70b
9    0x55fe23cb1415 postgres ExecutorRun + 0xf5
10   0x55fe23f3e5da postgres <symbol not found> + 0x23f3e5da
11   0x55fe23f4039a postgres PortalRun + 0x28a
12   0x55fe23f39180 postgres exec_simple_query + 0x6c0
13   0x55fe23f3d9a4 postgres PostgresMain + 0x1ef4
14   0x55fe23e89764 postgres <symbol not found> + 0x23e89764
15   0x55fe23e8a9ca postgres PostmasterMain + 0xf8a
16   0x55fe23a4a628 postgres main + 0x5d8
17   0x7fe5346ab1ca libc.so.6 <symbol not found> + 0x346ab1ca
18   0x7fe5346ab28b libc.so.6 __libc_start_main + 0x8b
19   0x55fe23a4c8a5 postgres _start + 0x25
"
2026-12-02 01:53:33.830053 MSK,,,p3499893,th845801280,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 3500294) was terminated by signal 11: Segmentation fault","Failed process was running: SELECT pg_catalog.ivm_visible_in_prestate(0::oid, '(0,1)'::tid, 0::oid, 0::integer);",,,,,,0,,"postmaster.c",4278,
2026-12-02 01:53:33.830059 MSK,,,p3499893,th845801280,,,,0,,,seg-1,,,,,"LOG","00000","terminating any other active server processes",,,,,,,0,,"postmaster.c",4071,
2026-12-02 01:53:33.830063 MSK,,,p3499893,th845801280,,,,0,,,seg-1,,,,,"LOG","00000","all server processes terminated; reinitializing",,,,,,,0,,"postmaster.c",4551,

The regression invokes the function as a regular role before any IVM
maintenance has populated the backend state, and expects a controlled error.

GDB backtrace (second reproduction, captured at SIGSEGV with gdb 15.1):
Program received signal SIGSEGV, Segmentation fault.
#0  0x000055820e9ad1cf in ivm_visible_in_prestate ()
#1  0x000055820ea1d8b5 in ExecInterpExpr ()
#2  0x000055820ea63502 in ExecResult ()
#3  0x000055820ea2b232 in ExecProcNodeFirst ()
#4  0x000055820ea2139a in ExecutePlan ()
#5  0x000055820ea2219b in standard_ExecutorRun ()
#6  0x000055820ea223a5 in ExecutorRun ()
apache#7  0x000055820ecaf56a in PortalRunSelect ()
apache#8  0x000055820ecb132a in PortalRun ()
apache#9  0x000055820ecaa110 in exec_simple_query ()
#10 0x000055820ecae934 in PostgresMain ()
apache#11 0x000055820ebfa6f4 in ServerLoop.isra.0 ()
apache#12 0x000055820ebfb95a in PostmasterMain ()
apache#13 0x000055820e7bb5e8 in main ()
[Inferior 1 (process 3562847) detached]

The GDB build had function symbols but no DWARF variable information. The server
log from this second run records the failed SQL and SIGSEGV in
ivm_visible_in_prestate; the first full verbatim server log is included above.
reshke added a commit that referenced this pull request Dec 3, 2026
FigureColnameInternal recursively walks a raw expression while
CREATE INDEX derives the preliminary index column name. This happens
before transformExpr() applies its stack-depth protection, so a deep cast
chain can exhaust the backend stack. Check stack depth on every recursive
visit and reject the expression with stack_depth_limit_exceeded.

Add a create_index regression that dynamically builds the deep expression,
so the source tree does not contain a megabyte-scale SQL statement.

SQL-reachable SIGSEGV: CREATE INDEX expression cast chain

The query is executable by the ordinary table owner. The test role sqlsmith_probe has rolsuper=false and owns schema index_hunt and table index_hunt.idx_t. It created a short index successfully with the same role.

Setup SQL:
CREATE SCHEMA index_hunt AUTHORIZATION sqlsmith_probe;
CREATE TABLE index_hunt.idx_t(a integer) DISTRIBUTED RANDOMLY;

Reproducer SQL: execute as sqlsmith_probe; N=270000:
CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((a::int::int::...::int));

Generate the exact SQL with:
python3 - <<'PY'
n = 270000
expr = 'a' + '::int' * n
print('CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((' + expr + '));')
PY

The grammar builds a left-deep TypeCast tree. CREATE INDEX reaches FigureIndexColname()/FigureColnameInternal before transformExpr(). The backend SIGSEGVs in FigureColnameInternal.constprop.0. GDB reports roughly 261k recursive frames at the 500k repro; 270k also crashes.

GDB bt (top frames):
#0  0x000055bcff76594f in FigureColnameInternal.constprop.0 ()
#1  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#2  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#3  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#4  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#5  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#6  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#7  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#8  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#9  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#10 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#11 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#12 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#13 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#14 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#15 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#16 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#17 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#18 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#19 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
(More stack frames follow...)
Warning: 'set logging off', an alias for the command 'set logging enabled', is deprecated.
Use 'set logging enabled off'.

Verbatim coordinator postmaster log:
2026-12-03 16:06:52.845238 MSK,,,p1484041,th1997600576,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 2111634) was terminated by signal 11: Segmentation fault","Failed process was running: CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((a::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int:",,,,,,0,,"postmaster.c",4278,
reshke added a commit that referenced this pull request Dec 3, 2026
FigureColnameInternal recursively walks a raw expression while
CREATE INDEX derives the preliminary index column name. This happens
before transformExpr() applies its stack-depth protection, so a deep cast
chain can exhaust the backend stack. Check stack depth on every recursive
visit and reject the expression with stack_depth_limit_exceeded.

Add a create_index regression that dynamically builds the deep expression,
so the source tree does not contain a megabyte-scale SQL statement.

SQL-reachable SIGSEGV: CREATE INDEX expression cast chain

The query is executable by the ordinary table owner. The test role sqlsmith_probe has rolsuper=false and owns schema index_hunt and table index_hunt.idx_t. It created a short index successfully with the same role.

Setup SQL:
CREATE SCHEMA index_hunt AUTHORIZATION sqlsmith_probe;
CREATE TABLE index_hunt.idx_t(a integer) DISTRIBUTED RANDOMLY;

Reproducer SQL: execute as sqlsmith_probe; N=270000:
CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((a::int::int::...::int));

Generate the exact SQL with:
python3 - <<'PY'
n = 270000
expr = 'a' + '::int' * n
print('CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((' + expr + '));')
PY

The grammar builds a left-deep TypeCast tree. CREATE INDEX reaches FigureIndexColname()/FigureColnameInternal before transformExpr(). The backend SIGSEGVs in FigureColnameInternal.constprop.0. GDB reports roughly 261k recursive frames at the 500k repro; 270k also crashes.

GDB bt (top frames):
#0  0x000055bcff76594f in FigureColnameInternal.constprop.0 ()
#1  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#2  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#3  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#4  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#5  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#6  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#7  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#8  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#9  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#10 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#11 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#12 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#13 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#14 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#15 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#16 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#17 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#18 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#19 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
(More stack frames follow...)
Warning: 'set logging off', an alias for the command 'set logging enabled', is deprecated.
Use 'set logging enabled off'.

Verbatim coordinator postmaster log:
2026-12-03 16:06:52.845238 MSK,,,p1484041,th1997600576,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 2111634) was terminated by signal 11: Segmentation fault","Failed process was running: CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((a::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int:",,,,,,0,,"postmaster.c",4278,
reshke added a commit that referenced this pull request Dec 3, 2026
FigureColnameInternal recursively walks a raw expression while
CREATE INDEX derives the preliminary index column name. This happens
before transformExpr() applies its stack-depth protection, so a deep cast
chain can exhaust the backend stack. Check stack depth on every recursive
visit and reject the expression with stack_depth_limit_exceeded.

Add a create_index regression that dynamically builds the deep expression,
so the source tree does not contain a megabyte-scale SQL statement.

SQL-reachable SIGSEGV: CREATE INDEX expression cast chain

The query is executable by the ordinary table owner. The test role sqlsmith_probe has rolsuper=false and owns schema index_hunt and table index_hunt.idx_t. It created a short index successfully with the same role.

Setup SQL:
CREATE SCHEMA index_hunt AUTHORIZATION sqlsmith_probe;
CREATE TABLE index_hunt.idx_t(a integer) DISTRIBUTED RANDOMLY;

Reproducer SQL: execute as sqlsmith_probe; N=270000:
CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((a::int::int::...::int));

Generate the exact SQL with:
python3 - <<'PY'
n = 270000
expr = 'a' + '::int' * n
print('CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((' + expr + '));')
PY

The grammar builds a left-deep TypeCast tree. CREATE INDEX reaches FigureIndexColname()/FigureColnameInternal before transformExpr(). The backend SIGSEGVs in FigureColnameInternal.constprop.0. GDB reports roughly 261k recursive frames at the 500k repro; 270k also crashes.

GDB bt (top frames):
#0  0x000055bcff76594f in FigureColnameInternal.constprop.0 ()
#1  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#2  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#3  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#4  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#5  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#6  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#7  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#8  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#9  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#10 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#11 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#12 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#13 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#14 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#15 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#16 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#17 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#18 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#19 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
(More stack frames follow...)
Warning: 'set logging off', an alias for the command 'set logging enabled', is deprecated.
Use 'set logging enabled off'.

Verbatim coordinator postmaster log:
2026-12-03 16:06:52.845238 MSK,,,p1484041,th1997600576,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 2111634) was terminated by signal 11: Segmentation fault","Failed process was running: CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((a::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int:",,,,,,0,,"postmaster.c",4278,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants