Database Reference
In-Depth Information
Data on a Cassandra node is stored locally for each row. Rows are distributed across
multiple nodes, but all columns for a particular row key will be stored locally on a
node. Cassandra by default provides the primary index over row key for faster retrieval
by row key.
Secondary Indexes
Indexes over column values are known as secondary indexes. These indexes are stored
locally on a node where physical data resides. That allows Cassandra to perform faster
index-based retrieval of data. Secondary indexes are stored in a hidden column family
and internally managed by the node itself.
Let's explore more on secondary indexes with a simple exercise.
1.
First, let's create a keyspace twitter and column family users .
create keyspace twitter with replication = {
'class':'SimpleStrategy' ,
'replication_factor':3};use twitter;
create column family users with
key_validation_class='UTF8Type' and
comparator='UTF8Type' and
default_validation_class='UTF8Type';
create table users (user_id uuid primary key,
first_name text, twitter_handle text);
2.
Let's create index over first_name using create index syntax (see
Figure 3-3 ) .
create index fname_idx on users(first_name);
3.
Describe table users :
describe table users;
Figure 3-3 shows users schema with index created on
first_name.
 
Search WWH ::




Custom Search