-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BACKPORT 2.6][#6470] YSQL: Enable ALTER SCHEMA RENAME
Summary: DocDB layer knows nothing about postgres schemas. This information in stored only in postgres sys catalog. It is enough to allow the `ALTER SCHEMA RENAME` command on parser level to support schema reaming. Original commit: D12387 / 39b2b6b Test Plan: Jenkins: rebase: 2.6 postgres's regress test `namespace.sql` was integrated as `yb_pg_namespace.sql` ``` ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressPgMiscIndependent' ``` Reviewers: alex, mihnea Reviewed By: mihnea Subscribers: yql Differential Revision: https://phabricator.dev.yugabyte.com/D12471
- Loading branch information
1 parent
5db005b
commit d6ad691
Showing
4 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/postgres/src/test/regress/expected/yb_pg_namespace.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
-- | ||
-- Regression tests for schemas (namespaces) | ||
-- | ||
CREATE SCHEMA test_ns_schema_1 | ||
CREATE UNIQUE INDEX abc_a_idx ON abc (a) | ||
CREATE VIEW abc_view AS | ||
SELECT a+1 AS a, b+1 AS b FROM abc | ||
CREATE TABLE abc ( | ||
a serial, | ||
b int UNIQUE | ||
); | ||
ERROR: CREATE SCHEMA with elements not supported yet | ||
LINE 2: CREATE UNIQUE INDEX abc_a_idx ON abc (a) | ||
^ | ||
HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues | ||
-- TODO(dmitry): Remove separate statements for creation each element in schema after | ||
-- `schema creation with elements` command will be supported. | ||
CREATE SCHEMA test_ns_schema_1; | ||
CREATE TABLE test_ns_schema_1.abc (a serial, b int UNIQUE); | ||
CREATE UNIQUE INDEX abc_a_idx ON test_ns_schema_1.abc (a); | ||
CREATE VIEW test_ns_schema_1.abc_view AS SELECT a+1 AS a, b+1 AS b FROM test_ns_schema_1.abc; | ||
-- verify that the objects were created | ||
SELECT COUNT(*) FROM pg_class WHERE relnamespace = | ||
(SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_1'); | ||
count | ||
------- | ||
5 | ||
(1 row) | ||
|
||
INSERT INTO test_ns_schema_1.abc DEFAULT VALUES; | ||
INSERT INTO test_ns_schema_1.abc DEFAULT VALUES; | ||
INSERT INTO test_ns_schema_1.abc DEFAULT VALUES; | ||
SELECT * FROM test_ns_schema_1.abc ORDER BY a; | ||
a | b | ||
---+--- | ||
1 | | ||
2 | | ||
3 | | ||
(3 rows) | ||
|
||
SELECT * FROM test_ns_schema_1.abc_view ORDER BY a; | ||
a | b | ||
---+--- | ||
2 | | ||
3 | | ||
4 | | ||
(3 rows) | ||
|
||
ALTER SCHEMA test_ns_schema_1 RENAME TO test_ns_schema_renamed; | ||
SELECT COUNT(*) FROM pg_class WHERE relnamespace = | ||
(SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_1'); | ||
count | ||
------- | ||
0 | ||
(1 row) | ||
|
||
-- test IF NOT EXISTS cases | ||
CREATE SCHEMA test_ns_schema_renamed; -- fail, already exists | ||
ERROR: schema "test_ns_schema_renamed" already exists | ||
CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed; -- ok with notice | ||
NOTICE: schema "test_ns_schema_renamed" already exists, skipping | ||
CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed -- fail, disallowed | ||
CREATE TABLE abc ( | ||
a serial, | ||
b int UNIQUE | ||
); | ||
ERROR: CREATE SCHEMA IF NOT EXISTS cannot include schema elements | ||
LINE 2: CREATE TABLE abc ( | ||
^ | ||
DROP SCHEMA test_ns_schema_renamed CASCADE; | ||
NOTICE: drop cascades to 2 other objects | ||
DETAIL: drop cascades to table test_ns_schema_renamed.abc | ||
drop cascades to view test_ns_schema_renamed.abc_view | ||
-- verify that the objects were dropped | ||
SELECT COUNT(*) FROM pg_class WHERE relnamespace = | ||
(SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_renamed'); | ||
count | ||
------- | ||
0 | ||
(1 row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
-- | ||
-- Regression tests for schemas (namespaces) | ||
-- | ||
|
||
CREATE SCHEMA test_ns_schema_1 | ||
CREATE UNIQUE INDEX abc_a_idx ON abc (a) | ||
|
||
CREATE VIEW abc_view AS | ||
SELECT a+1 AS a, b+1 AS b FROM abc | ||
|
||
CREATE TABLE abc ( | ||
a serial, | ||
b int UNIQUE | ||
); | ||
|
||
-- TODO(dmitry): Remove separate statements for creation each element in schema after | ||
-- `schema creation with elements` command will be supported. | ||
CREATE SCHEMA test_ns_schema_1; | ||
CREATE TABLE test_ns_schema_1.abc (a serial, b int UNIQUE); | ||
CREATE UNIQUE INDEX abc_a_idx ON test_ns_schema_1.abc (a); | ||
CREATE VIEW test_ns_schema_1.abc_view AS SELECT a+1 AS a, b+1 AS b FROM test_ns_schema_1.abc; | ||
|
||
-- verify that the objects were created | ||
SELECT COUNT(*) FROM pg_class WHERE relnamespace = | ||
(SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_1'); | ||
|
||
INSERT INTO test_ns_schema_1.abc DEFAULT VALUES; | ||
INSERT INTO test_ns_schema_1.abc DEFAULT VALUES; | ||
INSERT INTO test_ns_schema_1.abc DEFAULT VALUES; | ||
|
||
SELECT * FROM test_ns_schema_1.abc ORDER BY a; | ||
SELECT * FROM test_ns_schema_1.abc_view ORDER BY a; | ||
|
||
ALTER SCHEMA test_ns_schema_1 RENAME TO test_ns_schema_renamed; | ||
SELECT COUNT(*) FROM pg_class WHERE relnamespace = | ||
(SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_1'); | ||
|
||
-- test IF NOT EXISTS cases | ||
CREATE SCHEMA test_ns_schema_renamed; -- fail, already exists | ||
CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed; -- ok with notice | ||
CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed -- fail, disallowed | ||
CREATE TABLE abc ( | ||
a serial, | ||
b int UNIQUE | ||
); | ||
|
||
DROP SCHEMA test_ns_schema_renamed CASCADE; | ||
|
||
-- verify that the objects were dropped | ||
SELECT COUNT(*) FROM pg_class WHERE relnamespace = | ||
(SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_renamed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters