mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Fix ALTER TABLE / REPLICA IDENTITY for temporal tables
REPLICA IDENTITY USING INDEX did not accept a GiST index. This should be allowed when used as a temporal primary key. Author: Paul Jungwirth <pj@illuminatedcomputing.com> Discussion: https://www.postgresql.org/message-id/04579cbf-b134-45e1-8f2d-8c54c849c1ee@illuminatedcomputing.com
This commit is contained in:
@ -17296,9 +17296,14 @@ ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode
|
|||||||
errmsg("\"%s\" is not an index for table \"%s\"",
|
errmsg("\"%s\" is not an index for table \"%s\"",
|
||||||
RelationGetRelationName(indexRel),
|
RelationGetRelationName(indexRel),
|
||||||
RelationGetRelationName(rel))));
|
RelationGetRelationName(rel))));
|
||||||
/* The AM must support uniqueness, and the index must in fact be unique. */
|
/*
|
||||||
if (!indexRel->rd_indam->amcanunique ||
|
* The AM must support uniqueness, and the index must in fact be unique.
|
||||||
!indexRel->rd_index->indisunique)
|
* If we have a WITHOUT OVERLAPS constraint (identified by uniqueness +
|
||||||
|
* exclusion), we can use that too.
|
||||||
|
*/
|
||||||
|
if ((!indexRel->rd_indam->amcanunique ||
|
||||||
|
!indexRel->rd_index->indisunique) &&
|
||||||
|
!(indexRel->rd_index->indisunique && indexRel->rd_index->indisexclusion))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||||
errmsg("cannot use non-unique index \"%s\" as replica identity",
|
errmsg("cannot use non-unique index \"%s\" as replica identity",
|
||||||
|
@ -978,9 +978,25 @@ SELECT * FROM tp2 ORDER BY id, valid_at;
|
|||||||
|
|
||||||
DROP TABLE temporal_partitioned;
|
DROP TABLE temporal_partitioned;
|
||||||
-- ALTER TABLE REPLICA IDENTITY
|
-- ALTER TABLE REPLICA IDENTITY
|
||||||
-- (should fail)
|
\d temporal_rng
|
||||||
|
Table "public.temporal_rng"
|
||||||
|
Column | Type | Collation | Nullable | Default
|
||||||
|
----------+-----------+-----------+----------+---------
|
||||||
|
id | int4range | | not null |
|
||||||
|
valid_at | daterange | | not null |
|
||||||
|
Indexes:
|
||||||
|
"temporal_rng_pk" PRIMARY KEY (id, valid_at WITHOUT OVERLAPS)
|
||||||
|
|
||||||
ALTER TABLE temporal_rng REPLICA IDENTITY USING INDEX temporal_rng_pk;
|
ALTER TABLE temporal_rng REPLICA IDENTITY USING INDEX temporal_rng_pk;
|
||||||
ERROR: cannot use non-unique index "temporal_rng_pk" as replica identity
|
\d temporal_rng
|
||||||
|
Table "public.temporal_rng"
|
||||||
|
Column | Type | Collation | Nullable | Default
|
||||||
|
----------+-----------+-----------+----------+---------
|
||||||
|
id | int4range | | not null |
|
||||||
|
valid_at | daterange | | not null |
|
||||||
|
Indexes:
|
||||||
|
"temporal_rng_pk" PRIMARY KEY (id, valid_at WITHOUT OVERLAPS) REPLICA IDENTITY
|
||||||
|
|
||||||
--
|
--
|
||||||
-- ON CONFLICT: ranges
|
-- ON CONFLICT: ranges
|
||||||
--
|
--
|
||||||
|
@ -691,8 +691,9 @@ SELECT * FROM tp2 ORDER BY id, valid_at;
|
|||||||
DROP TABLE temporal_partitioned;
|
DROP TABLE temporal_partitioned;
|
||||||
|
|
||||||
-- ALTER TABLE REPLICA IDENTITY
|
-- ALTER TABLE REPLICA IDENTITY
|
||||||
-- (should fail)
|
\d temporal_rng
|
||||||
ALTER TABLE temporal_rng REPLICA IDENTITY USING INDEX temporal_rng_pk;
|
ALTER TABLE temporal_rng REPLICA IDENTITY USING INDEX temporal_rng_pk;
|
||||||
|
\d temporal_rng
|
||||||
|
|
||||||
--
|
--
|
||||||
-- ON CONFLICT: ranges
|
-- ON CONFLICT: ranges
|
||||||
|
Reference in New Issue
Block a user