2014-09-22 49 views
2

我有一個問題,即二級指標在Cassandra是返回零行:卡桑德拉二級索引的問題 - 返回零行

我沿着入門文檔如下:

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

在此基礎上,我有以下卡桑德拉腳本

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

這應該是直截了當的 - 我錯過了什麼嗎?

回答

4

對於2個SELECT查詢返回的結果將意味着CREATE INDEX將執行同步現有的所有數據後僅回報將被編入索引。

如果更改腳本中的順序以在插入任何數據之前定義索引,我希望2選擇返回結果。

+0

是的,我以爲我已經試過了,但我必須有脂肪手指該嘗試。試了一遍,你是對的。儘管Datastax文檔錯誤。 – 2014-09-22 03:56:04

1

使用Cassandra 2.1.0,無論索引是在插入數據之前還是之後創建,我都會得到結果。

 
    Connected to Test Cluster at 127.0.0.1:9042. 
    [cqlsh 5.0.1 | Cassandra 2.1.0 | CQL spec 3.2.0 | Native protocol v3] 
    Use HELP for help. 
    cqlsh> 
    cqlsh> CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }; 
    cqlsh> use test; 
    cqlsh:test> CREATE TABLE users ( user_id int PRIMARY KEY, fname text, lname text); 
    cqlsh:test> INSERT INTO users (user_id, fname, lname) 
     ... VALUES (1745, 'john', 'smith'); 
    cqlsh:test> INSERT INTO users (user_id, fname, lname) 
     ... VALUES (1744, 'john', 'doe'); 
    cqlsh:test> INSERT INTO users (user_id, fname, lname) 
     ... VALUES (1746, 'john', 'smith'); 
    cqlsh:test> CREATE INDEX ON users (lname); 
    cqlsh:test> SELECT * FROM users WHERE lname = 'smith'; 

    user_id | fname | lname 
    ---------+-------+------- 
     1745 | john | smith 
     1746 | john | smith 

    (2 rows) 

    cqlsh:test> SELECT * FROM users WHERE lname = 'doe'; 

    user_id | fname | lname 
    ---------+-------+------- 
     1744 | john | doe 

    (1 rows) 
+0

並在hello.cql腳本中運行您的命令也會返回3行,2行和1行。 – catpaws 2014-09-22 14:22:56

+0

公平 - 可能是平臺或版本特定。爲了完整起見,當我回到那個框時,會發布特定的版本信息。 – 2014-09-22 17:53:35

0

下面是我的安裝平臺和版本信息:

 
[email protected]:~/Dropbox/source/casandra$ nodetool -h localhost version 
ReleaseVersion: 2.0.10 
[email protected]:~/Dropbox/source/casandra$ lsb_release -a 
No LSB modules are available. 
Distributor ID: Ubuntu 
Description: Ubuntu 14.04.1 LTS 
Release: 14.04 
Codename: trusty 
[email protected]:~/Dropbox/source/casandra$ ^C 
[email protected]:~/Dropbox/source/casandra$ 
+0

2.0.10 tarball安裝或任何以前的2.0 tarball安裝中不存在此問題。我剛剛嘗試在雲中安裝ubuntu上的2.0.10包失敗,所以我無法檢查您的平臺。是否有可能抹平石板並重試? – catpaws 2014-09-23 05:46:25

+0

更正 - 在2.0.5 https://issues.apache.org/jira/browse/CASSANDRA-6517上有一個類似的問題,但已解決。如果您願意,請嘗試使用nodetool rebuild_index測試用戶 – catpaws 2014-09-23 06:08:48