Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/backend/catalog/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,10 @@ heap_create_with_catalog(const char *relname,
* NAMEDATALEN and gets truncated. Then the name may same with other child
* table's.
*
* Auxiliary relations in pg_ext_aux don't need array type. Relations in
* pg_ext_aux are assumed simple relation, their array types are unexpected
* to be used in the extension code.
*
* The below code is different from upstream since we preassign type
* OID first on QD and use the name as key to retrieve the pre-assigned
* OID from QE.
Expand All @@ -1666,7 +1670,10 @@ heap_create_with_catalog(const char *relname,
relkind == RELKIND_AOBLOCKDIR ||
relkind == RELKIND_AOVISIMAP ||
relnamespace == PG_BITMAPINDEX_NAMESPACE ||
relnamespace == PG_EXTAUX_NAMESPACE))
(relnamespace == PG_EXTAUX_NAMESPACE &&
(relkind == RELKIND_RELATION ||
relkind == RELKIND_VIEW ||
relkind == RELKIND_MATVIEW))))
{
/* OK, so pre-assign a type OID for the array type */
Oid new_array_oid;
Expand Down
79 changes: 79 additions & 0 deletions src/test/regress/expected/pg_ext_aux.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
-- Test use of namespace pg_ext_aux
-- Test 1: Create database object in pg_ext_aux should fail normally
create table pg_ext_aux.extaux_t(a int, b int);
ERROR: permission denied to create "pg_ext_aux.extaux_t"
DETAIL: System catalog modifications are currently disallowed.
create view pg_ext_aux.extaux_v as select oid, relname from pg_class;
ERROR: permission denied to create "pg_ext_aux.extaux_v"
DETAIL: System catalog modifications are currently disallowed.
create materialized view pg_ext_aux.extaux_mv as select oid, relname from pg_class;
ERROR: permission denied to create "pg_ext_aux.extaux_mv"
DETAIL: System catalog modifications are currently disallowed.
-- shell type is created successfully
create type pg_ext_aux.extaux_shell_type;
-- concreate type will fail
create type pg_ext_aux.extaux_concreat_type AS (sum int, count int);
ERROR: permission denied to create "pg_ext_aux.extaux_concreat_type"
DETAIL: System catalog modifications are currently disallowed.
-- create function will success
create function pg_ext_aux.extaux_add1(i integer) returns integer AS $$
begin
return i + 1;
end;
$$ language plpgsql;
-- Test 2: Create database object in pg_ext_aux should success
-- if allow_system_table_mods is on
set allow_system_table_mods = on;
create table pg_ext_aux.extaux_t(a int, b text);
create view pg_ext_aux.extaux_v as select * from pg_ext_aux.extaux_t;
create materialized view pg_ext_aux.extaux_mv as select * from pg_ext_aux.extaux_t;
create type pg_ext_aux.extaux_concreat_type AS (sum int, count int);
set allow_system_table_mods = off;
-- Test 3: Check that the array type is not created
-- these relations have its reltype, but have no array type
select typname, typarray from pg_type where oid = (select reltype from pg_class where relname='extaux_t');
typname | typarray
---------+----------
(0 rows)

select typname, typarray from pg_type where oid = (select reltype from pg_class where relname='extaux_v');
typname | typarray
---------+----------
(0 rows)

select typname, typarray from pg_type where oid = (select reltype from pg_class where relname='extaux_mv');
typname | typarray
---------+----------
(0 rows)

-- Test 4: check function works
select pg_ext_aux.extaux_add1(7);
extaux_add1
-------------
8
(1 row)

-- Test 5: Check that these relations are protected
-- fail: should not allowed to insert by user
insert into pg_ext_aux.extaux_t values(1,'hello');
ERROR: permission denied: "extaux_t" is a system catalog
-- fail: should not allowed to refresh by user
refresh materialized view pg_ext_aux.extaux_mv;
ERROR: cannot swap toast files by links for system catalogs (cluster.c:1424)
-- fail: should not allow to be dropped by user
drop view pg_ext_aux.extaux_v;
ERROR: permission denied: "extaux_v" is a system catalog
drop materialized view pg_ext_aux.extaux_mv;
ERROR: permission denied: "extaux_mv" is a system catalog
drop table pg_ext_aux.extaux_t;
ERROR: permission denied: "extaux_t" is a system catalog
-- Test 6: type and functions may be dropped normally
drop type pg_ext_aux.extaux_shell_type;
drop type pg_ext_aux.extaux_concreat_type;
drop function pg_ext_aux.extaux_add1(i integer);
-- Clean up
set allow_system_table_mods = on;
drop view pg_ext_aux.extaux_v;
drop materialized view pg_ext_aux.extaux_mv;
drop table pg_ext_aux.extaux_t;
reset allow_system_table_mods;
3 changes: 3 additions & 0 deletions src/test/regress/greenplum_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# hitting max_connections limit on segments.
#

# test for builtin namespace pg_ext_aux
test: pg_ext_aux

test: gp_dispatch_keepalives

# copy command
Expand Down
62 changes: 62 additions & 0 deletions src/test/regress/sql/pg_ext_aux.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
-- Test use of namespace pg_ext_aux

-- Test 1: Create database object in pg_ext_aux should fail normally
create table pg_ext_aux.extaux_t(a int, b int);
create view pg_ext_aux.extaux_v as select oid, relname from pg_class;
create materialized view pg_ext_aux.extaux_mv as select oid, relname from pg_class;

-- shell type is created successfully
create type pg_ext_aux.extaux_shell_type;
-- concreate type will fail
create type pg_ext_aux.extaux_concreat_type AS (sum int, count int);

-- create function will success
create function pg_ext_aux.extaux_add1(i integer) returns integer AS $$
begin
return i + 1;
end;
$$ language plpgsql;


-- Test 2: Create database object in pg_ext_aux should success
-- if allow_system_table_mods is on
set allow_system_table_mods = on;
create table pg_ext_aux.extaux_t(a int, b text);
create view pg_ext_aux.extaux_v as select * from pg_ext_aux.extaux_t;
create materialized view pg_ext_aux.extaux_mv as select * from pg_ext_aux.extaux_t;
create type pg_ext_aux.extaux_concreat_type AS (sum int, count int);
set allow_system_table_mods = off;

-- Test 3: Check that the array type is not created
-- these relations have its reltype, but have no array type
select typname, typarray from pg_type where oid = (select reltype from pg_class where relname='extaux_t');
select typname, typarray from pg_type where oid = (select reltype from pg_class where relname='extaux_v');
select typname, typarray from pg_type where oid = (select reltype from pg_class where relname='extaux_mv');

-- Test 4: check function works
select pg_ext_aux.extaux_add1(7);

-- Test 5: Check that these relations are protected
-- fail: should not allowed to insert by user
insert into pg_ext_aux.extaux_t values(1,'hello');
-- fail: should not allowed to refresh by user
refresh materialized view pg_ext_aux.extaux_mv;

-- fail: should not allow to be dropped by user
drop view pg_ext_aux.extaux_v;
drop materialized view pg_ext_aux.extaux_mv;
drop table pg_ext_aux.extaux_t;

-- Test 6: type and functions may be dropped normally
drop type pg_ext_aux.extaux_shell_type;
drop type pg_ext_aux.extaux_concreat_type;
drop function pg_ext_aux.extaux_add1(i integer);


-- Clean up
set allow_system_table_mods = on;
drop view pg_ext_aux.extaux_v;
drop materialized view pg_ext_aux.extaux_mv;
drop table pg_ext_aux.extaux_t;

reset allow_system_table_mods;