2
votes

Suppose, I have an application which reads data from cassandra and displays them to the user in chunks of lines like 10 or 20 rows a page. Is there a way to do it efficiently in cassandra? Suppose, I have a table 'ks1.cf1' with partition key 'pk' and clustering column 'ck' and each partition has more than 1000 rows and I want to display 10 rows per partition to the user at a time. One way to do it is running

SELECT * FROM ks1.cf1 LIMIT 10; and get the last row and do an inequality based on the clustering column (value of 'ck') and limiting the results again like

SELECT * FROM ks1.cf1 WHERE ck > value_in_last_row LIMIT 10;

Is this an efficient way to do this or will there be a lot of overhead running the same query multiple times? How does result pagination work in cqlsh and does cql or java driver support anything like it? Also, does using LIMIT fetch the entire partition and display only the number of records requested? Also, how can I do the same for general queries like if I am fetching multiple partitions and want to display n partitions at a time?

1

1 Answers

5
votes

This is easy if you only need to jump to the next page. The latest Java driver versions (2.0.10.1 and 2.1.6) expose the paging state of the query, see documentation here.

On the other hand, there is no trivial solution for offset queries (e.g. jump to page 20 directly). Cassandra does not implement them out of the box, see CASSANDRA-6511.