At a glance
- First API call:
POST /query/sql?getCursor=true&numRows=Nruns the query and returns page 1 plus arequestId,brokerHostandbrokerPort. - Subsequent calls:
GET /responseStore/{requestId}/results?offset=X&numRows=Nreturns any page you ask for. Through the StarTree proxy, also send theFORWARD_HOSTandFORWARD_PORTheaders. - Cleanup: stored results expire and are deleted automatically.
Overview
Without cursors, paging through a large result usually means sending the same query again and again with a differentLIMIT and OFFSET. Each of those calls makes Pinot do the full query work again. With cursors, the broker runs the query one time, saves the full result, and hands you pages of it on request.
Use cursor pagination when:
- A query returns more rows than you want to send to a client in one response.
- You are building a UI with “next page” or “load more” controls.
- You are exporting or processing a large result in batches.
- You want every page to come from the same snapshot of results.
How it works
The broker runs your query once, saves the whole result in its response store, and then serves pages from that saved copy. Servers are only involved in the first API call. On StarTree Cloud, calls go through the StarTree proxy, which forwards follow-up calls to the broker named in theFORWARD_HOST and FORWARD_PORT headers.
- Your app sends the query with
getCursor=true. The broker runs it on the servers like any other query. - The broker saves the full result to its response store and gives it an ID (
requestId). - The broker returns the first page, the
requestId, the total row count, and its own address inbrokerHostandbrokerPort. - For each later page, your app asks the same broker for rows starting at an
offset. The broker reads them from the stored result. The query is not run again. - After the expiration time, the broker deletes the stored result automatically.
Prerequisites
Cursor pagination must be enabled on your environment’s brokers. Ask StarTree Support to enable it. Support can also tune the page size and how long stored results are kept. See Broker configuration for the settings involved and Sizing and tuning for how to choose values.How expiration and the cleaner work together. A stored result expires after the
expiration time, and the cleaner deletes expired results on its next run. For example, with a 15-minute expiration and a cleaner that runs every 10 minutes, a result is removed between 15 and 25 minutes after the query. Ask for an expiration longer than your clients need to page through a result.Paging through results
A first API call opens the cursor, and subsequent calls fetch the remaining pages. In all examples, replacexxx.startree.cloud with your broker URL, and <YOUR_TOKEN>, <your_table>, <REQUEST_ID>, <BROKER_HOST> and <BROKER_PORT> with your own values.
The examples use a result of 17 rows read with a page size of 10. Page 1 returns rows 0 to 9 and page 2 returns the remaining 7.
Run the query and open a cursor
Send the query withPOST /query/sql, adding getCursor=true and your page size numRows as URL parameters. Put the SQL in the JSON body as usual.
resultTable, plus the cursor fields:
A first-page response with a page size of 3 looks like this (trimmed):
Fetch the next pages
CallGET /responseStore/{requestId}/results with the offset of the first row you want and the page size in numRows. Through the StarTree proxy, add the FORWARD_HOST and FORWARD_PORT headers with the brokerHost and brokerPort values from the first response.
offset by your page size each time (0, 10, 20, …) until offset reaches numRowsResultSet. The last page may hold fewer rows than you asked for, and its numRows field shows the actual count.
Reach the right broker
The stored result lives only on the broker that ran the query. Other brokers do not have it. Use one of these two options for every follow-up call:- Call the same broker directly: send every page fetch to the broker named in
brokerHostandbrokerPortin the first response. - Use the StarTree proxy URL with forward headers: send the call to the proxy broker URL with
FORWARD_HOST: <brokerHost>andFORWARD_PORT: <brokerPort>. The proxy forwards the call to exactly that broker.
/responseStore call:
Sending only
FORWARD_HOST fails with this error:
Use the values exactly as returned. The proxy does not check
FORWARD_HOST against its broker list; it forwards to whatever address you send. Copy brokerHost and brokerPort from the first response. brokerHost is usually an internal cluster hostname. That is expected, because the proxy resolves it inside the cluster.Stop at the total
Anoffset equal to or larger than numRowsResultSet returns an error, not an empty page. With 17 stored rows, valid offsets are 0 to 16.
offset=17, because it equals the total, and the broker returns it as an HTTP 500 error. Stop paging once offset reaches numRowsResultSet. An offset inside the range with a large numRows is fine: it simply returns the rows that are left.
Clean up (optional)
Stored results are deleted automatically after they expire. To free the space right away when you are done, delete the cursor. Through the proxy, this call also needs the forward headers.Parameters
There are two kinds of settings: request parameters and headers you send with each call, and broker configuration that sets the page size and storage behavior.Request parameters and headers
Broker configuration
These are the cursor settings a broker reads. To change any of them, contact StarTree Support.
Durations accept the units
d, h, m and s, and combinations such as 1h30m.
With the defaults, a stored result can stay on disk for up to 2 hours (expiration plus one cleaner cycle).
Good to know
- Stay on the same broker. Always fetch pages from the broker that ran the query: either call the broker in
brokerHostdirectly, or call the StarTree proxy URL with bothFORWARD_HOSTandFORWARD_PORTheaders. The proxy does not track which broker owns arequestId, so without these headers a call can land on a different broker and fail with “not found”. - Results expire. A stored result lives for the
expirationtime, and may stay up to one more cleaner cycle before it is deleted. After that, run the query again to get a new cursor. - Check broker disk size. If your cursor QPS is very high, check the broker disk size. Stored results stay on the broker’s disk until they expire, so a high volume of cursor queries could fill the disk. See Estimate broker disk.
- Pick a sensible page size. Each page fetch re-reads the stored result, so very small pages over a very large result are slower. Pages of hundreds or thousands of rows work better than pages of 10.
- The query still runs in full. Cursors page the delivery of results, not the query itself. The query’s
LIMITand the broker’s memory limits still apply, and only read (SELECT) queries can open a cursor. - Results are a snapshot. Every page comes from the result saved when the query ran, so new data ingested later does not appear until you run the query again.
Sizing and tuning
Estimate broker disk
Each cursor query writes its full result to the disk of the broker that ran it. A result can stay on disk for up toexpiration + cleaner.frequencyPeriod before it is deleted.
bytesWritten on real queries rather than estimating it.
Choose expiration and cleaner period
expiration(E): set it to the longest time a client needs to page through one result (p99), plus a margin. A paging session that outlives E fails with “not found”.cleaner.frequencyPeriod(C): keep it small next to E, about E/3 to E/2. The worst-case lifetime of a result is E + C, so a smaller C keeps disk use close to the estimate. A cleaner run only scans and deletes expired results, so running it often is cheap.- The defaults (
1h/1h) keep results up to 2 hours, which uses about 4–5× more disk than15m/10mat the same query rate.
How many cursor queries a broker can handle
There is no fixed cursor-specific QPS limit. Capacity depends on four things:- Query capacity: every first call (
getCursor=true) is a full query, so normal broker and server capacity and table query quotas apply. - Disk: use the estimate in Estimate broker disk.
- Broker memory: the broker builds and writes the whole result before it returns page 1. Many large results at once put pressure on broker heap.
- Page-fetch load: page fetches read from the stored files, so many fetches over large results cost broker CPU and disk I/O.
Test at peak QPS and watch the brokers. Run the load test at your peak cursor QPS, including expected bursts, with realistic result sizes and paging patterns. During the test, monitor every broker and confirm it stays stable:
- CPU: no sustained saturation; usage settles at a steady level.
- Memory: JVM heap does not keep growing, no long or frequent GC pauses, no out-of-memory errors.
- Disk: response-store usage levels off once the cleaner starts deleting expired results.
- Latency: first-call and page-fetch latency stay within your targets.

