This is an automated email from the ASF dual-hosted git repository.
avamingli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
The following commit(s) were added to refs/heads/main by this push:
new 6b968245a59 Fix CTAS crash.
6b968245a59 is described below
commit 6b968245a59fc4e26b0cd842412c33403738afe2
Author: Zhang Mingli <[email protected]>
AuthorDate: Wed Jul 9 10:59:54 2025 +0800
Fix CTAS crash.
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]
---
src/backend/cdb/cdbpath.c | 10 +++++++++-
src/test/regress/expected/bfv_planner.out | 2 ++
src/test/regress/expected/bfv_planner_optimizer.out | 2 ++
src/test/regress/sql/bfv_planner.sql | 3 +++
4 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/backend/cdb/cdbpath.c b/src/backend/cdb/cdbpath.c
index e6b60509342..d19bb141a4b 100644
--- a/src/backend/cdb/cdbpath.c
+++ b/src/backend/cdb/cdbpath.c
@@ -2622,7 +2622,15 @@ create_motion_path_for_insert(PlannerInfo *root,
GpPolicy *policy,
}
}
- subpath = cdbpath_create_broadcast_motion_path(root, subpath,
policy->numsegments);
+
+ /*
+ * planner may have add a top Motion eariler.
+ * Create table t1(id int) distributed randomly;
+ * Create table t2 as select random() from t1 distributed
replicated;
+ * Avoid Motion if there was already one.
+ */
+ if (!CdbPathLocus_IsReplicated(subpath->locus))
+ subpath = cdbpath_create_broadcast_motion_path(root,
subpath, policy->numsegments);
}
else
elog(ERROR, "unrecognized policy type %u", policyType);
diff --git a/src/test/regress/expected/bfv_planner.out
b/src/test/regress/expected/bfv_planner.out
index 139b470152a..eafe2e8bc15 100644
--- a/src/test/regress/expected/bfv_planner.out
+++ b/src/test/regress/expected/bfv_planner.out
@@ -663,6 +663,8 @@ select count(distinct nextval) from
gp_dist_random('t_rep4');
(1 row)
drop table rep_tbl, t_rep4;
+create table t_issue_1218_random(id int) distributed randomly;
+create table t_issue_1218_replicated as select random() from
t_issue_1218_random distributed replicated;
--
-- Test append different numsegments tables work well
-- See Github issue: https://github.com/greenplum-db/gpdb/issues/12146
diff --git a/src/test/regress/expected/bfv_planner_optimizer.out
b/src/test/regress/expected/bfv_planner_optimizer.out
index e1ca30b7544..56ab8968024 100644
--- a/src/test/regress/expected/bfv_planner_optimizer.out
+++ b/src/test/regress/expected/bfv_planner_optimizer.out
@@ -681,6 +681,8 @@ select count(distinct nextval) from
gp_dist_random('t_rep4');
(1 row)
drop table rep_tbl, t_rep4;
+create table t_issue_1218_random(id int) distributed randomly;
+create table t_issue_1218_replicated as select random() from
t_issue_1218_random distributed replicated;
--
-- Test append different numsegments tables work well
-- See Github issue: https://github.com/greenplum-db/gpdb/issues/12146
diff --git a/src/test/regress/sql/bfv_planner.sql
b/src/test/regress/sql/bfv_planner.sql
index 114813641d1..c68c73ab5f6 100644
--- a/src/test/regress/sql/bfv_planner.sql
+++ b/src/test/regress/sql/bfv_planner.sql
@@ -345,6 +345,9 @@ select count(*) from gp_dist_random('t_rep4');
select count(distinct nextval) from gp_dist_random('t_rep4');
drop table rep_tbl, t_rep4;
+create table t_issue_1218_random(id int) distributed randomly;
+create table t_issue_1218_replicated as select random() from
t_issue_1218_random distributed replicated;
+
--
-- Test append different numsegments tables work well
-- See Github issue: https://github.com/greenplum-db/gpdb/issues/12146
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]