Prevent tombstones creation

2019-03-01 01:12发布

问题:

I need to perform an insert to Cassandra table without creating tombstones for any column. I am using a query similar to this :

insert into my_table(col1,col2,col3) values(val1,val2,null)

where col1, col2 and col3 are all the attributes in my_table. Is there any other solution or workaround to prevent tombstone creation for say col3 apart from passing only non-null attributes in our query and letting cassandra set the remaining attributes to null?

回答1:

Don't include col3 in your insert and it just wont set anything.

insert into my_table(col1,col2) values(val1,val2)

If curious about structure on disk, do a nodetool flush and run sstabledump on the sstable created to see difference.



回答2:

If you insert null values, Cassandra will create tombstones. If you know that col3 will be null, don't use it in your query.

insert into my_table(col1,col2) values(val1,val2)

I would suggest two really good articles on the subject

  • Common Problems with Cassandra Tombstones
  • About Deletes and Tombstones in Cassandra.


回答3:

Assuming you are using prepared statements you can use the "unset" functionality that was introduced in Cassandra 2.2.0, which lets you use leave prepared statement variables without values and without creating tombstones on the server. It is supported in the Java driver 3.0.0 and other drivers.