Allow DROP CONSTRAINT on compressed hypertables

Removing constraints is always safe so there is no reason to block it on
compressed hypertables. Adding constraints is still blocked for
compressed hypertables as verifying of constraints currently requires
decompressed hypertable.
This commit is contained in:
Sven Klemm 2024-03-07 17:54:22 +01:00 committed by Sven Klemm
parent 67ad085d18
commit 3bb331860d
7 changed files with 22 additions and 8 deletions

1
.unreleased/pr_6754 Normal file
View File

@ -0,0 +1 @@
Implements: #6754 Allow DROP CONSTRAINT on compressed hypertables

View File

@ -250,10 +250,11 @@ check_alter_table_allowed_on_ht_with_compression(Hypertable *ht, AlterTableStmt
/* this is passed down in `process_altertable_change_owner` */ /* this is passed down in `process_altertable_change_owner` */
case AT_SetTableSpace: case AT_SetTableSpace:
/* this is passed down in `process_altertable_set_tablespace_end` */ /* this is passed down in `process_altertable_set_tablespace_end` */
case AT_SetStatistics: /* should this be pushed down in some way? */ case AT_SetStatistics: /* should this be pushed down in some way? */
case AT_AddColumn: /* this is passed down */ case AT_AddColumn: /* this is passed down */
case AT_ColumnDefault: /* this is passed down */ case AT_ColumnDefault: /* this is passed down */
case AT_DropColumn: /* this is passed down */ case AT_DropColumn: /* this is passed down */
case AT_DropConstraint: /* this is passed down */
#if PG14_GE #if PG14_GE
case AT_ReAddStatistics: case AT_ReAddStatistics:
case AT_SetCompression: case AT_SetCompression:

View File

@ -208,8 +208,10 @@ ALTER TABLE foo ADD CONSTRAINT chk CHECK(b > 0);
ERROR: operation not supported on hypertables that have compression enabled ERROR: operation not supported on hypertables that have compression enabled
ALTER TABLE foo ADD CONSTRAINT chk UNIQUE(b); ALTER TABLE foo ADD CONSTRAINT chk UNIQUE(b);
ERROR: operation not supported on hypertables that have compression enabled ERROR: operation not supported on hypertables that have compression enabled
--should succeed
BEGIN;
ALTER TABLE foo DROP CONSTRAINT chk_existing; ALTER TABLE foo DROP CONSTRAINT chk_existing;
ERROR: operation not supported on hypertables that have compression enabled ROLLBACK;
--note that the time column "a" should not be added to the end of the order by list again (should appear first) --note that the time column "a" should not be added to the end of the order by list again (should appear first)
SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass;
relid | segmentby | orderby | orderby_desc | orderby_nullsfirst relid | segmentby | orderby | orderby_desc | orderby_nullsfirst

View File

@ -208,8 +208,10 @@ ALTER TABLE foo ADD CONSTRAINT chk CHECK(b > 0);
ERROR: operation not supported on hypertables that have compression enabled ERROR: operation not supported on hypertables that have compression enabled
ALTER TABLE foo ADD CONSTRAINT chk UNIQUE(b); ALTER TABLE foo ADD CONSTRAINT chk UNIQUE(b);
ERROR: operation not supported on hypertables that have compression enabled ERROR: operation not supported on hypertables that have compression enabled
--should succeed
BEGIN;
ALTER TABLE foo DROP CONSTRAINT chk_existing; ALTER TABLE foo DROP CONSTRAINT chk_existing;
ERROR: operation not supported on hypertables that have compression enabled ROLLBACK;
--note that the time column "a" should not be added to the end of the order by list again (should appear first) --note that the time column "a" should not be added to the end of the order by list again (should appear first)
SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass;
relid | segmentby | orderby | orderby_desc | orderby_nullsfirst relid | segmentby | orderby | orderby_desc | orderby_nullsfirst

View File

@ -208,8 +208,10 @@ ALTER TABLE foo ADD CONSTRAINT chk CHECK(b > 0);
ERROR: operation not supported on hypertables that have compression enabled ERROR: operation not supported on hypertables that have compression enabled
ALTER TABLE foo ADD CONSTRAINT chk UNIQUE(b); ALTER TABLE foo ADD CONSTRAINT chk UNIQUE(b);
ERROR: operation not supported on hypertables that have compression enabled ERROR: operation not supported on hypertables that have compression enabled
--should succeed
BEGIN;
ALTER TABLE foo DROP CONSTRAINT chk_existing; ALTER TABLE foo DROP CONSTRAINT chk_existing;
ERROR: operation not supported on hypertables that have compression enabled ROLLBACK;
--note that the time column "a" should not be added to the end of the order by list again (should appear first) --note that the time column "a" should not be added to the end of the order by list again (should appear first)
SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass;
relid | segmentby | orderby | orderby_desc | orderby_nullsfirst relid | segmentby | orderby | orderby_desc | orderby_nullsfirst

View File

@ -208,8 +208,10 @@ ALTER TABLE foo ADD CONSTRAINT chk CHECK(b > 0);
ERROR: operation not supported on hypertables that have compression enabled ERROR: operation not supported on hypertables that have compression enabled
ALTER TABLE foo ADD CONSTRAINT chk UNIQUE(b); ALTER TABLE foo ADD CONSTRAINT chk UNIQUE(b);
ERROR: operation not supported on hypertables that have compression enabled ERROR: operation not supported on hypertables that have compression enabled
--should succeed
BEGIN;
ALTER TABLE foo DROP CONSTRAINT chk_existing; ALTER TABLE foo DROP CONSTRAINT chk_existing;
ERROR: operation not supported on hypertables that have compression enabled ROLLBACK;
--note that the time column "a" should not be added to the end of the order by list again (should appear first) --note that the time column "a" should not be added to the end of the order by list again (should appear first)
SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass;
relid | segmentby | orderby | orderby_desc | orderby_nullsfirst relid | segmentby | orderby | orderby_desc | orderby_nullsfirst

View File

@ -112,7 +112,11 @@ ALTER TABLE foo ALTER COLUMN t SET NOT NULL;
ALTER TABLE foo RESET (timescaledb.compress); ALTER TABLE foo RESET (timescaledb.compress);
ALTER TABLE foo ADD CONSTRAINT chk CHECK(b > 0); ALTER TABLE foo ADD CONSTRAINT chk CHECK(b > 0);
ALTER TABLE foo ADD CONSTRAINT chk UNIQUE(b); ALTER TABLE foo ADD CONSTRAINT chk UNIQUE(b);
--should succeed
BEGIN;
ALTER TABLE foo DROP CONSTRAINT chk_existing; ALTER TABLE foo DROP CONSTRAINT chk_existing;
ROLLBACK;
--note that the time column "a" should not be added to the end of the order by list again (should appear first) --note that the time column "a" should not be added to the end of the order by list again (should appear first)
SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass;