Understanding and Managing gp_max_slices
search cancel

Understanding and Managing gp_max_slices

book

Article ID: 430557

calendar_today

Updated On:

Products

VMware Tanzu Greenplum

Issue/Introduction

In Greenplum Database (GPDB), a slice is a subset of a query plan that can be executed independently by a segment. Whenever data needs to move between segments (a Motion), the planner creates a new slice.

 The gp_max_slices GUC is used to set the upper limit on how many slices a single query can have. The default is typically 100.

 

Environment

GPDB 6.X.X

Cause

Error Symptom:

Users will receive the following error during the query planning phase:

ERROR: 54000: at most 100 slices are allowed in a query

Note: This error often does not appear in pg_log by default because it occurs during the Planner stage, before execution begins.

 

Common Causes of "Slice Bloat"

Cause Description
Non-Aligned Joins Joining two large tables on columns that are not their distribution keys.
Deep Nesting Multiple layers of subqueries or CTEs that each require redistribution.
Large UNION ALL Combining many tables (e.g., 50+ partitions or monthly tables) where each part of the union requires a motion.
Redistribution Chains A query that transforms data, redistributes it, transforms it again, and redistributes it again.

Resolution

Troubleshooting & Resolution Steps:

 

1. Identify the Motion (The "Explain" Test)

Run EXPLAIN on the failing query. Look for the number of Send and Recv operations. Each time you see a Redistribute Motion, Broadcast Motion, or Gather Motion, you are looking at a slice boundary.

2. Immediate Fixes (Query Refactoring)

  • Temporary Tables: Break the query into two parts. Insert the results of the first half into a TEMPORARY TABLE. This "resets" the slice counter for the second half of the logic.

  • Match Distribution Keys: Ensure the columns used in JOIN clauses match the DISTRIBUTED BY clause of the physical tables. This allows for a Local Join (0 slices).

  • Materialize CTEs: In some versions, using AS MATERIALIZED in a CTE can help the planner handle the logic more efficiently.

3. Adjusting the Limit

If the query is logically sound but inherently complex (e.g., a massive report), you can increase the limit.

Session Level (Recommended):

SQL
 
SET gp_max_slices = 200;
-- Run query

System Level (Requires Reload):

gpconfig -c gp_max_slices -v 200
gpstop -u

> Warning: Increasing this globally can lead to "Out of Memory" (OOM) errors if many complex queries run simultaneously.


Related Parameters

  • gp_vmem_protect_limit: High slice counts increase the risk of hitting this memory ceiling.

  • max_statement_mem: Limits the memory a single query can pull from the vmem pool.