Skip to content

Catch up Gitlab commits - #19

Merged
my-ship-it merged 9 commits into
apache:mainfrom
avamingli:catchup_gitlab
Jul 24, 2023
Merged

my-ship-it merged 9 commits into
apache:mainfrom
avamingli:catchup_gitlab

Conversation

@avamingli

@avamingli avamingli commented Jul 19, 2023 •

Copy link
Copy Markdown
Contributor

Change logs

We have been opened source CBDB for a while and it lags behind Gitlab a lot.
This pr catches up commits
from
This commit adds UnionStore table for CBDB, we need to create extenti…
to
Exclude unnecessary files when not enable ic_proxy
Mostly cherry-pick from master branch of Gitlab with some commit messages refinement.

Contributor's Checklist

Here are some reminders before you submit the pull request:

  • Document changes
  • Communicate in the GitHub Issues or Discussions (list them if needed)
  • Add tests for the change
  • Pass make installcheck
  • Pass make -C src/test installcheck-cbdb-parallel

leo and others added 8 commits July 19, 2023 17:22
…on unionstore to enable this feature. We can create UnionStore table using syntax: create table xxx using union_store.

We seperate WAL records related with UnionStore table from other WAL records, send those records to UnionStore through UnionStore's XLog system. UnionStore constructs pages to serve CBDB's page read requests.

The core changes of CBDB:

Add hook XLogInsert_hook for plugins to support more WAL managers.
Add UnionStore XLog system. Backends write WAL records into ring buffer, and WAL Proposer send the WAL records to WAL Service of UnionStore.
Add storage manager hook smgr_hook for plugins to add more storage managers.
Add t_cid to some XLog header, this is to ensure consistency of transaction.
Add hook ReadBuffer_hook for plugins to support more buffer read procedures
Add hook index_create_hook for plugins to support more index create procedures.
Add hook index_build_hook for plugins to support more index build procedures.
Add hook Startup_hook for plugins to do additional startup works.
Add hook relation_size_hook for plugins to calculate relation size.
Add hook NewSegRelfilenode_assign_hook for plugins to assign relfilenode.
Add hook start_bgworkers_hook for plugins to start background workers.
Other parts of code comes from neon postgres.

Design Doc: https://hashdata.feishu.cn/docx/QFSidS6jpoeGIjxgD5Pc2QFdnZe
This was introduced by 0798f4a, use brace for body of if else condition
nested to assertion macro to avoid compile error.
CBDB will try to elide motion node when create plan if we
are from a SingleQE to Entry.
But that only adjust the top node's locus.
However, the locus doesn't affect the plan for execution.
But when we explain show locus, it will confuse us because
the locus of a plan node shows where it executes.
And for Motion node, its locus is the target locus we want
to be.

explain(costs off, locus) select distinct min(c1), max(c1) from t1;
                         QUERY PLAN
------------------------------------------------------------
 Unique
   Locus: Entry
   Group Key: (min(c1)), (max(c1))
   ->  Sort
         Locus: SingleQE
         Sort Key: (min(c1)), (max(c1))
         ->  Aggregate
               Locus: SingleQE
               ->  Gather Motion 3:1  (slice1; segments: 3)
                     Locus: SingleQE
                     ->  Seq Scan on t1
                           Locus: Hashed

The real plan will execute Unique, Sort and Aggregate on QD after a Gather Motion.
So all the locus of nodes until Gather Motion are Entry locus.

This commit pushes the MotionPath's locus down onto descendant subpaths of the same slice.

explain(costs off, locus) select distinct min(f1), max(f1) from t1;
                         QUERY PLAN
------------------------------------------------------------
 Unique
   Locus: Entry
   Group Key: (min(f1)), (max(f1))
   ->  Sort
         Locus: Entry
         Sort Key: (min(f1)), (max(f1))
         ->  Aggregate
               Locus: Entry
               ->  Gather Motion 3:1  (slice1; segments: 3)
                     Locus: Entry
                     ->  Seq Scan on t1
                           Locus: Hashed

Authored-by: Zhang Mingli avamingli@gmail.com
There would be a memory detected write warning if targetlist or
qual is null for AOCS table.
Enlarge columns array size to natts + 1 to avoid that as heap tables.

A sql like below will get there:
SET default_table_access_method=ao_column;
create temp table nocolumns();
select exists(select * from nocolumns);
When sample scan on AOCS, the relationTupleDesc in aocs_rescan is not set.
That will cause a assertion failure that scan->columnScanInfo.relationTupleDesc
is not null.
This commit will set that relationTupleDesc if it is null.
Some temp file are forgetten to be removed after regression.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/test/regress/data/minirepro_q.sql
        src/test/regress/data/part_ext.tbl
        src/test/regress/expected/external_table_union_all.out
        src/test/regress/expected/external_table_union_all_optimizer.out
        src/test/regress/sql/external_table_union_all.sql

Clean them all to avoid git diffs after regression is passed.

Authored-by: Zhang Mingli avamingli@gmail.com
Split interconnect code as a module into contrib/intercontect
A new interconnect interface in ml_ipc.h
  The new interconnect interface is decoupled from the motion layer
  The new interconnect interface makes it easier to add an interconnect implementation
* ic_proxy_bgworker.c/ic_proxy_bgworker.h still remains in cbdb
This commit fixes vectorized query call function result loss problem.

In the vectorization scenario, customize a function as follows
CREATE FUNCTION equipment_named_ambiguous_2b(hobby text)
    RETURNS setof equipment_r
    AS 'select * from equipment_r where equipment_r.hobby = hobby'
    LANGUAGE SQL;

Execute select equipment_named_ambiguous_2b(text 'skywalking'),results will be lost.
For the internal sql of the function, 'select * from equipment_r where equipment_r.hobby = hobby' follows the vectorized execution path,
 and the returned result is multiple tuples. There is such a piece of code in the implementation logic of the function fmgr_sql:

/* Extract the result as a datum, and copy out from the slot */
result = postquel_get_single_result(slot, fcinfo,
fcache, oldcontext);
/* Clear the tuplestore, but keep it for next time */
/* NB: this might delete the slot's content, but we don't care */
tuplestore_clear(fcache->tstore);

Every time a tuple is returned, the tuplestore_clear will be called to clean up, which will cause the data loss of the query result.
@CLAassistant

CLAassistant commented Jul 19, 2023 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiiii, @avamingli welcome!🎊 Thanks for taking the effort to make our project better! 🙌 Keep making such awesome contributions!

@avamingli

Copy link
Copy Markdown
Contributor Author

@my-ship-it

@tuhaihe

tuhaihe commented Jul 20, 2023 •

Copy link
Copy Markdown
Member

Hi @avamingli, I'm planning the new license header rules for Cloudberry Database, so we can adopt them before merging this PR. Let me know if you have any concerns. /cc @my-ship-it

We don't need extra libs like libuv when config without --enable-ic-porxy.
Use ENABLE_IC_PROXY to identify dependency.
@avamingli

Copy link
Copy Markdown
Contributor Author

CI passed, thanks @sandiandian for more resources.

@yjhjstz yjhjstz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@my-ship-it
my-ship-it merged commit 9979adb into apache:main Jul 24, 2023
@avamingli
avamingli deleted the catchup_gitlab branch July 24, 2023 07:52
Jaroslavian referenced this pull request in open-gpdb/cloudberry Jan 15, 2026
* ereport(log) bug queries at the end of extension
reshke added a commit to reshke/cloudberrydb that referenced this pull request Nov 14, 2026
A replicated data-modifying CTE with ORDER BY reaches the sorted receiver with motionType GATHER_SINGLE, sendSorted set, and a non-NULL merge heap. It tripped the nodeMotion.c:441 assertion, which only allowed GATHER. Permit GATHER_SINGLE while retaining the sendSorted and heap checks.

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

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

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

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

7 participants