Database Reference
In-Depth Information
Chapter7.Reading and Writing Data
Now that we understand the data model, we'll look at the different kinds of queries you can per-
form in Cassandra to read and write data. In this chapter, we use Cassandra 0.6.7-beta1, which
is the most recent release version at the time of this writing.
Query Differences Between RDBMS and Cassandra
There are several differences between Cassandra's model and query methods and what's avail-
able in RDBMS, and these are important to keep in mind.
No Update Query
There is no first-order concept of an update in Cassandra, meaning that there is no client query
called an “update.” You can readily achieve the same effect, however, by simply performing an
insert using an existing row key. If you issue an insert statement for a key that already exists,
Cassandra will overwrite the values for any matching columns; if your query contains additional
columns that don't already exist for that row key, then the additional columns will be inserted.
This is all seamless.
Record-Level Atomicity on Writes
Cassandra automatically gives you record-level atomicity on every write operation. In RDBMS,
you would have to specify row-level locking. Although Cassandra offers atomicity at the column
family level, it does not guarantee isolation.
No Server-Side Transaction Support
Because you need to denormalize tables to create secondary indexes, you might need to insert
data into two or more tables (one for your primary table and one for your inverted or secondary
index). This means issuing two insert statements. So if it is applicable for your use case, you'll
need to manually “roll back” writes by issuing a delete if one of the insert operations fails.
More to the point, perhaps, is that Cassandra doesn't have transactions, because it just wasn't
built with that goal in mind.
No Duplicate Keys
It is possible in SQL databases to insert more than one row with identical values if you have not
defined a unique primary key constraint on one of the columns. This is not possible in Cassandra.
Search WWH ::




Custom Search