cassandracqlcql3datastax-enterprise

Results pagination in Cassandra (CQL)


I am wondering how can I achieve pagination using Cassandra.

Let us say that I have a blog. The blog lists max 10 posts per page. To access next posts a user must click on pagination menu to access page 2 (posts 11-20), page 3 (posts 21-30), etc.

Using SQL under MySQL, I could do the following:

SELECT * FROM posts LIMIT 20,10;

The first parameter of LIMIT is offset from the beginning of result set and second argument is amount of rows to fetch. The example above returns 10 rows starting from row 20.

How can I achieve the same effect in CQL?

I have found some solutions on Google, but all of them require to have "the last result from previous query". It works for having "next" button to paginate to another 10-results-set, but what if I want to jump from page 1 to page 5?


Solution

  • Try using the token function in CQL: https://docs.datastax.com/en/cql-oss/3.3/cql/cql_using/useToken.html

    Another suggestion, if you are using DSE, solr supports deep paging: https://cwiki.apache.org/confluence/display/solr/Pagination+of+Results