Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查Cassandra中是否存在筛选行的最佳方法?按用户定义的聚合?_Cassandra_Aggregate Functions - Fatal编程技术网

检查Cassandra中是否存在筛选行的最佳方法?按用户定义的聚合?

检查Cassandra中是否存在筛选行的最佳方法?按用户定义的聚合?,cassandra,aggregate-functions,Cassandra,Aggregate Functions,我有一张卡桑德拉桌子 CREATE TABLE read_locks ( parent_path text, filename text, instance text, PRIMARY KEY ((parent_path, filename), instance) ); 逻辑上,我希望通过以下语句检查文件上是否存在任何锁: select count(*)>0 as result from read_locks where parent_path='...'

我有一张卡桑德拉桌子

CREATE TABLE read_locks (
    parent_path text,
    filename text,
    instance text,
    PRIMARY KEY ((parent_path, filename), instance)
);
逻辑上,我希望通过以下语句检查文件上是否存在任何锁:

select count(*)>0 as result from read_locks where parent_path='...' and filename='...';
cass_iterator_next(rows)
当然,我至少有两个实现

select count(*) as result from read_locks where parent_path='...' and filename='...';

然后使用其他代码,即C++,检查结果的值。 或

然后使用其他代码,即C++,检查下面语句的布尔值:

select count(*)>0 as result from read_locks where parent_path='...' and filename='...';
cass_iterator_next(rows)
我不确定哪一个更好

我想有一个用户定义的聚合函数可以实现这一点,但我想不出来

请分享你的评论

提前谢谢大家,,
Ying

如果您只关心是否有锁,以及现在有多少锁,那么添加这样的限制子句可能更有效:

SELECT * FROM read_locks WHERE parent_path='...' and filename='...' LIMIT 1;

如果它返回一行,那么您知道文件上至少有一个锁,如果它不返回任何内容,那么文件上就没有锁。

如果您可以有多个实例(>1000),并且您只关心任何实例是否存在锁,那么您应该避免计数。计数将导致一次读取所有数据,这对于大量行将导致问题。至少使用*可以利用分页控制每页读取的数据量。建议不错。谢谢你的建议。谢谢