cassandracassandra-3.0cql3tombstone

Cassandra map and column update regarding tombstones


I have this following table:

CREATE TABLE example
(
    id text,
    users map<text,text>,
    lastvisit int,
    ...
    PRIMARY KEY (userid)
);

Sometimes I update a column or a map entry like:

1) update example set users = users - {'JOE'} where id = 'id';
2) update example set users = users + {'JOE':'meta'} where id = 'id';
3) update example set lastvisit = 100 where id = 'id';

I need to know how each query handles the old data in manner of tombstones and compaction.

The following I have researched/ advised but specially on maps I lack on information.

  1. Deletes the map entry at key = 'JOE' by generating a tombstone only for that entry in the map. On compaction the value is dropped.

  2. Inserts the key value pair to the map. The old entry is dropped at compaction since there is a newer entry.

  3. The column entry is updated and like in 2, the old value is dropped in compaction

The question in each case is, will the whole row be written again or only the updated value with a newer timestamp ?


Solution

    1. A tombstone for the map item where key = 'BOB' will be inserted.
    2. The row doesn't get overwritten. Just adds a new map item.
    3. Strictly speaking, it's not an UPDATE -- a new column will be inserted. All mutations in C* are inserts under the hood even for deletes.

    Here are some additional points:

    You had a typo in your schema. It should be -- users map<text,text>.

    For (1) you need to enclose the item in curly brackets otherwise the CQL statement is invalid -- {'JOE'}.

    For (2) you need a colon (:) to delimit the key and value -- {'JOE':'meta'}.

    For (3) there's no evidence that lastvisit was defined so a new column lastvisit = 100 will be inserted and there's no old value to be deleted. Cheers!