Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

BigQuery Error : Resources exceeded during query execution

We are reporting an error which happened for 2 days in a row now in our BigQuery Operations.

These processes were running normal for quite some time but had starting erroring out.

We are getting following error message :

"Job scheduled_query_#### failed with error INVALID_ARGUMENT: Resources exceeded during query execution: The query could not be executed in the allotted memory. Peak usage: 133% of limit.
Top memory consumer(s):
sort operations used for analytic OVER() clauses: 99%
other/unattributed: 1%"

When we run the process afterwards manually, it seems to work but failed during scheduled operations.

Can you please help us debug this issue.

0 1 6,128
1 REPLY 1

The error message indeed suggests that the query is consuming excessive memory, primarily due to sort operations within analytic OVER() clauses. This excessive memory usage can occur when handling large datasets or when data isn't partitioned efficiently.

To mitigate this issue, consider the following strategies:

  1. Reduce Data Volume Processed:

    • Implement more stringent data filtering before applying the analytic function. This reduction can be achieved by refining WHERE clauses or by selecting only the necessary columns.
    • Consider using data sampling techniques if applicable, to process a representative subset of your data.
  2. Improve Data Partitioning:

    • Optimize the way data is partitioned. Effective partitioning can help distribute the workload more evenly across multiple workers, potentially reducing the memory load on each one.
    • Review and adjust the partition keys to ensure they align well with your query's structure and data distribution.
  3. Alter Query Approach:

    • Switch to aggregation functions where feasible. Aggregations often handle large datasets more efficiently than analytic functions, as they don't require processing all data simultaneously.
    • If the use of analytic functions is essential, consider optimizing the OVER() clause. For example, limit the window frame or partition the data more strategically within the clause.
  4. Query Optimization:

    • Examine the query execution plan to identify other potential bottlenecks or inefficiencies.
    • If you're using ORDER BY within the OVER() clause, ensure it's necessary for your analytical goals, as sorting can be resource-intensive.
  5. Monitor and Adjust Resources:

    • Monitor resource usage during query execution to better understand the memory demands.
    • If feasible, adjust the resource allocation for your BigQuery job to handle higher memory requirements.

Remember, the effectiveness of these strategies can vary based on the specifics of your dataset and query. It may require some experimentation to find the right balance between performance and resource usage.