Database Reference
In-Depth Information
Cassandra provides support to add indexes over column values, called Secondary
indexes . Chapter 3 will cover more about indexes, so for now let's just take a look at a
simple secondary index example.
Let's discuss the same Twitter example and see how we can utilize and enable sec-
ondary index support.
1.
First, let's create twitter keyspace and column family users .
create keyspace twitter with replication =
{'class' : 'SimpleStrategy' ,
'replication_factor' : 3};
use twitter;
create table users(user_id text PRIMARY
KEY,fullname text,email text,password text,
followers map<text, text>);
2.
Insert a user with e-mail and password:
insert into
users(user_id,email,password,fullname,followers)
values
('imvivek',' imvivek@xxx.com ','password','vivekm',{'mkundera':'milan
kundera','guest': 'guestuser'});
Before we move ahead with this exercise, it's worth discussing
which columns should be indexed?
Any read request using the secondary index will actually be
broadcast to all nodes in a cluster. Cassandra maintains a hidden
column family for the secondary index locally on node, which is
scanned for retrieving rows using secondary indexes.
While performing data modeling, we should create secondary in-
dexes over column values which should return a big chunk of data
over a very large data set. Indexes over unique values of small data
sets would simply become an overhead, which is not a good data
modeling practice. Index over fullname is a possible candidate for in-
dexing.
Search WWH ::




Custom Search