I am trying to create a table in Cassandra.
CREATE TABLE users (
user_name varchar PRIMARY KEY,
password varchar,
gender varchar,
session_token varchar,
state varchar,
birth_year bigint
);
现在如果我想查询表session_token = 1000001
的表用户名和密码Select user_name,password from users where session_token = 1000001;
Will this query work or do I have to create an index on session_token first and then do select query?
答案 0 :(得分:1)
您必须先在其上创建索引。
记住何时不使用索引:
在您的情况下,session_token
似乎是高基数列
最好创建另一个表:
CREATE TABLE user_by_session (
session_token varchar,
user_name varchar,
password varchar,
PRIMARY KEY(session_token, user_name)
);
现在您可以查询:
SELECT user_name, password FROM user_by_session WHERE session_token = '1000001';
来源:http://docs.datastax.com/en/cql/3.1/cql/ddl/ddl_when_use_index_c.html#concept_ds_sgh_yzz_zj