# ---------------------------------------------------------
# Index With Delete Preserving Encoding
# ---------------------------------------------------------
statement
CREATE TABLE ti (
    a INT PRIMARY KEY,
    b INT,
    c INT,
    FAMILY (a, b, c),
    INDEX index_to_mutate (b, c)
);
----

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

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

kvtrace
DELETE FROM ti WHERE a = 1
----
Scan /Table/106/1/1/0 lock Exclusive (Block, Unreplicated)
Put (delete) /Table/106/2/2/100/1/0
Del /Table/106/1/1/0

# ---------------------------------------------------------
# Partial Index With Delete Preserving Encoding
# ---------------------------------------------------------
statement
CREATE TABLE tpi (
    a INT PRIMARY KEY,
    b INT,
    c STRING,
    FAMILY (a, b, c),
    INDEX partial (c) WHERE a > b AND c IN ('foo', 'foobar')
);
----

mutate-index tpi partial WRITE_ONLY use_delete_preserving_encoding=true
----

statement
INSERT INTO tpi VALUES (1, 2, 'bar'), (2, 3, 'bar'), (3, 2, 'foo')
----

# Delete a row that doesn't match the partial index.
kvtrace
DELETE FROM tpi WHERE a = 1
----
Scan /Table/107/1/1/0 lock Exclusive (Block, Unreplicated)
Del /Table/107/1/1/0

# Delete a row that matches the partial index.
kvtrace
DELETE FROM tpi WHERE a = 3
----
Scan /Table/107/1/3/0 lock Exclusive (Block, Unreplicated)
Put (delete) /Table/107/2/"foo"/3/0
Del /Table/107/1/3/0

# ---------------------------------------------------------
# Expression Index With Delete Preserving Encoding
# ---------------------------------------------------------
statement
CREATE TABLE tei (
  k INT PRIMARY KEY,
  a INT,
  b INT,
  FAMILY (k, a, b),
  INDEX t_a_plus_b_idx ((a + b))
)
----

mutate-index tei t_a_plus_b_idx WRITE_ONLY use_delete_preserving_encoding=true
----

statement
INSERT INTO tei VALUES (1, 2, 100), (2, 3, 200), (3, 4, 300)
----

kvtrace
DELETE FROM tei WHERE a + b = 102
----
Scan /Table/108/{1-2}
Put (delete) /Table/108/2/102/1/0
Del /Table/108/1/1/0

# ---------------------------------------------------------
# Inverted Index With Delete Preserving Encoding
# ---------------------------------------------------------

statement
CREATE TABLE tii (
  a INT PRIMARY KEY,
  b INT[],
  FAMILY (a,b),
  INVERTED INDEX inverted (b)
)
----

mutate-index tii inverted WRITE_ONLY use_delete_preserving_encoding=true
----

statement
INSERT INTO tii VALUES (1, ARRAY[1, 2, 3, 2, 2, NULL, 3])
----

kvtrace
DELETE FROM tii WHERE a = 1
----
Scan /Table/109/1/1/0 lock Exclusive (Block, Unreplicated)
Put (delete) /Table/109/2/NULL/1/0
Put (delete) /Table/109/2/1/1/0
Put (delete) /Table/109/2/2/1/0
Put (delete) /Table/109/2/3/1/0
Del /Table/109/1/1/0

# ---------------------------------------------------------
# Multicolumn Inverted Index With Delete Preserving Encoding
# ---------------------------------------------------------

statement
CREATE TABLE tmi (
  a INT PRIMARY KEY,
  b INT,
  c JSON,
  FAMILY (a, b, c),
  INVERTED INDEX inverted (b, c)
)
----

mutate-index tmi inverted WRITE_ONLY use_delete_preserving_encoding=true
----

statement
INSERT INTO tmi VALUES (1, 2, '{"a": "foo", "b": "bar"}'::json)
----

kvtrace
DELETE FROM tmi WHERE a = 1
----
Scan /Table/110/1/1/0 lock Exclusive (Block, Unreplicated)
Put (delete) /Table/110/2/2/"a"/"foo"/1/0
Put (delete) /Table/110/2/2/"b"/"bar"/1/0
Del /Table/110/1/1/0
