Skip to content

Long ranges and limits ​

CQL samples a long range instead of reading it block by block, and a few caps keep a run from growing past what can finish.

None of this is a surprise if you know the three numbers involved. This page gives them, explains how CQL chooses a step when you do not, and lists what happens when a query is too big.

Why a range is sampled ​

from stETH at 25_800_000..26_000_000 names two hundred thousand blocks. To read the contract at each of them would take two hundred thousand calls, for a chart that nobody could read. So a state source has a budget of 10 000 rows per contract. If a range would exceed the budget, CQL samples it so that it fits.

Events are different. A Transfer that stETH emitted is a row whether you like it or not, so CQL never samples an event source. Instead, an event source has a cap on its span, below.

How the step is chosen ​

If you write every, that is the step, and CQL never adjusts it. If you do not, CQL walks the ladder 1, 2, 5, 10, 20, 50, 100, …. It takes the smallest step that keeps the source under 10 000 rows. It reports the choice in the run's diagnostics:

CQL3900 · info · Sampling every 50 blocks to stay under max_state_rows (10000)

Two things are true of any step. First, the grid is absolute. The sampled blocks are the multiples of the step inside the range, not "every k-th from the start". So two runs with the same step land on the same blocks. Second, CQL always includes the end of the range, so the newest value is always present.

Write the step yourself when the ladder's choice is not the one that you want to read. every 7200 is close to a day on Ethereum, which is once per rebase for stETH. every 1h on a time range is exactly an hour.

The caps ​

WhatCapWhen you meet it
State rows per contract10 000Never as an error — the range is sampled instead.
Rows out of any operator100 000CQL3014 before the run when it can be predicted, CQL4004 during it otherwise.
Blocks in one event source10 000 000CQL3015, before the run.
Requests in one run50 000CQL3016 before the run from an estimate, CQL4008 during it.
Result size512 MiBCQL3019 before the run when it can be predicted, CQL4009 after the order, summarize, distinct, join or union that crossed it.
Held in memory at onceabout 8 MiB in the workbenchCQL3019 before the run when it can be predicted, CQL4010 during it.
Columns out of any operator7 812CQL3021, before the run, wherever the query runs.

On a time range, "before the run" means "when the run finds the blocks of the range". CQL finds the blocks of a time range only when the run starts. So the run checks CQL3014, CQL3015, CQL3016 and CQL3019 at that time, before it reads the contract. If a cap stops it, the run fails with that code.

In the workbench, the memory that a run holds at once is the byte cap that you meet first. If a query's result would come near 512 MiB, CQL refuses the query long before that, as CQL3019 or CQL4010.

A cap that CQL can see from the query alone stops the run before CQL fetches anything. On a time range, CQL first finds the blocks of the range, and then it checks the cap. So you do not wait for a query that cannot finish. A cap that depends on the data stops the run at the operator that crossed it and names it. CQL never truncates a result silently. You get all the rows or a diagnostic, never the first 100 000 with no warning.

Making a query smaller ​

The message always suggests the fix, and it is one of three:

  • Narrow the range. latest-21600..latest instead of latest-720000..latest.
  • Sample more coarsely. every 1d instead of every 1h. stETH moves once a day, so an hourly sample of its share rate is twenty-three copies of the same value.
  • Aggregate. summarize total = sum(e.value) by day = bin($timestamp, 1d) reduces a million stETH transfers to a few hundred rows before they reach the grid.

An expand multiplies rows. For example, the staking router's four module ids sampled 5 000 times is 20 000 rows. So when you meet a cap after an expand, you can usually fix it by sampling the source that it expands.

A join or a union holds both of its sides at once. So you fix the memory cap that you meet there inside the parentheses as well as before them. Summarize or narrow each side before CQL joins it.

A join also adds every column of its right side to the left side's columns. An event brings a column for each of its arguments. So a long chain of joins over a wide event can pass the column cap (CQL3021) with no rows at all. project the columns you need on each side before CQL joins it.

See also ​