You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by yj...@apache.org on 2025/01/27 12:32:30 UTC
(cloudberry) 04/39: Disallow SUBPARTITION BY clause on empty partition
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit f1d890e5e7131b05e861a01357291f98f84ed16b
Author: Divyesh Vanjare <va...@vmware.com>
AuthorDate: Mon Nov 27 13:33:32 2023 -0500
Disallow SUBPARTITION BY clause on empty partition
We should not allow subpartition by clause when creating empty partition
hierarchy with modern syntax (CREATE PARTITION BY ... without creating
any partitions and then later on adding partitions by CREATE TABLE
PARTITION OF...).
Example:
CREATE TABLE foo(i int, j int) PARTITION BY range(i) SUBPARTITION BY
range(j);
Here the info about subpart by j is lost.
This is because the info in the subpartition by clause is currently
lost. Partitions attached henceforth don't obey the partition policy of
the top level. So, ban it outright - it is a bad mixture of upstream and
legacy syntax.
---
src/backend/parser/gram.y | 10 ++++++++++
src/test/regress/expected/partition.out | 15 +++++++++++++++
src/test/regress/expected/partition_optimizer.out | 15 +++++++++++++++
src/test/regress/sql/partition.sql | 15 +++++++++++++++
4 files changed, 55 insertions(+)
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index fdbe8f7f9e..a6d0a83b82 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -5964,6 +5964,10 @@ OptFirstPartitionSpec: PartitionSpec opt_list_subparts OptTabPartitionSpec
if ($1->gpPartDef)
check_expressions_in_partition_key($1, yyscanner);
$$ = $1;
+ /* Do not allow SUBPARTITION BY clause for empty partition hierarchy */
+ if (!$1->gpPartDef && $1->subPartSpec)
+ ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("SUBPARTITION BY clause is not allowed when no partitions specified at depth 1")));
pg_yyget_extra(yyscanner)->tail_partition_magic = true;
}
@@ -5991,6 +5995,12 @@ OptSecondPartitionSpec:
*/
if (n->gpPartDef)
check_expressions_in_partition_key(n, yyscanner);
+
+ /* Do not allow SUBPARTITION BY clause for empty partition hierarchy */
+ if (!n->gpPartDef && n->subPartSpec)
+ ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("SUBPARTITION BY clause is not allowed when no partitions specified at depth 1")));
+
$$ = n;
pg_yyget_extra(yyscanner)->tail_partition_magic = false;
diff --git a/src/test/regress/expected/partition.out b/src/test/regress/expected/partition.out
index ab05ebb29b..124c31ea50 100755
--- a/src/test/regress/expected/partition.out
+++ b/src/test/regress/expected/partition.out
@@ -6638,3 +6638,18 @@ PARTITION BY RANGE (year)
( START (2010) END (2012) EVERY (1),
DEFAULT PARTITION outlying_years );
drop table p3_sales;
+-- We should not allow subpartition by clause when creating empty partition hierarchy
+-- Should error out
+CREATE TABLE empty_partition_disallow_subpartition(i int, j int)
+PARTITION BY range(i) SUBPARTITION BY range(j);
+ERROR: SUBPARTITION BY clause is not allowed when no partitions specified at depth 1
+-- Check with other Partition syntax
+CREATE TABLE empty_partition_disallow_subpartition_2(i int, j int)
+ DISTRIBUTED BY (i) PARTITION BY range(i) SUBPARTITION BY range(j);
+ERROR: SUBPARTITION BY clause is not allowed when no partitions specified at depth 1
+-- Should work fine for empty hierarchy when subpartition is not specified
+CREATE TABLE empty_partition(i int, j int) PARTITION BY range(i);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum 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.
+-- Check with other Partition syntax
+CREATE TABLE empty_partition2(i int, j int) DISTRIBUTED BY (i) PARTITION BY range(i);
diff --git a/src/test/regress/expected/partition_optimizer.out b/src/test/regress/expected/partition_optimizer.out
index 71a1370896..274689c513 100755
--- a/src/test/regress/expected/partition_optimizer.out
+++ b/src/test/regress/expected/partition_optimizer.out
@@ -6641,3 +6641,18 @@ PARTITION BY RANGE (year)
( START (2010) END (2012) EVERY (1),
DEFAULT PARTITION outlying_years );
drop table p3_sales;
+-- We should not allow subpartition by clause when creating empty partition hierarchy
+-- Should error out
+CREATE TABLE empty_partition_disallow_subpartition(i int, j int)
+PARTITION BY range(i) SUBPARTITION BY range(j);
+ERROR: SUBPARTITION BY clause is not allowed when no partitions specified at depth 1
+-- Check with other Partition syntax
+CREATE TABLE empty_partition_disallow_subpartition_2(i int, j int)
+ DISTRIBUTED BY (i) PARTITION BY range(i) SUBPARTITION BY range(j);
+ERROR: SUBPARTITION BY clause is not allowed when no partitions specified at depth 1
+-- Should work fine for empty hierarchy when subpartition is not specified
+CREATE TABLE empty_partition(i int, j int) PARTITION BY range(i);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum 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.
+-- Check with other Partition syntax
+CREATE TABLE empty_partition2(i int, j int) DISTRIBUTED BY (i) PARTITION BY range(i);
diff --git a/src/test/regress/sql/partition.sql b/src/test/regress/sql/partition.sql
index bbbc2aacf8..43c55a4b72 100644
--- a/src/test/regress/sql/partition.sql
+++ b/src/test/regress/sql/partition.sql
@@ -4215,3 +4215,18 @@ PARTITION BY RANGE (year)
DEFAULT PARTITION outlying_years );
drop table p3_sales;
+
+-- We should not allow subpartition by clause when creating empty partition hierarchy
+-- Should error out
+CREATE TABLE empty_partition_disallow_subpartition(i int, j int)
+PARTITION BY range(i) SUBPARTITION BY range(j);
+
+-- Check with other Partition syntax
+CREATE TABLE empty_partition_disallow_subpartition_2(i int, j int)
+ DISTRIBUTED BY (i) PARTITION BY range(i) SUBPARTITION BY range(j);
+
+-- Should work fine for empty hierarchy when subpartition is not specified
+CREATE TABLE empty_partition(i int, j int) PARTITION BY range(i);
+
+-- Check with other Partition syntax
+CREATE TABLE empty_partition2(i int, j int) DISTRIBUTED BY (i) PARTITION BY range(i);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org