Pagination

ArcadeDB supports pagination natively. Pagination doesn’t consume server side resources because no cursors are used. Only Record ID’s are used as pointers to the physical position in the bucket.

There are 2 ways to achieve pagination:

Use the SKIP-LIMIT

The first and simpler way to do pagination is to use the SKIP/LIMIT approach. This is the slower way because ArcadeDB repeats the query and just skips the first X records from the result. Syntax:

SELECT FROM <target> [WHERE ...] SKIP <records-to-skip> LIMIT <max-records>

Where: - records-to-skip is the number of records to skip before starting to collect them as the result set. It cannot be negative: since v26.12.1 a negative value raises a CommandExecutionException (Cannot execute a query with a negative SKIP), where earlier versions ran the query as SKIP 0 and returned the first page again - max-records is the maximum number of records returned by the query

Since v26.12.1, when the query reads an index in key order (an ORDER BY on the indexed property, with or without a range on it in the WHERE) and nothing between the index and the SKIP needs the record (no other WHERE condition, DISTINCT, GROUP BY, expand(), UNWIND or LET), the skipped rows are counted from the index entries without loading their records, and the projections are not computed for them. SELECT id FROM P WHERE id >= 0 ORDER BY id SKIP 50000 LIMIT 10 therefore no longer loads 50,000 records to throw them away. The rows returned are the same, records of a type with a read trigger or read event listener are still loaded, and a user who may not read a skipped record still gets the same security error. The index entries are still walked one by one, so a WHERE on the last key read (WHERE id > <last-id> ORDER BY id LIMIT <max-records>) stays faster for deep pages.

Use the RID-LIMIT

This method is faster than the SKIP-LIMIT because ArcadeDB will begin the scan from the starting RID. ArcadeDB can seek the first record in about O(1) time. The downside is that it’s more complex to use.

The trick here is to execute the query multiple times setting the LIMIT as the page size and using the greater than > operator against @rid. The lower-rid is the starting point to search, for example #10:300.

Syntax:

SELECT FROM <target> WHERE @rid > <lower-rid> ... [LIMIT <max-records>]

Where: - lower-rid is the exclusive lower bound of the range as RID - max-records is the maximum number of records returned by the query

In this way, ArcadeDB will start to scan the bucket from the given position lower-rid + 1. After the first call, the lower-rid will be the rid of the last record returned by the previous call. To scan the cluster from the beginning, use #-1:-1 as lower-rid .