Skip to content

Update ISSUE and Pull Request templates - #3

Merged
tuhaihe merged 1 commit into
prfrom
dj-pr
Jun 15, 2023
Merged

tuhaihe merged 1 commit into
prfrom
dj-pr

Conversation

@tuhaihe

@tuhaihe tuhaihe commented Jun 15, 2023

Copy link
Copy Markdown
Member

For a better user and developer experience, update the Issue and PR templates.

Files changed:

  • Add bug-report.yml
  • Modify pull_request_template.md
  • Delete bug-report.md
  • Delete enhancement.md
  • Delete feature-request.md

For a better user and developer experience, update the Issue and PR templates.

Files changed:
* Add bug-report.yml
* Modify pull_request_template.md
* Delete bug-report.md
* Delete enhancement.md
* Delete feature-request.md
@tuhaihe
tuhaihe merged commit 8fe9843 into pr Jun 15, 2023
@tuhaihe
tuhaihe deleted the dj-pr branch June 15, 2023 03:10
HuSen8891 added a commit to HuSen8891/cloudberrydb that referenced this pull request Mar 1, 2024
For test case:

create table t0(c0 inet) distributed randomly;
create table t2(c0 inet) distributed randomly;
create table t3(c0 inet) distributed randomly;

SELECT ALL t2.c0, t3.c0, t0.c0 FROM t0, ONLY t3 FULL OUTER JOIN t2 ON ((t2.c0)=(t3.c0))
WHERE (((('0.5496844753539182')||(t3.c0)))LIKE(CAST((0.13292931)::MONEY AS VARCHAR(971))))
UNION ALL SELECT t2.c0, t3.c0, t0.c0 FROM t0, ONLY t3 FULL OUTER JOIN t2 ON ((t2.c0)=(t3.c0))
WHERE NOT ((((('0.5496844753539182')||(t3.c0)))LIKE((CAST(0.13292931 AS MONEY))::VARCHAR(971))))
UNION ALL SELECT ALL t2.c0, t3.c0, t0.c0 FROM t0*, ONLY t3 FULL OUTER JOIN t2 ON ((t2.c0)=(t3.c0))
WHERE ((((('0.5496844753539182')||(t3.c0)))LIKE((CAST(0.13292931 AS MONEY))::VARCHAR(971)))) ISNULL;

will cause crash because of assert failure in 'create_plan_recurse'.

'apache#3  0x00007fe94eccf476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
 apache#4  0x00007fe94ecb57f3 in __GI_abort () at ./stdlib/abort.c:79
 apache#5  0x00007fe94fcdd548 in ExceptionalCondition (conditionName=0x7fe95043dcd0 "best_path->parallel_workers == best_path->locus.parallel_workers",
     errorType=0x7fe95043db06 "FailedAssertion", fileName=0x7fe95043dbdb "createplan.c", lineNumber=623) at assert.c:48
 apache#6  0x00007fe94f94918f in create_plan_recurse (root=0x55d7cbe96f78, best_path=0x55d7cbec0380, flags=1) at createplan.c:623
 apache#7  0x00007fe94f94a1f8 in create_append_plan (root=0x55d7cbe96f78, best_path=0x55d7cbec0700, flags=1) at createplan.c:1380
 apache#8  0x00007fe94f948d37 in create_plan_recurse (root=0x55d7cbe96f78, best_path=0x55d7cbec0700, flags=1) at createplan.c:481
 apache#9  0x00007fe94f94e2d1 in create_motion_plan (root=0x55d7cbe96f78, path=0x55d7cbec0e50) at createplan.c:3316
 #10 0x00007fe94f9490dc in create_plan_recurse (root=0x55d7cbe96f78, best_path=0x55d7cbec0e50, flags=1) at createplan.c:608
 apache#11 0x00007fe94f948ba3 in create_plan (root=0x55d7cbe96f78, best_path=0x55d7cbec0e50, curSlice=0x55d7cbe96f20) at createplan.c:392'

The parallel_workers should be set to zero because parallel full join is not supported yet.
my-ship-it pushed a commit that referenced this pull request Mar 4, 2024
For test case:

create table t0(c0 inet) distributed randomly;
create table t2(c0 inet) distributed randomly;
create table t3(c0 inet) distributed randomly;

SELECT ALL t2.c0, t3.c0, t0.c0 FROM t0, ONLY t3 FULL OUTER JOIN t2 ON ((t2.c0)=(t3.c0))
WHERE (((('0.5496844753539182')||(t3.c0)))LIKE(CAST((0.13292931)::MONEY AS VARCHAR(971))))
UNION ALL SELECT t2.c0, t3.c0, t0.c0 FROM t0, ONLY t3 FULL OUTER JOIN t2 ON ((t2.c0)=(t3.c0))
WHERE NOT ((((('0.5496844753539182')||(t3.c0)))LIKE((CAST(0.13292931 AS MONEY))::VARCHAR(971))))
UNION ALL SELECT ALL t2.c0, t3.c0, t0.c0 FROM t0*, ONLY t3 FULL OUTER JOIN t2 ON ((t2.c0)=(t3.c0))
WHERE ((((('0.5496844753539182')||(t3.c0)))LIKE((CAST(0.13292931 AS MONEY))::VARCHAR(971)))) ISNULL;

will cause crash because of assert failure in 'create_plan_recurse'.

'#3  0x00007fe94eccf476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
 #4  0x00007fe94ecb57f3 in __GI_abort () at ./stdlib/abort.c:79
 #5  0x00007fe94fcdd548 in ExceptionalCondition (conditionName=0x7fe95043dcd0 "best_path->parallel_workers == best_path->locus.parallel_workers",
     errorType=0x7fe95043db06 "FailedAssertion", fileName=0x7fe95043dbdb "createplan.c", lineNumber=623) at assert.c:48
 #6  0x00007fe94f94918f in create_plan_recurse (root=0x55d7cbe96f78, best_path=0x55d7cbec0380, flags=1) at createplan.c:623
 #7  0x00007fe94f94a1f8 in create_append_plan (root=0x55d7cbe96f78, best_path=0x55d7cbec0700, flags=1) at createplan.c:1380
 #8  0x00007fe94f948d37 in create_plan_recurse (root=0x55d7cbe96f78, best_path=0x55d7cbec0700, flags=1) at createplan.c:481
 #9  0x00007fe94f94e2d1 in create_motion_plan (root=0x55d7cbe96f78, path=0x55d7cbec0e50) at createplan.c:3316
 #10 0x00007fe94f9490dc in create_plan_recurse (root=0x55d7cbe96f78, best_path=0x55d7cbec0e50, flags=1) at createplan.c:608
 #11 0x00007fe94f948ba3 in create_plan (root=0x55d7cbe96f78, best_path=0x55d7cbec0e50, curSlice=0x55d7cbe96f20) at createplan.c:392'

The parallel_workers should be set to zero because parallel full join is not supported yet.
foreyes pushed a commit to foreyes/cloudberrydb that referenced this pull request Jul 8, 2024
For test case:

create table t0(c0 inet) distributed randomly;
create table t2(c0 inet) distributed randomly;
create table t3(c0 inet) distributed randomly;

SELECT ALL t2.c0, t3.c0, t0.c0 FROM t0, ONLY t3 FULL OUTER JOIN t2 ON ((t2.c0)=(t3.c0))
WHERE (((('0.5496844753539182')||(t3.c0)))LIKE(CAST((0.13292931)::MONEY AS VARCHAR(971))))
UNION ALL SELECT t2.c0, t3.c0, t0.c0 FROM t0, ONLY t3 FULL OUTER JOIN t2 ON ((t2.c0)=(t3.c0))
WHERE NOT ((((('0.5496844753539182')||(t3.c0)))LIKE((CAST(0.13292931 AS MONEY))::VARCHAR(971))))
UNION ALL SELECT ALL t2.c0, t3.c0, t0.c0 FROM t0*, ONLY t3 FULL OUTER JOIN t2 ON ((t2.c0)=(t3.c0))
WHERE ((((('0.5496844753539182')||(t3.c0)))LIKE((CAST(0.13292931 AS MONEY))::VARCHAR(971)))) ISNULL;

will cause crash because of assert failure in 'create_plan_recurse'.

'apache#3  0x00007fe94eccf476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
 apache#4  0x00007fe94ecb57f3 in __GI_abort () at ./stdlib/abort.c:79
 apache#5  0x00007fe94fcdd548 in ExceptionalCondition (conditionName=0x7fe95043dcd0 "best_path->parallel_workers == best_path->locus.parallel_workers",
     errorType=0x7fe95043db06 "FailedAssertion", fileName=0x7fe95043dbdb "createplan.c", lineNumber=623) at assert.c:48
 apache#6  0x00007fe94f94918f in create_plan_recurse (root=0x55d7cbe96f78, best_path=0x55d7cbec0380, flags=1) at createplan.c:623
 apache#7  0x00007fe94f94a1f8 in create_append_plan (root=0x55d7cbe96f78, best_path=0x55d7cbec0700, flags=1) at createplan.c:1380
 apache#8  0x00007fe94f948d37 in create_plan_recurse (root=0x55d7cbe96f78, best_path=0x55d7cbec0700, flags=1) at createplan.c:481
 apache#9  0x00007fe94f94e2d1 in create_motion_plan (root=0x55d7cbe96f78, path=0x55d7cbec0e50) at createplan.c:3316
 #10 0x00007fe94f9490dc in create_plan_recurse (root=0x55d7cbe96f78, best_path=0x55d7cbec0e50, flags=1) at createplan.c:608
 apache#11 0x00007fe94f948ba3 in create_plan (root=0x55d7cbe96f78, best_path=0x55d7cbec0e50, curSlice=0x55d7cbe96f20) at createplan.c:392'

The parallel_workers should be set to zero because parallel full join is not supported yet.
robozmey added a commit to robozmey/cloudberrydb that referenced this pull request Dec 13, 2024
Dumps CdbExplain_NodeSummary struct in EXPLAIN ANALYZE

`set gp_enable_explain_node_summary=on;`

`drop table if exists tt; create table tt (a int, b int) distributed randomly;`

`explain (analyze,verbose) insert into tt select * from generate_series(1,1000)a,generate_series(1,1000)b;`

`explain (analyze,verbose) select * from tt where a > b;`

```
                                                                                                               QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..431.00 rows=1 width=8) (actual time=33.612..78.159 rows=1000 loops=1)
   Output: a, b
   Node Summary:                  vmax       vsum       vcnt       imax
     ntuples:                     1000       1000          1         -1
     execmemused:                    0          0          0          0
     workmemused:                    0          0          0          0
     workmemwanted:                  0          0          0          0
     totalWorkfileCreated:           0          0          0          0
     peakMemBalance:             44592      44592          1         -1
     totalPartTableScanned:          0          0          0          0
     segindex0: -1
     ninst: 1
     StatInsts:
       (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
       (seg-1) 241 0.00 0.03 0.08 1000.00 1.00 0 0 0 0 0 0 44592.00 0 0 0 0 0 0 0
   ->  Seq Scan on public.tt  (cost=0.00..431.00 rows=1 width=8) (actual time=2.512..77.640 rows=353 loops=1)
         Output: a, b
         Filter: (tt.a = 100)
         Node Summary:                  vmax       vsum       vcnt       imax
           ntuples:                      353       1000          3          0
           execmemused:                    0          0          0          0
           workmemused:                    0          0          0          0
           workmemwanted:                  0          0          0          0
           totalWorkfileCreated:           0          0          0          0
           peakMemBalance:             19072      57216          3          0
           totalPartTableScanned:          0          0          0          0
           segindex0: 0
           ninst: 3
           StatInsts:
             (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
             (seg0) 211 0.00 0.00 0.08 353.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg1) 211 0.00 0.00 0.03 330.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg2) 211 0.00 0.00 0.05 317.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
 Planning time: 4.514 ms
   (slice0)    Executor memory: 119K bytes.
   (slice1)    Executor memory: 27K bytes avg x 3 workers, 27K bytes max (seg0).
 Memory used:  128000kB
 Optimizer: Pivotal Optimizer (GPORCA)
 Execution time: 78.584 ms
(39 rows)
```
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Dec 20, 2024
We've heard a couple of reports of people having trouble with
multi-gigabyte-sized query-texts files.  It occurred to me that on
32-bit platforms, there could be an issue with integer overflow
of calculations associated with the total query text size.
Address that with several changes:

1. Limit pg_stat_statements.max to INT_MAX / 2 not INT_MAX.
The hashtable code will bound it to that anyway unless "long"
is 64 bits.  We still need overflow guards on its use, but
this helps.

2. Add a check to prevent extending the query-texts file to
more than MaxAllocHugeSize.  If it got that big, qtext_load_file
would certainly fail, so there's not much point in allowing it.
Without this, we'd need to consider whether extent, query_offset,
and related variables shouldn't be off_t not size_t.

3. Adjust the comparisons in need_gc_qtexts() to be done in 64-bit
arithmetic on all platforms.  It appears possible that under duress
those multiplications could overflow 32 bits, yielding a false
conclusion that we need to garbage-collect the texts file, which
could lead to repeatedly garbage-collecting after every hash table
insertion.

Per report from Bruno da Silva.  I'm not convinced that these
issues fully explain his problem; there may be some other bug that's
contributing to the query-texts file becoming so large in the first
place.  But it did get that big, so apache#2 is a reasonable defense,
and apache#3 could explain the reported performance difficulties.

(See also commit 8bbe4cb, which addressed some related bugs.
The second Discussion: link is the thread that led up to that.)

This issue is old, and is primarily a problem for old platforms,
so back-patch.

Discussion: https://postgr.es/m/CAB+Nuk93fL1Q9eLOCotvLP07g7RAv4vbdrkm0cVQohDVMpAb9A@mail.gmail.com
Discussion: https://postgr.es/m/5601D354.5000703@BlueTreble.com
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Dec 22, 2024
We've heard a couple of reports of people having trouble with
multi-gigabyte-sized query-texts files.  It occurred to me that on
32-bit platforms, there could be an issue with integer overflow
of calculations associated with the total query text size.
Address that with several changes:

1. Limit pg_stat_statements.max to INT_MAX / 2 not INT_MAX.
The hashtable code will bound it to that anyway unless "long"
is 64 bits.  We still need overflow guards on its use, but
this helps.

2. Add a check to prevent extending the query-texts file to
more than MaxAllocHugeSize.  If it got that big, qtext_load_file
would certainly fail, so there's not much point in allowing it.
Without this, we'd need to consider whether extent, query_offset,
and related variables shouldn't be off_t not size_t.

3. Adjust the comparisons in need_gc_qtexts() to be done in 64-bit
arithmetic on all platforms.  It appears possible that under duress
those multiplications could overflow 32 bits, yielding a false
conclusion that we need to garbage-collect the texts file, which
could lead to repeatedly garbage-collecting after every hash table
insertion.

Per report from Bruno da Silva.  I'm not convinced that these
issues fully explain his problem; there may be some other bug that's
contributing to the query-texts file becoming so large in the first
place.  But it did get that big, so apache#2 is a reasonable defense,
and apache#3 could explain the reported performance difficulties.

(See also commit 8bbe4cb, which addressed some related bugs.
The second Discussion: link is the thread that led up to that.)

This issue is old, and is primarily a problem for old platforms,
so back-patch.

Discussion: https://postgr.es/m/CAB+Nuk93fL1Q9eLOCotvLP07g7RAv4vbdrkm0cVQohDVMpAb9A@mail.gmail.com
Discussion: https://postgr.es/m/5601D354.5000703@BlueTreble.com
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Dec 24, 2024
We've heard a couple of reports of people having trouble with
multi-gigabyte-sized query-texts files.  It occurred to me that on
32-bit platforms, there could be an issue with integer overflow
of calculations associated with the total query text size.
Address that with several changes:

1. Limit pg_stat_statements.max to INT_MAX / 2 not INT_MAX.
The hashtable code will bound it to that anyway unless "long"
is 64 bits.  We still need overflow guards on its use, but
this helps.

2. Add a check to prevent extending the query-texts file to
more than MaxAllocHugeSize.  If it got that big, qtext_load_file
would certainly fail, so there's not much point in allowing it.
Without this, we'd need to consider whether extent, query_offset,
and related variables shouldn't be off_t not size_t.

3. Adjust the comparisons in need_gc_qtexts() to be done in 64-bit
arithmetic on all platforms.  It appears possible that under duress
those multiplications could overflow 32 bits, yielding a false
conclusion that we need to garbage-collect the texts file, which
could lead to repeatedly garbage-collecting after every hash table
insertion.

Per report from Bruno da Silva.  I'm not convinced that these
issues fully explain his problem; there may be some other bug that's
contributing to the query-texts file becoming so large in the first
place.  But it did get that big, so apache#2 is a reasonable defense,
and apache#3 could explain the reported performance difficulties.

(See also commit 8bbe4cb, which addressed some related bugs.
The second Discussion: link is the thread that led up to that.)

This issue is old, and is primarily a problem for old platforms,
so back-patch.

Discussion: https://postgr.es/m/CAB+Nuk93fL1Q9eLOCotvLP07g7RAv4vbdrkm0cVQohDVMpAb9A@mail.gmail.com
Discussion: https://postgr.es/m/5601D354.5000703@BlueTreble.com
my-ship-it pushed a commit that referenced this pull request Dec 24, 2024
We've heard a couple of reports of people having trouble with
multi-gigabyte-sized query-texts files.  It occurred to me that on
32-bit platforms, there could be an issue with integer overflow
of calculations associated with the total query text size.
Address that with several changes:

1. Limit pg_stat_statements.max to INT_MAX / 2 not INT_MAX.
The hashtable code will bound it to that anyway unless "long"
is 64 bits.  We still need overflow guards on its use, but
this helps.

2. Add a check to prevent extending the query-texts file to
more than MaxAllocHugeSize.  If it got that big, qtext_load_file
would certainly fail, so there's not much point in allowing it.
Without this, we'd need to consider whether extent, query_offset,
and related variables shouldn't be off_t not size_t.

3. Adjust the comparisons in need_gc_qtexts() to be done in 64-bit
arithmetic on all platforms.  It appears possible that under duress
those multiplications could overflow 32 bits, yielding a false
conclusion that we need to garbage-collect the texts file, which
could lead to repeatedly garbage-collecting after every hash table
insertion.

Per report from Bruno da Silva.  I'm not convinced that these
issues fully explain his problem; there may be some other bug that's
contributing to the query-texts file becoming so large in the first
place.  But it did get that big, so #2 is a reasonable defense,
and #3 could explain the reported performance difficulties.

(See also commit 8bbe4cb, which addressed some related bugs.
The second Discussion: link is the thread that led up to that.)

This issue is old, and is primarily a problem for old platforms,
so back-patch.

Discussion: https://postgr.es/m/CAB+Nuk93fL1Q9eLOCotvLP07g7RAv4vbdrkm0cVQohDVMpAb9A@mail.gmail.com
Discussion: https://postgr.es/m/5601D354.5000703@BlueTreble.com
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Dec 24, 2024
We've heard a couple of reports of people having trouble with
multi-gigabyte-sized query-texts files.  It occurred to me that on
32-bit platforms, there could be an issue with integer overflow
of calculations associated with the total query text size.
Address that with several changes:

1. Limit pg_stat_statements.max to INT_MAX / 2 not INT_MAX.
The hashtable code will bound it to that anyway unless "long"
is 64 bits.  We still need overflow guards on its use, but
this helps.

2. Add a check to prevent extending the query-texts file to
more than MaxAllocHugeSize.  If it got that big, qtext_load_file
would certainly fail, so there's not much point in allowing it.
Without this, we'd need to consider whether extent, query_offset,
and related variables shouldn't be off_t not size_t.

3. Adjust the comparisons in need_gc_qtexts() to be done in 64-bit
arithmetic on all platforms.  It appears possible that under duress
those multiplications could overflow 32 bits, yielding a false
conclusion that we need to garbage-collect the texts file, which
could lead to repeatedly garbage-collecting after every hash table
insertion.

Per report from Bruno da Silva.  I'm not convinced that these
issues fully explain his problem; there may be some other bug that's
contributing to the query-texts file becoming so large in the first
place.  But it did get that big, so apache#2 is a reasonable defense,
and apache#3 could explain the reported performance difficulties.

(See also commit 8bbe4cb, which addressed some related bugs.
The second Discussion: link is the thread that led up to that.)

This issue is old, and is primarily a problem for old platforms,
so back-patch.

Discussion: https://postgr.es/m/CAB+Nuk93fL1Q9eLOCotvLP07g7RAv4vbdrkm0cVQohDVMpAb9A@mail.gmail.com
Discussion: https://postgr.es/m/5601D354.5000703@BlueTreble.com
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Dec 24, 2024
We've heard a couple of reports of people having trouble with
multi-gigabyte-sized query-texts files.  It occurred to me that on
32-bit platforms, there could be an issue with integer overflow
of calculations associated with the total query text size.
Address that with several changes:

1. Limit pg_stat_statements.max to INT_MAX / 2 not INT_MAX.
The hashtable code will bound it to that anyway unless "long"
is 64 bits.  We still need overflow guards on its use, but
this helps.

2. Add a check to prevent extending the query-texts file to
more than MaxAllocHugeSize.  If it got that big, qtext_load_file
would certainly fail, so there's not much point in allowing it.
Without this, we'd need to consider whether extent, query_offset,
and related variables shouldn't be off_t not size_t.

3. Adjust the comparisons in need_gc_qtexts() to be done in 64-bit
arithmetic on all platforms.  It appears possible that under duress
those multiplications could overflow 32 bits, yielding a false
conclusion that we need to garbage-collect the texts file, which
could lead to repeatedly garbage-collecting after every hash table
insertion.

Per report from Bruno da Silva.  I'm not convinced that these
issues fully explain his problem; there may be some other bug that's
contributing to the query-texts file becoming so large in the first
place.  But it did get that big, so apache#2 is a reasonable defense,
and apache#3 could explain the reported performance difficulties.

(See also commit 8bbe4cb, which addressed some related bugs.
The second Discussion: link is the thread that led up to that.)

This issue is old, and is primarily a problem for old platforms,
so back-patch.

Discussion: https://postgr.es/m/CAB+Nuk93fL1Q9eLOCotvLP07g7RAv4vbdrkm0cVQohDVMpAb9A@mail.gmail.com
Discussion: https://postgr.es/m/5601D354.5000703@BlueTreble.com
avamingli pushed a commit that referenced this pull request Jan 23, 2025
## Problem
An error occurs in python lib when a plpython function is executed.
After our analysis, in the user's cluster, a plpython UDF 
was running with the unstable network, and got a timeout error:
`failed to acquire resources on one or more segments`.
Then a plpython UDF was run in the same session, and the UDF
failed with GC error.

Here is the core dump:
```
2023-11-24 10:15:18.945507 CST,,,p2705198,th2081832064,,,,0,,,seg-1,,,,,"LOG","00000","3rd party error log:
    #0 0x7f7c68b6d55b in frame_dealloc /home/cc/repo/cpython/Objects/frameobject.c:509:5
    #1 0x7f7c68b5109d in gen_send_ex /home/cc/repo/cpython/Objects/genobject.c:108:9
    #2 0x7f7c68af9ddd in PyIter_Next /home/cc/repo/cpython/Objects/abstract.c:3118:14
    #3 0x7f7c78caa5c0 in PLy_exec_function /home/cc/repo/gpdb6/src/pl/plpython/plpy_exec.c:134:11
    #4 0x7f7c78cb5ffb in plpython_call_handler /home/cc/repo/gpdb6/src/pl/plpython/plpy_main.c:387:13
    #5 0x562f5e008bb5 in ExecMakeTableFunctionResult /home/cc/repo/gpdb6/src/backend/executor/execQual.c:2395:13
    #6 0x562f5e0dddec in FunctionNext_guts /home/cc/repo/gpdb6/src/backend/executor/nodeFunctionscan.c:142:5
    #7 0x562f5e0da094 in FunctionNext /home/cc/repo/gpdb6/src/backend/executor/nodeFunctionscan.c:350:11
    #8 0x562f5e03d4b0 in ExecScanFetch /home/cc/repo/gpdb6/src/backend/executor/execScan.c:84:9
    #9 0x562f5e03cd8f in ExecScan /home/cc/repo/gpdb6/src/backend/executor/execScan.c:154:10
    #10 0x562f5e0da072 in ExecFunctionScan /home/cc/repo/gpdb6/src/backend/executor/nodeFunctionscan.c:380:9
    #11 0x562f5e001a1c in ExecProcNode /home/cc/repo/gpdb6/src/backend/executor/execProcnode.c:1071:13
    #12 0x562f5dfe6377 in ExecutePlan /home/cc/repo/gpdb6/src/backend/executor/execMain.c:3202:10
    #13 0x562f5dfe5bf4 in standard_ExecutorRun /home/cc/repo/gpdb6/src/backend/executor/execMain.c:1171:5
    #14 0x562f5dfe4877 in ExecutorRun /home/cc/repo/gpdb6/src/backend/executor/execMain.c:992:4
    #15 0x562f5e857e69 in PortalRunSelect /home/cc/repo/gpdb6/src/backend/tcop/pquery.c:1164:4
    #16 0x562f5e856d3f in PortalRun /home/cc/repo/gpdb6/src/backend/tcop/pquery.c:1005:18
    #17 0x562f5e84607a in exec_simple_query /home/cc/repo/gpdb6/src/backend/tcop/postgres.c:1848:10
```

## Reproduce
We can use a simple procedure to reproduce the above problem:
- set timeout GUC: `gpconfig -c gp_segment_connect_timeout -v 5` and `gpstop -ari`
- prepare function:
```
CREATE EXTENSION plpythonu;
CREATE OR REPLACE FUNCTION test_func() RETURNS SETOF int AS
$$
plpy.execute("select pg_backend_pid()")

for i in range(0, 5):
    yield (i)

$$ LANGUAGE plpythonu;
```
- exit from the current psql session.
- stop the postmaster of segment: `gdb -p "the pid of segment postmaster"`
- enter a psql session.
- call `SELECT test_func();` and get error
```
gpadmin=# select test_func();
ERROR:  function "test_func" error fetching next item from iterator (plpy_elog.c:121)
DETAIL:  Exception: failed to acquire resources on one or more segments
CONTEXT:  Traceback (most recent call last):
PL/Python function "test_func"
```
- quit gdb and make postmaster runnable.
- call  `SELECT test_func();` again and get panic
```
gpadmin=# SELECT test_func();
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!> 
```

## Analysis
- There is an SPI call in test_func(): `plpy.execute()`. 
- Then coordinator will start a subtransaction by PLy_spi_subtransaction_begin();
- Meanwhile, if the segment cannot receive the instruction from the coordinator,
  the subtransaction beginning procedure return fails.
- BUT! The Python processor does not know whether an error happened and
  does not clean its environment.
- Then the next plpython UDF in the same session will fail due to the wrong
  Python environment.

## Solution
- Use try-catch to catch the exception caused by PLy_spi_subtransaction_begin()
- set the python error indicator by PLy_spi_exception_set()


Co-authored-by: Chen Mulong <chenmulong@gmail.com>
robozmey added a commit to robozmey/cloudberrydb that referenced this pull request Mar 25, 2025
Dumps CdbExplain_NodeSummary struct in EXPLAIN ANALYZE

`set gp_enable_explain_node_summary=on;`

`drop table if exists tt; create table tt (a int, b int) distributed randomly;`

`explain (analyze,verbose) insert into tt select * from generate_series(1,1000)a,generate_series(1,1000)b;`

`explain (analyze,verbose) select * from tt where a > b;`

```
                                                                                                               QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..431.00 rows=1 width=8) (actual time=33.612..78.159 rows=1000 loops=1)
   Output: a, b
   Node Summary:                  vmax       vsum       vcnt       imax
     ntuples:                     1000       1000          1         -1
     execmemused:                    0          0          0          0
     workmemused:                    0          0          0          0
     workmemwanted:                  0          0          0          0
     totalWorkfileCreated:           0          0          0          0
     peakMemBalance:             44592      44592          1         -1
     totalPartTableScanned:          0          0          0          0
     segindex0: -1
     ninst: 1
     StatInsts:
       (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
       (seg-1) 241 0.00 0.03 0.08 1000.00 1.00 0 0 0 0 0 0 44592.00 0 0 0 0 0 0 0
   ->  Seq Scan on public.tt  (cost=0.00..431.00 rows=1 width=8) (actual time=2.512..77.640 rows=353 loops=1)
         Output: a, b
         Filter: (tt.a = 100)
         Node Summary:                  vmax       vsum       vcnt       imax
           ntuples:                      353       1000          3          0
           execmemused:                    0          0          0          0
           workmemused:                    0          0          0          0
           workmemwanted:                  0          0          0          0
           totalWorkfileCreated:           0          0          0          0
           peakMemBalance:             19072      57216          3          0
           totalPartTableScanned:          0          0          0          0
           segindex0: 0
           ninst: 3
           StatInsts:
             (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
             (seg0) 211 0.00 0.00 0.08 353.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg1) 211 0.00 0.00 0.03 330.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg2) 211 0.00 0.00 0.05 317.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
 Planning time: 4.514 ms
   (slice0)    Executor memory: 119K bytes.
   (slice1)    Executor memory: 27K bytes avg x 3 workers, 27K bytes max (seg0).
 Memory used:  128000kB
 Optimizer: Pivotal Optimizer (GPORCA)
 Execution time: 78.584 ms
(39 rows)
```
robozmey added a commit to robozmey/cloudberrydb that referenced this pull request Apr 8, 2025
Dumps CdbExplain_NodeSummary struct in EXPLAIN ANALYZE

`set gp_enable_explain_node_summary=on;`

`drop table if exists tt; create table tt (a int, b int) distributed randomly;`

`explain (analyze,verbose) insert into tt select * from generate_series(1,1000)a,generate_series(1,1000)b;`

`explain (analyze,verbose) select * from tt where a > b;`

```
                                                                                                               QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..431.00 rows=1 width=8) (actual time=33.612..78.159 rows=1000 loops=1)
   Output: a, b
   Node Summary:                  vmax       vsum       vcnt       imax
     ntuples:                     1000       1000          1         -1
     execmemused:                    0          0          0          0
     workmemused:                    0          0          0          0
     workmemwanted:                  0          0          0          0
     totalWorkfileCreated:           0          0          0          0
     peakMemBalance:             44592      44592          1         -1
     totalPartTableScanned:          0          0          0          0
     segindex0: -1
     ninst: 1
     StatInsts:
       (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
       (seg-1) 241 0.00 0.03 0.08 1000.00 1.00 0 0 0 0 0 0 44592.00 0 0 0 0 0 0 0
   ->  Seq Scan on public.tt  (cost=0.00..431.00 rows=1 width=8) (actual time=2.512..77.640 rows=353 loops=1)
         Output: a, b
         Filter: (tt.a = 100)
         Node Summary:                  vmax       vsum       vcnt       imax
           ntuples:                      353       1000          3          0
           execmemused:                    0          0          0          0
           workmemused:                    0          0          0          0
           workmemwanted:                  0          0          0          0
           totalWorkfileCreated:           0          0          0          0
           peakMemBalance:             19072      57216          3          0
           totalPartTableScanned:          0          0          0          0
           segindex0: 0
           ninst: 3
           StatInsts:
             (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
             (seg0) 211 0.00 0.00 0.08 353.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg1) 211 0.00 0.00 0.03 330.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg2) 211 0.00 0.00 0.05 317.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
 Planning time: 4.514 ms
   (slice0)    Executor memory: 119K bytes.
   (slice1)    Executor memory: 27K bytes avg x 3 workers, 27K bytes max (seg0).
 Memory used:  128000kB
 Optimizer: Pivotal Optimizer (GPORCA)
 Execution time: 78.584 ms
(39 rows)
```
robozmey added a commit to robozmey/cloudberrydb that referenced this pull request May 19, 2025
Dumps CdbExplain_NodeSummary struct in EXPLAIN ANALYZE

`set gp_enable_explain_node_summary=on;`

`drop table if exists tt; create table tt (a int, b int) distributed randomly;`

`explain (analyze,verbose) insert into tt select * from generate_series(1,1000)a,generate_series(1,1000)b;`

`explain (analyze,verbose) select * from tt where a > b;`

```
                                                                                                               QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..431.00 rows=1 width=8) (actual time=33.612..78.159 rows=1000 loops=1)
   Output: a, b
   Node Summary:                  vmax       vsum       vcnt       imax
     ntuples:                     1000       1000          1         -1
     execmemused:                    0          0          0          0
     workmemused:                    0          0          0          0
     workmemwanted:                  0          0          0          0
     totalWorkfileCreated:           0          0          0          0
     peakMemBalance:             44592      44592          1         -1
     totalPartTableScanned:          0          0          0          0
     segindex0: -1
     ninst: 1
     StatInsts:
       (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
       (seg-1) 241 0.00 0.03 0.08 1000.00 1.00 0 0 0 0 0 0 44592.00 0 0 0 0 0 0 0
   ->  Seq Scan on public.tt  (cost=0.00..431.00 rows=1 width=8) (actual time=2.512..77.640 rows=353 loops=1)
         Output: a, b
         Filter: (tt.a = 100)
         Node Summary:                  vmax       vsum       vcnt       imax
           ntuples:                      353       1000          3          0
           execmemused:                    0          0          0          0
           workmemused:                    0          0          0          0
           workmemwanted:                  0          0          0          0
           totalWorkfileCreated:           0          0          0          0
           peakMemBalance:             19072      57216          3          0
           totalPartTableScanned:          0          0          0          0
           segindex0: 0
           ninst: 3
           StatInsts:
             (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
             (seg0) 211 0.00 0.00 0.08 353.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg1) 211 0.00 0.00 0.03 330.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg2) 211 0.00 0.00 0.05 317.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
 Planning time: 4.514 ms
   (slice0)    Executor memory: 119K bytes.
   (slice1)    Executor memory: 27K bytes avg x 3 workers, 27K bytes max (seg0).
 Memory used:  128000kB
 Optimizer: Pivotal Optimizer (GPORCA)
 Execution time: 78.584 ms
(39 rows)
```
robozmey added a commit to robozmey/cloudberrydb that referenced this pull request Jun 11, 2025
Dumps CdbExplain_NodeSummary struct in EXPLAIN ANALYZE

`set gp_enable_explain_node_summary=on;`

`drop table if exists tt; create table tt (a int, b int) distributed randomly;`

`explain (analyze,verbose) insert into tt select * from generate_series(1,1000)a,generate_series(1,1000)b;`

`explain (analyze,verbose) select * from tt where a > b;`

```
                                                                                                               QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..431.00 rows=1 width=8) (actual time=33.612..78.159 rows=1000 loops=1)
   Output: a, b
   Node Summary:                  vmax       vsum       vcnt       imax
     ntuples:                     1000       1000          1         -1
     execmemused:                    0          0          0          0
     workmemused:                    0          0          0          0
     workmemwanted:                  0          0          0          0
     totalWorkfileCreated:           0          0          0          0
     peakMemBalance:             44592      44592          1         -1
     totalPartTableScanned:          0          0          0          0
     segindex0: -1
     ninst: 1
     StatInsts:
       (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
       (seg-1) 241 0.00 0.03 0.08 1000.00 1.00 0 0 0 0 0 0 44592.00 0 0 0 0 0 0 0
   ->  Seq Scan on public.tt  (cost=0.00..431.00 rows=1 width=8) (actual time=2.512..77.640 rows=353 loops=1)
         Output: a, b
         Filter: (tt.a = 100)
         Node Summary:                  vmax       vsum       vcnt       imax
           ntuples:                      353       1000          3          0
           execmemused:                    0          0          0          0
           workmemused:                    0          0          0          0
           workmemwanted:                  0          0          0          0
           totalWorkfileCreated:           0          0          0          0
           peakMemBalance:             19072      57216          3          0
           totalPartTableScanned:          0          0          0          0
           segindex0: 0
           ninst: 3
           StatInsts:
             (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
             (seg0) 211 0.00 0.00 0.08 353.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg1) 211 0.00 0.00 0.03 330.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg2) 211 0.00 0.00 0.05 317.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
 Planning time: 4.514 ms
   (slice0)    Executor memory: 119K bytes.
   (slice1)    Executor memory: 27K bytes avg x 3 workers, 27K bytes max (seg0).
 Memory used:  128000kB
 Optimizer: Pivotal Optimizer (GPORCA)
 Execution time: 78.584 ms
(39 rows)
```
robozmey added a commit to robozmey/cloudberrydb that referenced this pull request Jul 16, 2025
Dumps CdbExplain_NodeSummary struct in EXPLAIN ANALYZE

`set gp_enable_explain_node_summary=on;`

`drop table if exists tt; create table tt (a int, b int) distributed randomly;`

`explain (analyze,verbose) insert into tt select * from generate_series(1,1000)a,generate_series(1,1000)b;`

`explain (analyze,verbose) select * from tt where a > b;`

```
                                                                                                               QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..431.00 rows=1 width=8) (actual time=33.612..78.159 rows=1000 loops=1)
   Output: a, b
   Node Summary:                  vmax       vsum       vcnt       imax
     ntuples:                     1000       1000          1         -1
     execmemused:                    0          0          0          0
     workmemused:                    0          0          0          0
     workmemwanted:                  0          0          0          0
     totalWorkfileCreated:           0          0          0          0
     peakMemBalance:             44592      44592          1         -1
     totalPartTableScanned:          0          0          0          0
     segindex0: -1
     ninst: 1
     StatInsts:
       (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
       (seg-1) 241 0.00 0.03 0.08 1000.00 1.00 0 0 0 0 0 0 44592.00 0 0 0 0 0 0 0
   ->  Seq Scan on public.tt  (cost=0.00..431.00 rows=1 width=8) (actual time=2.512..77.640 rows=353 loops=1)
         Output: a, b
         Filter: (tt.a = 100)
         Node Summary:                  vmax       vsum       vcnt       imax
           ntuples:                      353       1000          3          0
           execmemused:                    0          0          0          0
           workmemused:                    0          0          0          0
           workmemwanted:                  0          0          0          0
           totalWorkfileCreated:           0          0          0          0
           peakMemBalance:             19072      57216          3          0
           totalPartTableScanned:          0          0          0          0
           segindex0: 0
           ninst: 3
           StatInsts:
             (segN) pstype starttime counter firsttuple startup total ntuples nloops execmemused workmemused workmemwanted workfileCreated firststart peakMemBalance numPartScanned sortMethod sortSpaceType sortSpaceUsed bnotes enotes
             (seg0) 211 0.00 0.00 0.08 353.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg1) 211 0.00 0.00 0.03 330.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
             (seg2) 211 0.00 0.00 0.05 317.00 1.00 0 0 0 0 0 0 19072.00 0 0 0 0 0 0 0
 Planning time: 4.514 ms
   (slice0)    Executor memory: 119K bytes.
   (slice1)    Executor memory: 27K bytes avg x 3 workers, 27K bytes max (seg0).
 Memory used:  128000kB
 Optimizer: Pivotal Optimizer (GPORCA)
 Execution time: 78.584 ms
(39 rows)
```
reshke added a commit that referenced this pull request Sep 19, 2025
leborchuk referenced this pull request in leborchuk/cloudberry Sep 2, 2026
Upstream PostgreSQL commit "Remove configure probe for sockaddr_in6 and
require AF_INET6." (bcc8b14) deleted the HAVE_IPV6 probe and stripped the
#ifdef HAVE_IPV6 guards from its own code, since AF_INET6 is now always
available. Cloudberry-specific code still gated IPv6 handling behind
#ifdef HAVE_IPV6, so after the PG16 merge those blocks became dead code:
HAVE_IPV6 is never defined on non-Windows builds.

The practical effect: on an IPv6-only cluster, getDnsCachedAddress() never
populates its cache entry (the IPv6 branch was compiled out), then returns
e->hostinfo with e == NULL -- a bogus non-NULL pointer (offsetof key[]) --
which the caller passes to pstrdup(), crashing in strlen(). This shows up
as a coordinator/FtsProbe SIGSEGV:

  #0 __strlen_evex
  #1 MemoryContextStrdup
  #2 getCdbComponentInfo
  #3 cdbcomponent_getCdbComponents
  apache#4 FtsProbeMain

Remove the leftover #ifdef HAVE_IPV6 guards so the IPv6 paths compile
unconditionally, matching what upstream did to its own files. Also guard
the cache return against a NULL entry so an unresolvable segment logs a
clean "cannot resolve network address" error instead of segfaulting.

Files: cdbutil.c (both getDnsCachedAddress copies), auth.c, and the
interconnect listener setup (ic_common.c, ic_tcp.c, ic_udpifc.c).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
leborchuk added a commit that referenced this pull request Sep 11, 2026
Upstream PostgreSQL commit "Remove configure probe for sockaddr_in6 and
require AF_INET6." (bcc8b14) deleted the HAVE_IPV6 probe and stripped the
#ifdef HAVE_IPV6 guards from its own code, since AF_INET6 is now always
available. Cloudberry-specific code still gated IPv6 handling behind
#ifdef HAVE_IPV6, so after the PG16 merge those blocks became dead code:
HAVE_IPV6 is never defined on non-Windows builds.

The practical effect: on an IPv6-only cluster, getDnsCachedAddress() never
populates its cache entry (the IPv6 branch was compiled out), then returns
e->hostinfo with e == NULL -- a bogus non-NULL pointer (offsetof key[]) --
which the caller passes to pstrdup(), crashing in strlen(). This shows up
as a coordinator/FtsProbe SIGSEGV:

  #0 __strlen_evex
  #1 MemoryContextStrdup
  #2 getCdbComponentInfo
  #3 cdbcomponent_getCdbComponents
  #4 FtsProbeMain

Remove the leftover #ifdef HAVE_IPV6 guards so the IPv6 paths compile
unconditionally, matching what upstream did to its own files. Also guard
the cache return against a NULL entry so an unresolvable segment logs a
clean "cannot resolve network address" error instead of segfaulting.

Files: cdbutil.c (both getDnsCachedAddress copies), auth.c, and the
interconnect listener setup (ic_common.c, ic_tcp.c, ic_udpifc.c).

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
leborchuk pushed a commit that referenced this pull request Sep 29, 2026
checkExtensionMembership() set the DUMP_COMPONENT_SECLABEL and
DUMP_COMPONENT_POLICY flags for extension member objects, even though
we lack any infrastructure for tracking extensions' initial settings
of these properties.  This is not OK.  The result was that a dump
would always include commands to set these properties for extension
objects that have them, with at least three negative consequences:

1. The restoring user might not have privilege to set these properties
on these objects.

2. The properties might be incorrect/irrelevant for the version of the
extension that's installed in the destination database.

3. The dump itself might fail, in the case of RLS properties attached
to extension tables that the dumping user lacks privilege to LOCK.
(That's because we must get at least AccessShareLock to ensure that
we don't fail while trying to decompile the RLS expressions.)

When and if somebody cares to invent initial-state infrastructure for
extensions' RLS policies and security labels, we could think about
finding another way around problem #3.  But in the absence of such
infrastructure, this whole thing is just wrong and we shouldn't do it.

(Note: this applies only to ordinary dumps; binary-upgrade dumps
still dump and restore extension member objects separately, with
all properties.)

Tom Lane and Jacob Champion.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/00d46a48-3324-d9a0-49bf-e7f0f11d1038@timescale.com
(cherry picked from commit 15439205d8cec6fff71e77f0fdd935129120edd0)
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Oct 27, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Oct 27, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Oct 27, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Oct 27, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Oct 27, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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 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 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.
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Oct 28, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit that referenced this pull request Oct 31, 2026
UBSan reported a misaligned member access when decoding the
distributed-transaction field of commit WAL records during
crash-recovery redo. The WAL record payload has no alignment
guarantee; the neighboring xl_origin branch already copies onto the
stack for exactly this reason. Do the same for xl_xact_distrib.

Sanitizer report (UBSan, instrumented build, crash recovery):
  xactdesc.c:155:34: runtime error: member access within misaligned
  address 0x7b39d104de44 for type 'struct xl_xact_distrib', which
  requires 8 byte alignment
  #0 ParseCommitRecord xactdesc.c:155
  #1 xact_redo xactdesc.c:...
  #2 ApplyWalRecord xlogrecovery.c:2023
  #3 PerformWalRecovery xlogrecovery.c:1845
Undefined behavior at recovery time; harmless on x86_64 but
incorrect on strictly aligned targets.
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Nov 9, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Nov 9, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Nov 16, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Nov 17, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit to yjhjstz/cloudberry that referenced this pull request Nov 17, 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit to yjhjstz/cloudberry 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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.
yjhjstz pushed a commit to yjhjstz/cloudberry 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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 to yjhjstz/cloudberry 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():

  apache#2 aocs_gettuple (targrow=69896) at aocsam.c:1339
  apache#3 aocs_get_target_tuple
  apache#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 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 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
#7  ExecProcNodeFirst (node=0x6464a0549f48) at execProcnode.c:633
#8  0x0000646474e91e6a in ExecProcNode (node=0x6464a0549f48) at ../../../src/include/executor/executor.h:305
#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
#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
#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
#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
#14 0x0000646475174247 in FillPortalStore (portal=portal@entry=0x6464a04ad358, isTopLevel=isTopLevel@entry=true) at pquery.c:1241
#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
#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
#17 0x0000646475172a87 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:5933
#18 0x00006464750a4aab in BackendRun (port=0x6464a044eec0) at postmaster.c:5095
#19 BackendStartup (port=0x6464a044eec0) at postmaster.c:4805
#20 ServerLoop () at postmaster.c:2107
#21 0x00006464750a5a8b in PostmasterMain (argc=argc@entry=7, argv=argv@entry=0x6464a040cee0) at postmaster.c:1750
#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
    #7  0x000056220af98e1b in PerformMembersTruncation (oldestOffset=<optimized out>, newOldestOffset=<optimized out>) at ../src/backend/access/transam/multixact.c:3006
    #8  TruncateMultiXact (newOldestMulti=newOldestMulti@entry=3221225472, newOldestMultiDB=newOldestMultiDB@entry=4) at ../src/backend/access/transam/multixact.c:3201
    #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
    #11 0x000056220b1c3f76 in do_autovacuum () at ../src/backend/postmaster/autovacuum.c:2550
    #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
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.

1 participant