Preserve pg_index.indisreplident across REINDEX CONCURRENTLY
authorMichael Paquier <michael@paquier.xyz>
Fri, 5 Jun 2020 01:26:02 +0000 (10:26 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 5 Jun 2020 01:26:02 +0000 (10:26 +0900)
If the flag value is lost, logical decoding would work the same way as
REPLICA IDENTITY NOTHING, meaning that no old tuple values would be
included in the changes anymore produced by logical decoding.

Author: Michael Paquier
Reviewed-by: Euler Taveira
Discussion: https://postgr.es/m/20200603065340.GK89559@paquier.xyz
Backpatch-through: 12

src/backend/catalog/index.c
src/test/regress/expected/create_index.out
src/test/regress/sql/create_index.sql

index 7cfbdd57db82329b1a06bcd43767d6c49d160f40..cdc01c49c9ff6c1a238b1c65f5a7113a374fb7bd 100644 (file)
@@ -1538,6 +1538,10 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
        newIndexForm->indimmediate = oldIndexForm->indimmediate;
        oldIndexForm->indimmediate = true;
 
+       /* Preserve indisreplident in the new index */
+       newIndexForm->indisreplident = oldIndexForm->indisreplident;
+       oldIndexForm->indisreplident = false;
+
        /* Preserve indisclustered in the new index */
        newIndexForm->indisclustered = oldIndexForm->indisclustered;
 
index ae95bb38a64642679397018e8e3e3b0273e1b25f..e3e6634d7e1cebbc1a1080ee7503afdc53a32413 100644 (file)
@@ -2141,6 +2141,27 @@ SELECT indexrelid::regclass, indisclustered FROM pg_index
 (1 row)
 
 DROP TABLE concur_clustered;
+-- Check that indisreplident updates are preserved.
+CREATE TABLE concur_replident(i int NOT NULL);
+CREATE UNIQUE INDEX concur_replident_i_idx ON concur_replident(i);
+ALTER TABLE concur_replident REPLICA IDENTITY
+  USING INDEX concur_replident_i_idx;
+SELECT indexrelid::regclass, indisreplident FROM pg_index
+  WHERE indrelid = 'concur_replident'::regclass;
+       indexrelid       | indisreplident 
+------------------------+----------------
+ concur_replident_i_idx | t
+(1 row)
+
+REINDEX TABLE CONCURRENTLY concur_replident;
+SELECT indexrelid::regclass, indisreplident FROM pg_index
+  WHERE indrelid = 'concur_replident'::regclass;
+       indexrelid       | indisreplident 
+------------------------+----------------
+ concur_replident_i_idx | t
+(1 row)
+
+DROP TABLE concur_replident;
 -- Partitions
 -- Create some partitioned tables
 CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1);
index c3246cb296ff8de9284a56961df51fac153d1a8a..f3667bacdc926b30a2a08f25011990227b118f8b 100644 (file)
@@ -866,6 +866,17 @@ REINDEX TABLE CONCURRENTLY concur_clustered;
 SELECT indexrelid::regclass, indisclustered FROM pg_index
   WHERE indrelid = 'concur_clustered'::regclass;
 DROP TABLE concur_clustered;
+-- Check that indisreplident updates are preserved.
+CREATE TABLE concur_replident(i int NOT NULL);
+CREATE UNIQUE INDEX concur_replident_i_idx ON concur_replident(i);
+ALTER TABLE concur_replident REPLICA IDENTITY
+  USING INDEX concur_replident_i_idx;
+SELECT indexrelid::regclass, indisreplident FROM pg_index
+  WHERE indrelid = 'concur_replident'::regclass;
+REINDEX TABLE CONCURRENTLY concur_replident;
+SELECT indexrelid::regclass, indisreplident FROM pg_index
+  WHERE indrelid = 'concur_replident'::regclass;
+DROP TABLE concur_replident;
 
 -- Partitions
 -- Create some partitioned tables