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: timescale#6158
  • Loading branch information
JamesGuthrie committed May 15, 2024
1 parent d49a422 commit c90abc2
Show file tree
Hide file tree
Showing 4 changed files with 46 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
34 changes: 34 additions & 0 deletions tsl/test/expected/compression_ddl.out
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,40 @@ 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
SELECT relreplident, count(*) FROM show_chunks('test1') ch INNER JOIN pg_class c ON (ch = c.oid) GROUP BY 1 ORDER BY 1;
relreplident | count
--------------+-------
d | 27
(1 row)

SELECT relreplident FROM pg_class c WHERE c.relname = 'test1';
relreplident
--------------
d
(1 row)

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 relreplident, count(*) FROM show_chunks('test1') ch INNER JOIN pg_class c ON (ch = c.oid) GROUP BY 1 ORDER BY 1;
relreplident | count
--------------+-------
f | 27
(1 row)

SELECT relreplident FROM pg_class c WHERE c.relname = 'test1';
relreplident
--------------
f
(1 row)

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
10 changes: 10 additions & 0 deletions tsl/test/sql/compression_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ 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
SELECT relreplident, count(*) FROM show_chunks('test1') ch INNER JOIN pg_class c ON (ch = c.oid) GROUP BY 1 ORDER BY 1;
SELECT relreplident FROM pg_class c WHERE c.relname = 'test1';
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 relreplident, count(*) FROM show_chunks('test1') ch INNER JOIN pg_class c ON (ch = c.oid) GROUP BY 1 ORDER BY 1;
SELECT relreplident FROM pg_class c WHERE c.relname = 'test1';
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 c90abc2

Please sign in to comment.