为什么(插入的)行在将列更新为空后消失? (但不是当它被插入时)

Why does a (upserted) row disappear after updating the column to null? (But not when it's been inserted)

我对 Cassandra 中的插入和更新的理解是它们基本上是同一件事。这也是文档所说的 ( https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlUpdate.html?hl=upsert )

Note: Unlike the INSERT command, the UPDATE command supports counters. Otherwise, the UPDATE and INSERT operations are identical.

所以除了对计数器的支持之外,它们应该是相同的。

但后来我 运行 遇到一个问题,如果我将列设置为 null,通过 update 创建的行将消失,而如果行是使用 insert.

创建
cqlsh:test> CREATE TABLE IF NOT EXISTS address_table (
               ...     name text PRIMARY KEY,
               ...     addresses text,
               ... );
cqlsh:test> insert into address_table (name, addresses) values ('Alice', 'applelane 1');
cqlsh:test> update address_table set addresses = 'broadway 2' where name = 'Bob' ;

cqlsh:test> select * from address_table;

 name  | addresses
-------+-------------
   Bob |  broadway 2
 Alice | applelane 1

(2 rows)


cqlsh:test> update address_table set addresses = null where name = 'Alice' ;
cqlsh:test> update address_table set addresses = null where name = 'Bob' ;

cqlsh:test> select * from address_table;

 name  | addresses
-------+-----------
 Alice |      null

(1 rows)

如果我跳过第一次创建行的单独步骤,也会发生同样的事情。使用 insert 我可以创建一个具有 null 值的行,但是如果我使用 update 则找不到该行。

cqlsh:test> insert into address_table (name, addresses) values ('Caroline', null);
cqlsh:test> update address_table set addresses = null where name = 'Dexter' ;
cqlsh:test> select * from address_table;

 name     | addresses
----------+-----------
 Caroline |      null
    Alice |      null

(2 rows)

谁能解释一下这是怎么回事?

我们正在使用 Cassandra 3.11.3

这是预期的行为。请参阅 https://issues.apache.org/jira/browse/CASSANDRA-14478

中的详细信息

INSERT adds a row marker, while UPDATE does not. What does this mean? Basically an UPDATE requests that individual cells of the row be added, but not that the row itself be added; So if one later deletes the same individual cells with DELETE, the entire row goes away. However, an "INSERT" not only adds the cells, it also requests that the row be added (this is implemented via a "row marker"). So if later all the row's individual cells are deleted, an empty row remains behind (i.e., the primary of the row which now has no content is still remembered in the table).