# ---------------------------------------------------------
# Ensure Unique Indexes Work With Delete Preserving Encoding
# ---------------------------------------------------------
statement
CREATE TABLE ti (
    a INT PRIMARY KEY,
    b INT,
    c INT,
    FAMILY (a, b, c),
    UNIQUE INDEX index_to_mutate (b, c) WHERE c > b
);
----

mutate-index ti index_to_mutate WRITE_ONLY use_delete_preserving_encoding=true
----

statement
INSERT INTO ti VALUES (1, 1, 100), (2, 2, 1)
----

# Test that it's okay to delete and insert the same entry back into the unique
# delete-preserving index.
kvtrace
DELETE FROM ti WHERE a = 1
----
Scan /Table/106/1/1/0 lock Exclusive (Block, Unreplicated)
Put (delete) /Table/106/2/1/100/0
Del /Table/106/1/1/0

kvtrace
INSERT INTO ti VALUES (1, 1, 100)
----
CPut /Table/106/1/1/0 -> /TUPLE/2:2:Int/1/1:3:Int/100
Put /Table/106/2/1/100/0 -> /BYTES/0x0a020389

# Update a row between not matching the partial index and matching the partial
# index, thus testing the index deletes that are triggered by this update path.
kvtrace
UPDATE ti SET c = 200 WHERE a = 2
----
Scan /Table/106/1/2/0 lock Exclusive (Block, Unreplicated)
Put /Table/106/1/2/0 -> /TUPLE/2:2:Int/2/1:3:Int/200
Put /Table/106/2/2/200/0 -> /BYTES/0x0a02038a

kvtrace
UPDATE ti SET c = 1 WHERE a = 2
----
Scan /Table/106/1/2/0 lock Exclusive (Block, Unreplicated)
Put /Table/106/1/2/0 -> /TUPLE/2:2:Int/2/1:3:Int/1
Put (delete) /Table/106/2/2/200/0

kvtrace
UPDATE ti SET c = 200 WHERE a = 2
----
Scan /Table/106/1/2/0 lock Exclusive (Block, Unreplicated)
Put /Table/106/1/2/0 -> /TUPLE/2:2:Int/2/1:3:Int/200
Put /Table/106/2/2/200/0 -> /BYTES/0x0a02038a
