This is an automated email from the ASF dual-hosted git repository. maxyang pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 7c9a7824ae9c9d8d8b90205d4c84afee8055777b Author: Zhenghua Lyu <[email protected]> AuthorDate: Mon Apr 15 16:02:58 2024 +0800 Add warning and guard code for zero-column table. This commit does two things: 1. print a warning log when user try to create a table with no columns 2. add guard code that distributed zero-column table cannot have distributed keys. fix misc_jiras --- src/backend/commands/tablecmds.c | 14 +++++++++ src/test/regress/expected/misc_jiras.out | 51 ++++++++++++++++++++++++++++++++ src/test/regress/sql/misc_jiras.sql | 25 ++++++++++++++++ 3 files changed, 90 insertions(+) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index f3102687ca..bb0f4a435d 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -1035,6 +1035,20 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, else policy = getPolicyForDistributedBy(stmt->distributedBy, descriptor); + /* Greenplum specific code */ + if (list_length(schema) == 0) + { + elogif(Gp_role == GP_ROLE_DISPATCH, LOG, + "creating a table with no columns."); + + /* + * Guard code: Github Issue 17271. Zero-column table + * if distributed, must have randomly policy. + */ + if (GpPolicyIsHashPartitioned(policy)) + policy = createRandomPartitionedPolicy(policy->numsegments); + } + if (partitioned && GpPolicyIsReplicated(policy)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), diff --git a/src/test/regress/expected/misc_jiras.out b/src/test/regress/expected/misc_jiras.out index 2c6d24f5a8..7f3e19ea93 100644 --- a/src/test/regress/expected/misc_jiras.out +++ b/src/test/regress/expected/misc_jiras.out @@ -62,3 +62,54 @@ select '溋' || (B'1'); ERROR: "溋" is not a valid binary digit LINE 1: select '溋' || (B'1'); ^ +-- Github Issue 17271 +-- test create zero-column table will throw warning only on QD +-- test policy on each segment (including coordinator) +create table t_17271(); +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause, and no column type is suitable for a distribution key. Creating a NULL policy entry. +-- coordinator policy +select localoid::regclass::text, policytype,numsegments,distkey,distclass +from gp_distribution_policy where localoid = 't_17271'::regclass::oid; + localoid | policytype | numsegments | distkey | distclass +----------+------------+-------------+---------+----------- + t_17271 | p | 3 | | +(1 row) + +-- segment policy +select localoid::regclass::text, policytype,numsegments,distkey,distclass +from gp_dist_random('gp_distribution_policy') where localoid = 't_17271'::regclass::oid; + localoid | policytype | numsegments | distkey | distclass +----------+------------+-------------+---------+----------- + t_17271 | p | 3 | | + t_17271 | p | 3 | | + t_17271 | p | 3 | | +(3 rows) + +create table t1_17271(a int , b int); +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Cloudberry Database data distribution key for this table. +HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. +create table t2_17271 as select from t1_17271 group by a; +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause. Creating a NULL policy entry. +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named '???' as the Cloudberry Database data distribution key for this table. +HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. +-- coordinator policy +select localoid::regclass::text, policytype,numsegments,distkey,distclass +from gp_distribution_policy where localoid = 't2_17271'::regclass::oid; + localoid | policytype | numsegments | distkey | distclass +----------+------------+-------------+---------+----------- + t2_17271 | p | 3 | | +(1 row) + +-- segment policy +select localoid::regclass::text, policytype,numsegments,distkey,distclass +from gp_dist_random('gp_distribution_policy') where localoid = 't2_17271'::regclass::oid; + localoid | policytype | numsegments | distkey | distclass +----------+------------+-------------+---------+----------- + t2_17271 | p | 3 | | + t2_17271 | p | 3 | | + t2_17271 | p | 3 | | +(3 rows) + +drop table t_17271; +drop table t1_17271; +drop table t2_17271; diff --git a/src/test/regress/sql/misc_jiras.sql b/src/test/regress/sql/misc_jiras.sql index fbd35f8b1a..651b26344d 100644 --- a/src/test/regress/sql/misc_jiras.sql +++ b/src/test/regress/sql/misc_jiras.sql @@ -45,3 +45,28 @@ reset statement_mem; -- non-ASCII multibyte character should show up correctly in error messages. select '溋' || (B'1'); + +-- Github Issue 17271 +-- test create zero-column table will throw warning only on QD +-- test policy on each segment (including coordinator) +create table t_17271(); +-- coordinator policy +select localoid::regclass::text, policytype,numsegments,distkey,distclass +from gp_distribution_policy where localoid = 't_17271'::regclass::oid; +-- segment policy +select localoid::regclass::text, policytype,numsegments,distkey,distclass +from gp_dist_random('gp_distribution_policy') where localoid = 't_17271'::regclass::oid; + +create table t1_17271(a int , b int); +create table t2_17271 as select from t1_17271 group by a; + +-- coordinator policy +select localoid::regclass::text, policytype,numsegments,distkey,distclass +from gp_distribution_policy where localoid = 't2_17271'::regclass::oid; +-- segment policy +select localoid::regclass::text, policytype,numsegments,distkey,distclass +from gp_dist_random('gp_distribution_policy') where localoid = 't2_17271'::regclass::oid; + +drop table t_17271; +drop table t1_17271; +drop table t2_17271; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
