我有一个问题,因为二级索引在 cassandra 中返回零行:
我正在遵循入门文档:
http://www.datastax.com/documentation/getting_started/doc/getting_started/gettingStartedCQL.html
基于此,我有以下 cassandra 脚本
/* hello.cql */ drop keyspace test; CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }; use test; CREATE TABLE users ( user_id int PRIMARY KEY, fname text, lname text); DESCRIBE TABLES; INSERT INTO users (user_id, fname, lname) VALUES (1745, 'john', 'smith'); INSERT INTO users (user_id, fname, lname) VALUES (1744, 'john', 'doe'); INSERT INTO users (user_id, fname, lname) VALUES (1746, 'john', 'smith'); SELECT * FROM users; CREATE INDEX ON users (lname); /* These queries both return 0 rows ??? */ SELECT * FROM users WHERE lname = 'smith'; SELECT * FROM users WHERE lname = 'doe';
但是...
cqlsh < hello.cql users user_id | fname | lname ---------+-------+------- 1745 | john | smith 1744 | john | doe 1746 | john | smith (3 rows) (0 rows) (0 rows)
这应该很简单——我错过了什么吗?
最佳答案
对于返回结果的 2 个 SELECT
查询意味着 CREATE INDEX
将同步执行并且它将仅 所有现有数据都被索引后返回。
如果您更改脚本中的顺序以在插入任何数据之前定义索引,我希望 2 个选择返回结果。
关于Cassandra 二级索引问题 - 返回零行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25965124/