---
title: RailQL errors and limits
description: Diagnose RailQL errors, unexpected aggregations, and missing data, and check permissions and operational limits.
---
RailQL checks syntax, types, units, and labels before running a query, then enforces limits during execution. A valid query can still produce unexpected results because of aggregation order or missing data.

<Banner variant="primary">RailQL is available through <a href="/platform/priority-boarding">Priority Boarding</a>. Breaking changes may occur.</Banner>

## Errors

RailQL reports an error with a code, a message, and the part of the query it applies to. The editor checks most errors as you type. The rest come from running the query.

| Code | Meaning |
|---|---|
| `E_SYNTAX` | The query doesn't parse |
| `E_FILTER_SYNTAX` | A filter doesn't parse, for example because of an unclosed quote or parenthesis |
| `E_FILTER_AMBIGUOUS` | A filter mixes AND and OR at one level |
| `E_FILTER_OPERATOR` | The operator doesn't fit the name, such as `>` on a text label |
| `E_FILTER_NESTED_SCOPE` | `service`, `deployment`, or `replica` on `http` is inside an `OR` or a negated group |
| `E_FREETEXT_IN_FILTER` | A message search on a source without messages |
| `E_UNKNOWN_SOURCE` | The source doesn't exist |
| `E_UNKNOWN_METRIC` | The metric doesn't exist |
| `E_UNKNOWN_LABEL`, `E_UNKNOWN_FIELD` | The source doesn't have this name |
| `E_LABEL_NOT_ON_METRIC` | The metric doesn't have this label |
| `E_UNKNOWN_VALUE` | The value isn't one the label takes, such as a service name that doesn't exist |
| `E_UNKNOWN_UNIT` | The unit doesn't exist, such as `m` for minutes |
| `E_UNIT_MISMATCH`, `E_UNIT_NOT_CONVERTIBLE` | The units don't fit together, such as bytes plus seconds |
| `E_FIELD_REQUIRED` | A rollup function needs a field |
| `E_STAGE_TYPE` | A rollup or stage doesn't fit its input |
| `E_ROLLUP_ON_COUNTER`, `E_ROLLUP_ON_LEVEL`, `E_ROLLUP_ON_HISTOGRAM` | The rollup doesn't fit the metric's kind |
| `E_SUM_OF_GAUGE` | `sum` of a Gauge |
| `E_RATE_ON_NON_COUNTER`, `E_CUMSUM_ON_NON_COUNTER` | `rate` or `cumsum` of something other than a Counter |
| `E_MERGE_ON_SCALAR` | `merge` of something other than a distribution |
| `E_EXTRACT_GROUPED` | A percentile stage with `by` |
| `E_REGROUP_NOT_SUBSET` | A stage groups by a label its input no longer has |
| `E_WINDOW_ON_STAGE` | `over` after a stage instead of on the rollup |
| `E_WITHOUT_ON_ROLLUP` | `without` on a rollup instead of a stage |
| `E_LABELS_INCOMPATIBLE` | The two sides of an arithmetic operator don't pair up |
| `E_ROWS_IN_ARITH`, `E_HIST_IN_ARITH` | An event stream or a distribution in arithmetic |
| `E_PAREN_PIPELINE` | A query with stages used in arithmetic without parentheses |
| `E_QUERY_TOO_LONG` | The query is longer than 4,096 characters |
| `E_TOO_MANY_SOURCES` | The query reads more than eight sources |
| `E_SERIES_LIMIT` | A source would return more than 50 series |
| `E_QUERY_TOO_LARGE` | A source needs too much memory or reads too many rows |
| `E_QUERY_TIMEOUT` | A source or the whole query took too long |
| `E_RANGE_BEFORE_RETENTION` | The selected range ends before the oldest available data. Choose a more recent range |
| `E_OVERLOADED` | RailQL can't run the query right now. Try again in a minute |

Warnings, with codes starting `W_`, don't stop a query. They point out queries that are probably wrong or slow, such as `W_EXPENSIVE_FILTER` for `@*`, which reads every key of every line, and `W_AGGREGATE_OF_EXTRACTION` for an average of percentiles.

## Understand aggregation order

Combining already-aggregated values can produce a different result from aggregating the original samples together. Two common mistakes are treating the sum of replica peaks as a service peak, and treating the average of endpoint averages as an overall average.

### Summing replica peaks can overstate service usage

This query takes the maximum memory usage of each replica within a step, then adds those maxima:

```railql
metric railway.memory.usage{service=api} rollup max | sum
```

If replica A peaks at 800 MiB before replica B peaks at 800 MiB, the result is 1,600 MiB even if the replicas never use that much memory at the same time. In this example, their combined usage is only 1,000 MiB at either recorded time:

<RailqlDiagram type="order" />

For a chart of average service memory usage, average each replica's samples within the step, then add the replica averages:

```railql
metric railway.memory.usage{service=api} rollup avg | sum
```

This calculates the sum of replica averages, not a peak. To inspect peaks, keep the replicas separate by omitting `| sum`. An exact combined peak requires adding simultaneous replica measurements before taking the maximum over time. `rollup max | sum` cannot calculate that: temporal aggregation runs before spatial aggregation, and each replica's maximum no longer contains the timing information needed.

### Averaging averages or percentiles gives the wrong overall value

Suppose one endpoint has one request taking 100 ms, and another has nine requests averaging 10 ms. Averaging the two endpoint averages gives 55 ms because each endpoint has equal weight. The average across all ten requests is 19 ms.

<RailqlDiagram type="average-order" />

Percentiles have the same problem: averaging endpoint p99 values doesn't produce the p99 of all requests. Once each distribution has been reduced to one percentile, the information needed to calculate the overall percentile is lost.

Keep durations as Histograms until after combining the endpoints. Use `merge` to combine their distributions, then extract the mean or percentile:

```railql
spans{service=api kind=server}
  rollup histogram(duration) by name | merge | avg
```

For the overall p99, replace `| avg` with `| p99`. If endpoint-level results aren't needed, omit `by name` and `| merge` to aggregate all matching durations into one distribution per step from the start.

## Missing data and empty results

Treating missing data as zero can make absent telemetry look like zero memory usage or a healthy service with no errors. A missing point means no value is available for that series and step. An empty result means no matching series was returned. Neither proves that the measured value was zero.

### A gap doesn't always mean zero

RailQL handles gaps according to the series kind:

| Kind | Value in a missing step of a returned series |
|---|---|
| Counter | Zero |
| Histogram | An empty distribution; its percentile is missing |
| UpDownCounter or Gauge | Missing; the previous value isn't carried forward |

If a memory series has a gap, don't interpret it as zero memory usage. Check the source and filters, selected time range, retention, and whether the service was reporting telemetry. Counter gaps become zero in the result, but the query alone still can't distinguish no activity from missing telemetry.

Similarly, `count_series` counts series with data in each step. Use it to count reporting replicas; check service or deployment status to determine whether replicas are running.

### Grouped ratios can omit series with no errors

A grouped count only returns label combinations present in the matching events. If a service has no failed requests anywhere in the range, `http{http_status>=500} rollup count by service` has no series for that service. Dividing it by `http rollup count by service` omits the service from the result, even if the denominator contains its successful requests. Zero-filling gaps in an existing Counter series doesn't create an absent series.

To diagnose a missing ratio, run the numerator and denominator separately and compare their labels. For the error ratio of one service, filter both sides to that service and use ungrouped counts:

```railql
((http{service=api http_status>=500} rollup count) /
 (http{service=api} rollup count)) | to %
```

An ungrouped count returns a zero-valued series even when no events match. This gives 0% when the service has requests but no failures, rather than dropping the service from the result.

### No requests means an undefined error ratio

Even with ungrouped counts, a step with no requests has no error ratio: dividing zero failures by zero requests is undefined. RailQL returns a missing value, not 0%.

| Requests in a step | Failed requests | Result |
|---|---|---|
| 100 | 5 | 5% |
| 100 | 0 | 0% |
| 0 | 0 | Missing |

Keep the request count alongside the error ratio to distinguish no traffic from traffic with no errors. If traffic was expected, inspect the request source and telemetry before interpreting the gap. A failed query is reported as an error separately from these successful queries with missing values or empty results.

## Limits

RailQL applies these limits by default.

| Limit | Default |
|---|---|
| Series per source | 50 |
| Sources per query | 8 |
| Query length | 4,096 characters |
| Time per query | 30 seconds |
| Time range | 90 days for metrics, your plan's log retention for events |
| Queries per workspace | 300 per minute, 16 at once |
| Event streams followed live | 5 at once per user |

A query that would return more than 50 series fails with an error that names the labels responsible and offers a fix. Group by fewer labels, or narrow the filter or the time range.

Event queries follow your plan's [log retention](/observability/logs#log-retention), with a maximum of seven days for DNS and flow events. Queries that read several sources use the shortest retention among them. If the selected range starts earlier, RailQL shortens it and reports `W_RANGE_CLAMPED`. See [Source retention](/observability/railql/data-sources#retention).

## Permissions

Reading or aggregating `logs` and `build_logs`, and listing individual `http` events, requires the Member role in the project. MCP query execution requires the Member role regardless of source. A permission error isn't an empty result: check project access before changing the query.

## Reduce cardinality

Cardinality is the number of distinct label combinations in a result. Grouping by a request path containing IDs, a trace ID, or a user ID can create many series.

Filter to a service first and group by labels with a bounded set of values, such as `http_status_class`. For instrumented spans, a normalized route attribute such as `@http.route` can group `/users/123` and `/users/456` under `/users/:id` if your instrumentation records it.

A spatial aggregation such as `| sum by service` can reduce the series read by a source when RailQL pushes it into that source. The limit also applies to intermediate source results, so a final aggregation doesn't guarantee that an otherwise oversized query will run. Use the error's suggested fix or narrow the source filter.