Merge pull request #5837 from citusdata/underscore_type_name

Fixes the type names that start with underscore bug
pull/5836/head
Halil Ozan Akgül 2022-03-22 14:35:55 +03:00 committed by GitHub
commit 001551d732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 2 deletions

View File

@ -94,6 +94,9 @@ static List * FilterNameListForDistributedTypes(List *objects, bool missing_ok);
static List * TypeNameListToObjectAddresses(List *objects);
static TypeName * MakeTypeNameFromRangeVar(const RangeVar *relation);
static Oid GetTypeOwner(Oid typeOid);
static Oid LookupNonAssociatedArrayTypeNameOid(ParseState *pstate,
const TypeName *typeName,
bool missing_ok);
/* recreate functions */
static CompositeTypeStmt * RecreateCompositeTypeStmt(Oid typeOid);
@ -742,7 +745,7 @@ CompositeTypeStmtObjectAddress(Node *node, bool missing_ok)
{
CompositeTypeStmt *stmt = castNode(CompositeTypeStmt, node);
TypeName *typeName = MakeTypeNameFromRangeVar(stmt->typevar);
Oid typeOid = LookupTypeNameOid(NULL, typeName, missing_ok);
Oid typeOid = LookupNonAssociatedArrayTypeNameOid(NULL, typeName, missing_ok);
ObjectAddress address = { 0 };
ObjectAddressSet(address, TypeRelationId, typeOid);
@ -763,7 +766,7 @@ CreateEnumStmtObjectAddress(Node *node, bool missing_ok)
{
CreateEnumStmt *stmt = castNode(CreateEnumStmt, node);
TypeName *typeName = makeTypeNameFromNameList(stmt->typeName);
Oid typeOid = LookupTypeNameOid(NULL, typeName, missing_ok);
Oid typeOid = LookupNonAssociatedArrayTypeNameOid(NULL, typeName, missing_ok);
ObjectAddress address = { 0 };
ObjectAddressSet(address, TypeRelationId, typeOid);
@ -1168,3 +1171,32 @@ ShouldPropagateTypeCreate()
return true;
}
/*
* LookupNonAssociatedArrayTypeNameOid returns the oid of the type with the given type name
* that is not an array type that is associated to another user defined type.
*/
static Oid
LookupNonAssociatedArrayTypeNameOid(ParseState *pstate, const TypeName *typeName,
bool missing_ok)
{
Type tup = LookupTypeName(NULL, typeName, NULL, missing_ok);
Oid typeOid = InvalidOid;
if (tup != NULL)
{
if (((Form_pg_type) GETSTRUCT(tup))->typelem == 0)
{
typeOid = ((Form_pg_type) GETSTRUCT(tup))->oid;
}
ReleaseSysCache(tup);
}
if (!missing_ok && typeOid == InvalidOid)
{
elog(ERROR, "type \"%s\" that is not an array type associated with "
"another type does not exist", TypeNameToString(typeName));
}
return typeOid;
}

View File

@ -183,5 +183,18 @@ INSERT INTO data_types_table SELECT * FROM data_types_table ON CONFLICT (dist_ke
INSERT INTO data_types_table SELECT * FROM data_types_table LIMIT 100000 ON CONFLICT (dist_key) DO UPDATE SET useless_column = 10;
INSERT INTO data_types_table (dist_key, col1, col2, col3, col4, col5, col6, col70, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, col18, col19, col20, col21, col22, col23, col24, col25, col26, col27, col28, col29, col32, col33, col34, col35, col36, col37, col38)
SELECT dist_key+1, col1, col2, col3, col4, col5, col6, col70, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, col18, col19, col20, col21, col22, col23, col24, col25, col26, col27, col28, col29, col32, col33, col34, col35, col36, col37, col38 FROM data_types_table ON CONFLICT (dist_key) DO UPDATE SET useless_column = 10;
-- test type names that start with underscore
CREATE TYPE underscore_type_1 AS (a INT);
CREATE TYPE _underscore_type_1 AS (a INT);
CREATE TYPE underscore_type_2 AS ENUM ('a');
CREATE TYPE _underscore_type_2 AS ENUM ('a');
SELECT result FROM run_command_on_all_nodes('SELECT count(*) FROM pg_type WHERE typname LIKE ''%underscore\_type%''');
result
---------------------------------------------------------------------
8
8
8
(3 rows)
SET client_min_messages TO ERROR;
DROP SCHEMA data_types CASCADE;

View File

@ -131,5 +131,15 @@ INSERT INTO data_types_table SELECT * FROM data_types_table LIMIT 100000 ON CONF
INSERT INTO data_types_table (dist_key, col1, col2, col3, col4, col5, col6, col70, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, col18, col19, col20, col21, col22, col23, col24, col25, col26, col27, col28, col29, col32, col33, col34, col35, col36, col37, col38)
SELECT dist_key+1, col1, col2, col3, col4, col5, col6, col70, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, col18, col19, col20, col21, col22, col23, col24, col25, col26, col27, col28, col29, col32, col33, col34, col35, col36, col37, col38 FROM data_types_table ON CONFLICT (dist_key) DO UPDATE SET useless_column = 10;
-- test type names that start with underscore
CREATE TYPE underscore_type_1 AS (a INT);
CREATE TYPE _underscore_type_1 AS (a INT);
CREATE TYPE underscore_type_2 AS ENUM ('a');
CREATE TYPE _underscore_type_2 AS ENUM ('a');
SELECT result FROM run_command_on_all_nodes('SELECT count(*) FROM pg_type WHERE typname LIKE ''%underscore\_type%''');
SET client_min_messages TO ERROR;
DROP SCHEMA data_types CASCADE;