提交 a8f5a045 编写于 作者: J Jimmy Yih

Do not automatically create an array type for child partitions

As part of the Postgres 8.3 merge, all heap tables now automatically
create an array type. The array type will usually be created with
typname '_<heap_name>' since the automatically created composite type
already takes the typname '<heap_name>' first. If typname
'_<heap_name>' is taken, the logic will continue to prepend
underscores until no collision (truncating the end if typname gets
past NAMEDATALEN of 64). This might be an oversight in upstream
Postgres since certain scenarios involving creating a large number of
heap tables with similar names could result in a lot of typname
collisions until no heap tables with similar names can be
created. This is very noticable in Greenplum heap partition tables
because Greenplum has logic to automatically name child partitions
with similar names instead of having the user name each child
partition.

To prevent typname collision failures when creating a heap partition
table with a large number of child partitions, we will now stop
automatically creating the array type for child partitions.

References:
https://www.postgresql.org/message-id/flat/20070302234016.GF3665%40fetter.org
https://github.com/postgres/postgres/commit/bc8036fc666a8f846b1d4b2f935af7edd90eb5aa
上级 a8c54b94
......@@ -179,7 +179,8 @@ _bitmap_create_lov_heapandindex(Relation rel,
false, 0,
ONCOMMIT_NOOP, NULL /* GP Policy */,
(Datum)0, false, true,
/* valid_opts */ true);
/* valid_opts */ true,
/* is_part_child */ false);
*lovHeapOid = heapid;
/*
......
......@@ -267,7 +267,8 @@ Boot_CreateStmt:
(Datum) 0,
false,
true,
/* valid_opts */ false);
/* valid_opts */ false,
/* is_part_child */ false);
elog(DEBUG4, "relation created with oid %u", id);
}
do_end();
......
......@@ -148,7 +148,8 @@ CreateAOAuxiliaryTable(
(Datum) 0,
/* use_user_acl */ false,
true,
/* valid_opts */ false);
/* valid_opts */ false,
/* is_part_child */ false);
/* Make this table visible, else index creation will fail */
CommandCounterIncrement();
......
......@@ -1300,6 +1300,7 @@ AddNewRelationType(const char *typeName,
* use_user_acl: TRUE if should look for user-defined default permissions;
* if FALSE, relacl is always set NULL
* allow_system_table_mods: TRUE to allow creation in system namespaces
* is_part_child: TRUE if relation is a child partition
*
* Returns the OID of the new relation
* --------------------------------
......@@ -1327,7 +1328,8 @@ heap_create_with_catalog(const char *relname,
Datum reloptions,
bool use_user_acl,
bool allow_system_table_mods,
bool valid_opts)
bool valid_opts,
bool is_part_child)
{
Relation pg_class_desc;
Relation new_rel_desc;
......@@ -1502,12 +1504,19 @@ heap_create_with_catalog(const char *relname,
*
* Also not for the auxiliary heaps created for bitmap indexes or append-
* only tables.
*
* In Greenplum, we do not create an array type for child
* partitions. Child partitions are automatically named very similarly
* which can cause typname collisions very easily. If there are a lot of
* typname collisions, it's possible that makeArrayTypeName could fail to
* create a typname and error us out.
*/
if (IsUnderPostmaster && ((relkind == RELKIND_RELATION && !appendOnlyRel) ||
relkind == RELKIND_VIEW ||
relkind == RELKIND_FOREIGN_TABLE ||
relkind == RELKIND_COMPOSITE_TYPE) &&
relnamespace != PG_BITMAPINDEX_NAMESPACE)
relnamespace != PG_BITMAPINDEX_NAMESPACE &&
!is_part_child)
{
/* OK, so pre-assign a type OID for the array type */
Relation pg_type = heap_open(TypeRelationId, AccessShareLock);
......
......@@ -261,7 +261,8 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
reloptions,
false,
true,
/* valid_opts */ false);
/* valid_opts */ false,
/* is_part_child */ false);
Assert(toast_relid != InvalidOid);
/* make the toast relation visible, else heap_open will fail */
......
......@@ -733,7 +733,8 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace,
reloptions,
false,
/* allowSystemTableModsDDL */ true,
/* valid_opts */ true);
/* valid_opts */ true,
/* is_part_child */ false);
Assert(OIDNewHeap != InvalidOid);
ReleaseSysCache(tuple);
......
......@@ -812,7 +812,8 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, char relstorage, boo
reloptions,
true,
allowSystemTableModsDDL,
valid_opts);
valid_opts,
stmt->is_part_child);
/*
* Give a warning if you use OIDS=TRUE on user tables. We do this after calling
......
......@@ -4046,7 +4046,8 @@ OpenIntoRel(QueryDesc *queryDesc)
reloptions,
true,
allowSystemTableModsDDL,
/* valid_opts */ !validate_reloptions);
/* valid_opts */ !validate_reloptions,
/* is_part_child */ false);
Assert(intoRelationId != InvalidOid);
FreeTupleDesc(tupdesc);
......
......@@ -83,7 +83,8 @@ extern Oid heap_create_with_catalog(const char *relname,
Datum reloptions,
bool use_user_acl,
bool allow_system_table_mods,
bool valid_opts);
bool valid_opts,
bool is_part_child);
extern void heap_drop_with_catalog(Oid relid);
......
......@@ -7715,6 +7715,21 @@ NOTICE: exchanged partition "other_log_ids" of relation "test_split_part" with
NOTICE: dropped partition "other_log_ids" for relation "test_split_part"
NOTICE: CREATE TABLE will create partition "test_split_part_1_prt_New" for table "test_split_part"
NOTICE: CREATE TABLE will create partition "test_split_part_1_prt_other_log_ids" for table "test_split_part"
-- Only the root partition should have automatically created an array type
select typname, typtype, typcategory from pg_type where typname like '%test_split_part%' and typcategory = 'A';
typname | typtype | typcategory
------------------+---------+-------------
_test_split_part | b | A
(1 row)
select array_agg(test_split_part) from test_split_part where log_id = 500;
array_agg
----------------
{"(500,{10})"}
(1 row)
select array_agg(test_split_part_1_prt_other_log_ids) from test_split_part_1_prt_other_log_ids where log_id = 500;
ERROR: could not find array type for data type test_split_part_1_prt_other_log_ids
-- Test that pg_get_partition_def() correctly dumps the renamed names for
-- partitions. Originally reported in MPP-7232
create table mpp7232a (a int, b int) distributed by (a) partition by range (b) (start (1) end (3) every (1));
......
......@@ -7709,6 +7709,21 @@ NOTICE: exchanged partition "other_log_ids" of relation "test_split_part" with
NOTICE: dropped partition "other_log_ids" for relation "test_split_part"
NOTICE: CREATE TABLE will create partition "test_split_part_1_prt_New" for table "test_split_part"
NOTICE: CREATE TABLE will create partition "test_split_part_1_prt_other_log_ids" for table "test_split_part"
-- Only the root partition should have automatically created an array type
select typname, typtype, typcategory from pg_type where typname like '%test_split_part%' and typcategory = 'A';
typname | typtype | typcategory
------------------+---------+-------------
_test_split_part | b | A
(1 row)
select array_agg(test_split_part) from test_split_part where log_id = 500;
array_agg
----------------
{"(500,{10})"}
(1 row)
select array_agg(test_split_part_1_prt_other_log_ids) from test_split_part_1_prt_other_log_ids where log_id = 500;
ERROR: could not find array type for data type test_split_part_1_prt_other_log_ids
-- Test that pg_get_partition_def() correctly dumps the renamed names for
-- partitions. Originally reported in MPP-7232
create table mpp7232a (a int, b int) distributed by (a) partition by range (b) (start (1) end (3) every (1));
......
......@@ -3713,6 +3713,11 @@ insert into test_split_part (log_id , f_array) select id, '{10}' from generate_s
ALTER TABLE test_split_part SPLIT DEFAULT PARTITION START (201) INCLUSIVE END (301) EXCLUSIVE INTO (PARTITION "New", DEFAULT PARTITION);
-- Only the root partition should have automatically created an array type
select typname, typtype, typcategory from pg_type where typname like '%test_split_part%' and typcategory = 'A';
select array_agg(test_split_part) from test_split_part where log_id = 500;
select array_agg(test_split_part_1_prt_other_log_ids) from test_split_part_1_prt_other_log_ids where log_id = 500;
-- Test that pg_get_partition_def() correctly dumps the renamed names for
-- partitions. Originally reported in MPP-7232
create table mpp7232a (a int, b int) distributed by (a) partition by range (b) (start (1) end (3) every (1));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册