Result paging with Cassandra drivers
Cassandra drivers support paging for queries that return large result sets. The client fetches each page in a separate network request.
Page size and paging state
The |
A request’s page size
specifies how many rows are returned at a time from the server.
With each response, the server returns a paging_state
, which is a binary token for the next request to indicate where to restart from.
For example:
Initial request: SELECT * FROM foo, page size = 10
Response: 10 rows, paging_state = 0xabcd
Second request, to get the next page: SELECT * FROM foo, page size = 10, paging_state = 0xabcd
Response: 10 rows, paging_state = 0xef32
Last request, in which the results are exhausted: SELECT * FROM foo, page size = 10, paging_state = 0xef32
Response: 5 rows, no paging_state (end of results)
Result objects
Drivers produce result objects that you can use to fetch the next page directly without manipulating the paging state or re-executing the query explicitly.
The paging state can be extracted from a given result object and reinjected in a query later. This option is useful if you need to store the state across executions. For example, in a stateless REST web service, the paging state can be encoded in the link to the next page to seamlessly navigate to where the user left off.
Configure and use result paging
For all drivers, paging is enabled by default with configurable options, and you can disable paging or override the page size for individual queries.
Each driver has it’s own paging API. For usage details, see the documentation for your driver.
C/C++ driver paging
See C/C++ driver paging.
C# driver paging
The C# driver provides automatic paging to traverse the whole result set transparently by triggering background fetches as the iteration crosses page boundaries.
GoCQL driver paging
See GoCQL driver paging.
Java driver paging
The Java driver supports multiple configuration options for result paging, including transparent background pagination. In asynchronous queries, you must explicitly fetch the next page to maintain the performance benefits of asynchronous query execution.
For more information, see the documentation for your version of the Java driver:
Node.js driver paging
The Node.js driver provides automatic paging to traverse the whole result set transparently by triggering background fetches as the iteration crosses page boundaries.
PHP driver paging
Python driver paging
The Python driver includes automatic paging to transparently traverse the entire result set by triggering background fetches as the iteration crosses page boundaries.