Give nicer error message when using alter_table_set_access_method on a view (#6553)

DESCRIPTION: Fixes alter_table_set_access_method error for views.

Fixes #6001
pull/6555/head
Gürkan İndibay 2022-12-12 23:56:22 +03:00 committed by GitHub
parent 1ad1a0a336
commit 3f091e3493
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 4 deletions

View File

@ -477,6 +477,11 @@ AlterTableSetAccessMethod(TableConversionParameters *params)
ereport(ERROR, (errmsg("you cannot alter access method of a partitioned table"))); ereport(ERROR, (errmsg("you cannot alter access method of a partitioned table")));
} }
if (get_rel_relkind(params->relationId) == RELKIND_VIEW)
{
ereport(ERROR, (errmsg("you cannot alter access method of a view")));
}
if (PartitionTable(params->relationId) && if (PartitionTable(params->relationId) &&
IsCitusTableType(params->relationId, DISTRIBUTED_TABLE)) IsCitusTableType(params->relationId, DISTRIBUTED_TABLE))
{ {

View File

@ -299,7 +299,7 @@ CREATE INDEX idx1 ON index_table (a);
-- also create an index with statistics -- also create an index with statistics
CREATE INDEX idx2 ON index_table ((a+1)); CREATE INDEX idx2 ON index_table ((a+1));
ALTER INDEX idx2 ALTER COLUMN 1 SET STATISTICS 300; ALTER INDEX idx2 ALTER COLUMN 1 SET STATISTICS 300;
SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table'; SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table' order by indexname;
indexname indexname
--------------------------------------------------------------------- ---------------------------------------------------------------------
idx1 idx1
@ -322,7 +322,7 @@ NOTICE: renaming the new table to alter_table_set_access_method.index_table
(1 row) (1 row)
SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table'; SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table' order by indexname;
indexname indexname
--------------------------------------------------------------------- ---------------------------------------------------------------------
idx1 idx1
@ -792,6 +792,19 @@ NOTICE: renaming the new table to alter_table_set_access_method.events
(1 row) (1 row)
COMMIT; COMMIT;
--create the view to test alter table set access method on it
CREATE TABLE view_test_table (id int, val int, flag bool, kind int);
SELECT create_distributed_table('view_test_table','id');
create_distributed_table
---------------------------------------------------------------------
(1 row)
INSERT INTO view_test_table VALUES (1, 1, true, 99), (2, 2, false, 99), (2, 3, true, 88);
CREATE VIEW view_test_view AS SELECT * FROM view_test_table;
-- error out when attempting to set access method of a view.
select alter_table_set_access_method('view_test_view','columnar');
ERROR: you cannot alter access method of a view
SET client_min_messages TO WARNING; SET client_min_messages TO WARNING;
DROP SCHEMA alter_table_set_access_method CASCADE; DROP SCHEMA alter_table_set_access_method CASCADE;
SELECT 1 FROM master_remove_node('localhost', :master_port); SELECT 1 FROM master_remove_node('localhost', :master_port);

View File

@ -99,10 +99,10 @@ CREATE INDEX idx1 ON index_table (a);
-- also create an index with statistics -- also create an index with statistics
CREATE INDEX idx2 ON index_table ((a+1)); CREATE INDEX idx2 ON index_table ((a+1));
ALTER INDEX idx2 ALTER COLUMN 1 SET STATISTICS 300; ALTER INDEX idx2 ALTER COLUMN 1 SET STATISTICS 300;
SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table'; SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table' order by indexname;
SELECT a.amname FROM pg_class c, pg_am a where c.relname = 'index_table' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid; SELECT a.amname FROM pg_class c, pg_am a where c.relname = 'index_table' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid;
SELECT alter_table_set_access_method('index_table', 'columnar'); SELECT alter_table_set_access_method('index_table', 'columnar');
SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table'; SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table' order by indexname;
SELECT a.amname FROM pg_class c, pg_am a where c.relname = 'index_table' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid; SELECT a.amname FROM pg_class c, pg_am a where c.relname = 'index_table' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid;
CREATE TABLE "heap_\'tbl" ( CREATE TABLE "heap_\'tbl" (
@ -271,6 +271,15 @@ BEGIN;
select alter_table_set_access_method('events', 'columnar'); select alter_table_set_access_method('events', 'columnar');
COMMIT; COMMIT;
--create the view to test alter table set access method on it
CREATE TABLE view_test_table (id int, val int, flag bool, kind int);
SELECT create_distributed_table('view_test_table','id');
INSERT INTO view_test_table VALUES (1, 1, true, 99), (2, 2, false, 99), (2, 3, true, 88);
CREATE VIEW view_test_view AS SELECT * FROM view_test_table;
-- error out when attempting to set access method of a view.
select alter_table_set_access_method('view_test_view','columnar');
SET client_min_messages TO WARNING; SET client_min_messages TO WARNING;
DROP SCHEMA alter_table_set_access_method CASCADE; DROP SCHEMA alter_table_set_access_method CASCADE;
SELECT 1 FROM master_remove_node('localhost', :master_port); SELECT 1 FROM master_remove_node('localhost', :master_port);