aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2020-06-05 10:29:27 +0900
committerMichael Paquier <michael@paquier.xyz>2020-06-05 10:29:27 +0900
commit75f14792408211f2ef6bf2dac31796a8a1ec3efb (patch)
tree862f270fc1da35bfd85e55c76657d5ad51088b1e
parenta958b07bc4533d8c80b0f10cc4a3b209002b387f (diff)
downloadpostgresql-75f14792408211f2ef6bf2dac31796a8a1ec3efb.tar.gz
postgresql-75f14792408211f2ef6bf2dac31796a8a1ec3efb.zip
Preserve pg_index.indisreplident across REINDEX CONCURRENTLY
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
-rw-r--r--src/backend/catalog/index.c4
-rw-r--r--src/test/regress/expected/create_index.out21
-rw-r--r--src/test/regress/sql/create_index.sql11
3 files changed, 36 insertions, 0 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 579b14c1f32..d290c7e980e 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -1527,6 +1527,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;
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index a649957f758..c3bf910e023 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2128,6 +2128,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);
diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql
index fb7da725ff0..56887526b82 100644
--- a/src/test/regress/sql/create_index.sql
+++ b/src/test/regress/sql/create_index.sql
@@ -860,6 +860,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