title: How to implement pagination for cassandra by using keys?
body: <p>I'm trying to implement some kind of pagination feature for my app that using cassandra in the backend.</p>
  
  <pre><code>CREATE TABLE sample (
      some_pk int,
      some_id int,
      name1 txt,
      name2 text,
      value text,
      PRIMARY KEY (some_pk, some_id, name1, name2)
  )
  WITH CLUSTERING ORDER BY(some_id DESC)
  </code></pre>
  
  <p>I want to query 100 records, then store the last records keys in memory to use them later.</p>
  
  <pre><code>+---------+---------+-------+-------+-------+
  | sample_pk| some_id | name1 | name2 | value |
  +---------+---------+-------+-------+-------+
  | 1       | 125     | x     | ''    | ''    |
  +---------+---------+-------+-------+-------+
  | 1       | 124     | a     | ''    | ''    |
  +---------+---------+-------+-------+-------+
  | 1       | 124     | b     | ''    | ''    |
  +---------+---------+-------+-------+-------+
  | 1       | 123     | y     | ''    | ''    |
  +---------+---------+-------+-------+-------+
  </code></pre>
  
  <p>(for simplicity, i left some columns empty. partition key(sample_pk) is not important)</p>
  
  <p>let's assume my page size is 2.</p>
  
  <pre><code>select * from sample where sample_pk=1 limit 2;
  </code></pre>
  
  <p>returns first 2 rows. now i store the last record in my query result and run query again to get next 2 rows;</p>
  
  <p>this is the query that does not work because of restriction of a single non-EQ relation</p>
  
  <pre><code>select * from where sample_pk=1 and some_id &lt;= 124 and name1&gt;='a' and name2&gt;='' limit 2; 
  </code></pre>
  
  <p>and this one returns wrong results because some_id is in descending order and name columns are in ascending order.</p>
  
  <pre><code>select * from where sample_pk=1 and (some_id, name1, name2) &lt;= (124, 'a', '') limit 2; 
  </code></pre>
  
  <p>So I'm stuck. How can I implement pagination? </p>