计算表

时间:2016-02-25 23:28:57

标签: cassandra

我在Cassandra DB中计算非常大的表时遇到了麻烦。

简单陈述:

SELECT COUNT(*) FROM my.table;

调用超时错误:

OperationTimedOut: errors={}, ...

我在〜/ .cassandra / cqlshrc文件中增加了client_timeout:

[connection]
client_timeout = 900

此时语句正在运行并再次调用OperationTimeout错误。如何计算表中的行?

1 个答案:

答案 0 :(得分:2)

您可以使用拆分令牌范围多次计数。 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

相关问题