Understanding queries
In order to make sense of the various types of queries, we will start with a common data model to be used across the following examples. For this data model, we will return to the authors
table, with name
as the partition key, followed by year
and title
as clustering columns. We'll also sort the year
in descending order. This table can be created as follows:
CREATE TABLE authors ( name text, year int, title text, isbn text, publisher text, PRIMARY KEY (name, year, title) ) WITH CLUSTERING ORDER BY (year DESC);
Also, for the purpose of these examples, we will assume a replication factor of three and consistency level of QUORUM
.
Query by key
We'll start with a basic query by key:
SELECT * FROM authors WHERE name = 'Tom Clancy';
For this simple select, the query makes the request to the coordinator node, which in this case owns a replica for our key. The coordinator then retrieves the row from another replica node to satisfy the quorum. Thus, we need a total of two...