Skip to content

Commit

Permalink
Allow replica identity on compressed hypertables
Browse files Browse the repository at this point in the history
This unblocks the execution of `ALTER TABLE ... REPLICA IDENTITY ...` on
hypertables with compression enabled. The configured replica identity
only propagates to tables belonging to the uncompressed hypertable.

Fixes: #6158
  • Loading branch information
JamesGuthrie committed May 15, 2024
1 parent 009d970 commit 0c9d6f5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions .unreleased/pr_6897
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements: #6897 Add support for replica identity on compressed hypertables
1 change: 1 addition & 0 deletions src/process_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ check_alter_table_allowed_on_ht_with_compression(Hypertable *ht, AlterTableStmt
case AT_ColumnDefault: /* this is passed down */
case AT_DropColumn: /* this is passed down */
case AT_DropConstraint: /* this is passed down */
case AT_ReplicaIdentity:
case AT_ReAddStatistics:
case AT_SetCompression:
continue;
Expand Down
42 changes: 42 additions & 0 deletions tsl/test/expected/compression_ddl.out
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,48 @@ DROP INDEX new_index;
ALTER TABLE test1 SET (fillfactor=100);
ALTER TABLE test1 RESET (fillfactor);
ALTER TABLE test1 ALTER COLUMN b SET STATISTICS 10;
-- ensure that REPLICA IDENTITY works
ALTER TABLE test1 REPLICA IDENTITY FULL;
SELECT relname, relreplident FROM pg_class WHERE relname = 'test1' ORDER BY relname;
relname | relreplident
---------+--------------
test1 | f
(1 row)

-- the chunk's setting should also change to FULL
SELECT relname, relreplident FROM show_chunks('test1') ch INNER JOIN pg_class c ON (ch = c.oid) ORDER BY relname;
relname | relreplident
-------------------+--------------
_hyper_1_10_chunk | f
_hyper_1_11_chunk | f
_hyper_1_12_chunk | f
_hyper_1_13_chunk | f
_hyper_1_14_chunk | f
_hyper_1_15_chunk | f
_hyper_1_16_chunk | f
_hyper_1_17_chunk | f
_hyper_1_18_chunk | f
_hyper_1_19_chunk | f
_hyper_1_1_chunk | f
_hyper_1_20_chunk | f
_hyper_1_21_chunk | f
_hyper_1_22_chunk | f
_hyper_1_23_chunk | f
_hyper_1_24_chunk | f
_hyper_1_25_chunk | f
_hyper_1_26_chunk | f
_hyper_1_27_chunk | f
_hyper_1_2_chunk | f
_hyper_1_3_chunk | f
_hyper_1_4_chunk | f
_hyper_1_5_chunk | f
_hyper_1_6_chunk | f
_hyper_1_7_chunk | f
_hyper_1_8_chunk | f
_hyper_1_9_chunk | f
(27 rows)

ALTER TABLE test1 REPLICA IDENTITY DEFAULT;
-- make sure we cannot create constraints or unique indexes on compressed hypertables
\set ON_ERROR_STOP 0
ALTER TABLE test1 ADD CONSTRAINT c1 UNIQUE(time,i);
Expand Down
7 changes: 7 additions & 0 deletions tsl/test/sql/compression_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ ALTER TABLE test1 SET (fillfactor=100);
ALTER TABLE test1 RESET (fillfactor);
ALTER TABLE test1 ALTER COLUMN b SET STATISTICS 10;

-- ensure that REPLICA IDENTITY works
ALTER TABLE test1 REPLICA IDENTITY FULL;
SELECT relname, relreplident FROM pg_class WHERE relname = 'test1' ORDER BY relname;
-- the chunk's setting should also change to FULL
SELECT relname, relreplident FROM show_chunks('test1') ch INNER JOIN pg_class c ON (ch = c.oid) ORDER BY relname;
ALTER TABLE test1 REPLICA IDENTITY DEFAULT;

-- make sure we cannot create constraints or unique indexes on compressed hypertables
\set ON_ERROR_STOP 0
ALTER TABLE test1 ADD CONSTRAINT c1 UNIQUE(time,i);
Expand Down

0 comments on commit 0c9d6f5

Please sign in to comment.