Cassandra二级索引问题 - 返回零行 [英] Cassandra secondary index issue - returning zero rows

查看:143
本文介绍了Cassandra二级索引问题 - 返回零行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,第二个索引在cassandra中返回零行:

I have a problem in that a secondary index is returning zero rows in cassandra:

我沿着入门文档跟踪:

http://www.datastax。 com / documentation / getting_started / doc / getting_started / gettingStartedCQL.html

根据我有以下cassandra脚本

Based on that I have the following cassandra script


/* 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)

这应该很简单 - 我错过了什么?

This should be straightforward -- am I missing something?

推荐答案

c $ c> SELECT 查询返回结果意味着 CREATE INDEX 将同步执行,它将

For the 2 SELECT queries to return results would mean that the CREATE INDEX would execute synchronously and it will only return after all existing data would be indexed.

如果您在插入任何数据之前更改脚本中的顺序以定义索引, '期望2选择返回结果。

If you change the order in the script to have the index defined before you insert any data, I'd expect the 2 selects to return results.

这篇关于Cassandra二级索引问题 - 返回零行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆