Request a demo

BigQuery error · Resources and limits

Not enough resources for query planning

After BigQuery expanded every view, WITH clause and SQL UDF, the query plan was too big to build. Split the query: materialize intermediate results in temporary tables inside a script, and cut repeated CTEs, deeply nested views and long UNION ALL chains.

Error reason resourcesExceeded · HTTP 400 · Checked against the Google Cloud docs in November 2026

The error message

Resources exceeded during query execution: Not enough resources for query planning - too many subqueries or query is too complex.

Causes

CTEs referenced many times

A WITH clause is not a stored result. Each reference to a CTE can be expanded and planned again, so a CTE used in five places, each using another CTE, grows the plan multiplicatively.

Deeply nested or repeated views

Views are expanded into the query text before planning. A view stack that is a few layers deep, where each layer joins the layer below several times, produces a plan far bigger than the SQL you see.

Long UNION ALL chains and generated SQL

Queries generated by a tool or macro that union hundreds of tables or repeat a large CASE per column hit the planning limit. The message has variants: too many fields accessed or query is too complex, query is too complex, and The query is too complex.

Very wide tables and complex SQL UDFs

Accessing thousands of columns, or calling SQL UDFs whose bodies expand into large expressions on every row reference, adds to the plan size.

How to fix it

1. Materialize repeated steps in temporary tables

In a multi-statement query, compute a heavy step once into a temp table and read it from the later statements. Each statement is planned separately, so none of them hits the limit.

CREATE TEMP TABLE daily_revenue AS
SELECT order_date, customer_id, SUM(amount) AS revenue
FROM `project.dataset.orders`
WHERE order_date >= '2026-11-01'
GROUP BY order_date, customer_id;

SELECT d.order_date, c.segment, SUM(d.revenue) AS revenue
FROM daily_revenue AS d
JOIN `project.dataset.customers` AS c USING (customer_id)
GROUP BY d.order_date, c.segment;

2. Flatten the view stack

Replace the lowest, most reused views with tables refreshed on a schedule or with materialized views, so the layers above read stored data instead of re-expanding SQL.

3. Replace UNION ALL over many tables with a wildcard table or one partitioned table

Date-sharded tables such as events_20261101, events_20261102 can be read with one wildcard reference and a _TABLE_SUFFIX filter instead of a union of every shard.

SELECT event_name, COUNT(*) AS events
FROM `project.dataset.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20261101' AND '20261122'
GROUP BY event_name;

4. Split the query into steps

Run independent parts as separate statements, for example one per metric, and join the small results at the end.

How to prevent it

  • Watch query_info.resource_warning in INFORMATION_SCHEMA.JOBS: BigQuery records a warning for queries that are getting close to the limit, before they fail.
  • Keep view nesting shallow and avoid views that reference the same base view several times.
  • Review generated SQL from BI tools and dbt macros for unions and repeated expressions that grow with the number of tables or columns.

FAQ

Is a query that is too complex billed?

On-demand, no: queries that return an error aren't charged. Planning failures happen before execution, so there is usually little or no slot time spent under editions either, but a scheduled query that keeps failing means the data downstream isn't refreshed.

Do CTEs in BigQuery get computed once?

Not necessarily. BigQuery may evaluate a non-recursive CTE each time it is referenced. Use a temporary table when the same intermediate result is read several times.

Will more slots fix a query planning error?

No. The limit is on the size of the query plan, not on execution capacity. Only a simpler query, or several smaller ones, fixes it.

SQL reference

More resources and limits

All BigQuery error messages · What 50M daily events say about BigQuery failures

Stop finding BigQuery failures in Slack threads

Masthead watches every BigQuery job, dbt model, Dataform action and Airflow task from audit logs, groups failures into incidents and shows which tables and dashboards are affected. No access to your data and no added BigQuery cost.