gpdb icon indicating copy to clipboard operation
gpdb copied to clipboard

Fix CTAS crash.

Open avamingli opened this issue 1 year ago • 6 comments

reproduce

gpadmin=# select version();

        version

--------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------
------------------------
 PostgreSQL 12.12 (Greenplum Database 7.1.0+dev.109.g2a14c41782d build dev) on x86_64-pc-linux-gnu, comp
iled by gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0, 64-bit compiled on Feb  1 2024 17:30:04 (with asser
t checking) Bhuvnesh C.
(1 row)

set optimizer=off;
create table t_random(id int) distributed randomly;
create table t_rep as select random() from t_random distributed replicated;

coredump

#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140077450003712)
    at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=140077450003712) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=140077450003712, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007f6655660476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007f66556467f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000055d4810191ff in ExceptionalCondition (
    conditionName=0x55d48173a5b0 "!(!((((const Node*)(lefttree))->type) == T_Motion))",
    errorType=0x55d4817394c6 "FailedAssertion", fileName=0x55d481739516 "createplan.c",
    lineNumber=7228) at assert.c:44
#6  0x000055d480cd2328 in make_motion (root=0x0, lefttree=0x55d4886bb650, numSortCols=0,
    sortColIdx=0x0, sortOperators=0x0, collations=0x0, nullsFirst=0x0) at createplan.c:7228
#7  0x000055d48111a55b in make_broadcast_motion (lefttree=0x55d4886bb650) at cdbmutate.c:140
#8  0x000055d480cd43a1 in cdbpathtoplan_create_motion_plan (root=0x55d4887b6790, path=0x55d4886ba948,
    subplan=0x55d4886bb650) at createplan.c:8160
#9  0x000055d480cca457 in create_motion_plan (root=0x55d4887b6790, path=0x55d4886ba948)
    at createplan.c:3165
#10 0x000055d480cc5a0c in create_plan_recurse (root=0x55d4887b6790, best_path=0x55d4886ba948, flags=1)
    at createplan.c:564
#11 0x000055d480cc545a in create_plan (root=0x55d4887b6790, best_path=0x55d4886ba948,
    curSlice=0x55d4887b6738) at createplan.c:363
#12 0x000055d480cda8ab in standard_planner (parse=0x55d4887b5ee8, cursorOptions=256, boundParams=0x0)
    at planner.c:579

RC

If we create a replicated table when selecting project volatile functions from a randomly distributed table, we will try to add a Motion on a Motion node that will cause a crash. Create table t1(id int) distributed randomly; Create table t2 as select random() from t1 distributed replicated;

planner may have add a top Motion earlier if we know the query's final locus. Some codes handle volatile functions lead us to create_motion_path_for_insert(), and we should consider the case to avoid Assertion failure when create_plan().

Authored-by: Zhang Mingli [email protected]

Here are some reminders before you submit the pull request

  • [ ] Add tests for the change
  • [ ] Document changes
  • [ ] Communicate in the mailing list if needed
  • [ ] Pass make installcheck
  • [ ] Review a PR in return to support the community

avamingli avatar Feb 01 '24 10:02 avamingli