Skip to content

Commit d3fc88a

Browse files
committed
Improve reloptions validation for partitioned tables using non-default AMs
Previously, when creating a partitioned table without an explicit `USING` clause, the reloptions (such as minmax_columns) were validated with the assumption that the default_table_access_method is either 'heap', 'ao_row', or 'ao_column'. This could incorrectly reject valid reloptions intended for other table access methods like 'pax'. This patch adjusts the validation logic in DefineRelation() so that reloptions are only validated for partitioned tables if the default AM is one of the known AMs that support reloptions validation. For non-default AMs, reloptions are passed unvalidated to allow extensions to handle them properly. This change enables successful creation of partitioned tables using `USING pax WITH (minmax_columns=...)` without validation errors, even when `default_table_access_method` is set to 'pax'.
1 parent 8793ec0 commit d3fc88a

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

contrib/pax_storage/expected/ddl.out

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,26 @@ select 1 from (select count(*) from gp_toolkit.gp_size_of_schema_disk) empty_out
8989
(1 row)
9090

9191
drop table pt_pax;
92+
-- expect create ok
93+
create table pax_test.partition_cow(c1 int, c2 bigint, c3 varchar, c4 text, c5 date, c6 float4, c7 float8, c8 numeric, c9 interval)
94+
partition by range(c1) (start(1) end(15000) every(5000))
95+
with (minmax_columns='c1,c2,c3,c4,c5,c6,c7,c8,c9');
96+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' as the Apache Cloudberry data distribution key for this table.
97+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
98+
-- expect create ok
99+
create table pax_test.partition_cow_1(c1 int, c2 bigint, c3 varchar, c4 text, c5 date, c6 float4, c7 float8, c8 numeric, c9 interval)
100+
partition by range(c1) (start(1) end(15000) every(5000))
101+
using pax with (minmax_columns='c1,c2,c3,c4,c5,c6,c7,c8,c9');
102+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' as the Apache Cloudberry data distribution key for this table.
103+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
104+
set default_table_access_method = heap;
105+
-- expect create fail
106+
create table pax_test.partition_cow_2(c1 int, c2 bigint, c3 varchar, c4 text, c5 date, c6 float4, c7 float8, c8 numeric, c9 interval)
107+
partition by range(c1) (start(1) end(15000) every(5000))
108+
with (minmax_columns='c1,c2,c3,c4,c5,c6,c7,c8,c9');
109+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' as the Apache Cloudberry data distribution key for this table.
110+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
111+
ERROR: unrecognized parameter "minmax_columns"
112+
set default_table_access_method = pax;
113+
drop table pax_test.partition_cow;
114+
drop table pax_test.partition_cow_1;

contrib/pax_storage/sql/ddl.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,21 @@ PARTITION BY RANGE (date)
5858
SELECT pg_catalog.pg_relation_size('pt_pax'::regclass);
5959
select 1 from (select count(*) from gp_toolkit.gp_size_of_schema_disk) empty_out;
6060
drop table pt_pax;
61+
62+
-- expect create ok
63+
create table pax_test.partition_cow(c1 int, c2 bigint, c3 varchar, c4 text, c5 date, c6 float4, c7 float8, c8 numeric, c9 interval)
64+
partition by range(c1) (start(1) end(15000) every(5000))
65+
with (minmax_columns='c1,c2,c3,c4,c5,c6,c7,c8,c9');
66+
-- expect create ok
67+
create table pax_test.partition_cow_1(c1 int, c2 bigint, c3 varchar, c4 text, c5 date, c6 float4, c7 float8, c8 numeric, c9 interval)
68+
partition by range(c1) (start(1) end(15000) every(5000))
69+
using pax with (minmax_columns='c1,c2,c3,c4,c5,c6,c7,c8,c9');
70+
71+
set default_table_access_method = heap;
72+
-- expect create fail
73+
create table pax_test.partition_cow_2(c1 int, c2 bigint, c3 varchar, c4 text, c5 date, c6 float4, c7 float8, c8 numeric, c9 interval)
74+
partition by range(c1) (start(1) end(15000) every(5000))
75+
with (minmax_columns='c1,c2,c3,c4,c5,c6,c7,c8,c9');
76+
set default_table_access_method = pax;
77+
drop table pax_test.partition_cow;
78+
drop table pax_test.partition_cow_1;

contrib/pax_storage/src/test/regress/input/partition_ddl.source

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@ create table part_heap1(a int, b int) using heap with (fillfactor=70) partition
999999
select c.relname, am.amname, c.reloptions from pg_partition_tree('part_heap1') as t join pg_class c on (t.relid::oid = c.oid) left join pg_am am on (c.relam = am.oid);
10001000

10011001
-- Test 3: Parent's reloptions are explicitly specified, and parent's AM is implicitly specified as heap
1002+
set default_table_access_method = heap;
10021003
create table part_heap2(a int, b int) with (fillfactor=70) partition by range(b) (partition p1 start(0) end(10) with(appendonly=true));
10031004
select c.relname, am.amname, c.reloptions from pg_partition_tree('part_heap2') as t join pg_class c on (t.relid::oid = c.oid) left join pg_am am on (c.relam = am.oid);
10041005

contrib/pax_storage/src/test/regress/output/partition_ddl.source

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,6 +2902,7 @@ select c.relname, am.amname, c.reloptions from pg_partition_tree('part_heap1') a
29022902
(2 rows)
29032903

29042904
-- Test 3: Parent's reloptions are explicitly specified, and parent's AM is implicitly specified as heap
2905+
set default_table_access_method = heap;
29052906
create table part_heap2(a int, b int) with (fillfactor=70) partition by range(b) (partition p1 start(0) end(10) with(appendonly=true));
29062907
ERROR: unrecognized parameter "fillfactor"
29072908
select c.relname, am.amname, c.reloptions from pg_partition_tree('part_heap2') as t join pg_class c on (t.relid::oid = c.oid) left join pg_am am on (c.relam = am.oid);

src/backend/commands/tablecmds.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,12 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
970970
if (OidIsValid(accessMethodId))
971971
(void) table_reloptions_am(accessMethodId, reloptions, 'r', true);
972972
else
973-
(void) partitioned_table_reloptions(reloptions, true);
973+
{
974+
bool validate = !strcasecmp(default_table_access_method, DEFAULT_TABLE_ACCESS_METHOD) ||
975+
!strcasecmp(default_table_access_method, "AO_ROW") ||
976+
!strcasecmp(default_table_access_method, "AO_COLUMN");
977+
(void) partitioned_table_reloptions(reloptions, validate);
978+
}
974979
break;
975980
case RELKIND_RELATION:
976981
case RELKIND_MATVIEW:

0 commit comments

Comments
 (0)