2016-02-25 73 views
1

我在Cassandra DB中非常大的表的行計數問題。在表中計算行

簡單的聲明:

SELECT COUNT(*) FROM my.table; 

調用超時錯誤:

OperationTimedOut: errors={}, ... 

我在〜/ .cassandra/cqlshrc文件增加CLIENT_TIMEOUT:

[connection] 
client_timeout = 900 

聲明運行這個時間並再次調用OperationTimeout錯誤。我如何計算表中的行數?

+0

超時時間可能是在服務器端。也許這[線程](http://stackoverflow.com/questions/15238970/rpc-timeout-in-cqlsh-cassandra)可以幫助嗎? – Ralf

+0

SELECT COUNT(*)FROM my.table limit <<上限>>例如隨着增加上限獲得記錄的實際計數。 – Gomes

回答

1

您可以使用拆分令牌範圍進行多次計數。 Cassandra使用從-2^63到+ 2^63-1的令牌範圍。因此,通過拆分這個範圍,你可以做這樣的疑問:

select count(*) from my.table where token(partitionKey) > -9223372036854775808 and token(partitionKey) < 0; 
select count(*) from my.table where token(partitionKey) >= 0 and token(partitionKey) < 9223372036854775807; 

添加這兩個數,你就會有總數。 如果這些查詢仍未通過,您可以再次將它們拆分爲更小的標記範圍。

看看這個工具,它基本上不正是這樣:https://github.com/brianmhess/cassandra-count