The best way to check existence of filtered rows in Cassandra? by user-defined aggregate?

对着背影说爱祢 提交于 2019-12-12 10:18:30

问题


I have a Cassandra table,

CREATE TABLE read_locks (
    parent_path text,
    filename text,
    instance text,
    PRIMARY KEY ((parent_path, filename), instance)
);

Logically I want to check the existence of any locks on a file by the following statement:

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

Of course, I have at least 2 implementations.

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

and then to use other code, i.e. C++, to check the value of result.

Or

select * from read_locks where parent_path='...' and filename='...';

and then to use other code, i.e. C++, to check the bool value of the following statement:

cass_iterator_next(rows)

I am not sure which is better.

And I guess there is a user-defined aggregate function to do so, but I couldn't figure out.

Please share your comments.

Thank you in advance, Ying


回答1:


If you only care if there are any locks, and now how many locks there are, then it's probably more efficient to add a limit clause like this:

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

If that returns a row, then you know there is at least one lock on the file, and if it returns nothing, then there are no locks on the file.



来源:https://stackoverflow.com/questions/39140089/the-best-way-to-check-existence-of-filtered-rows-in-cassandra-by-user-defined-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!