【问题标题】:Count rows in table计算表中的行数
【发布时间】:2016-06-09 00:09:33
【问题描述】:

我在 Cassandra DB 中非常大的表的行数方面遇到了问题。

简单语句:

SELECT COUNT(*) FROM my.table;

调用超时错误:

OperationTimedOut: errors={}, ...

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

[connection]
client_timeout = 900

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

【问题讨论】:

  • 超时可能在服务器端。也许这thread 有帮助?
  • SELECT COUNT(*) FROM my.table 限制 > 例如尝试增加上限以获取记录的实际计数。

标签: cassandra


【解决方案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

【讨论】:

    猜你喜欢
    • 2010-11-12
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-25
    • 2019-09-25
    • 1970-01-01
    相关资源
    最近更新 更多