prestodb/presto · error · PrestoException

NOT_SUPPORTED

NOT_SUPPORTED

Error message

GroupedKHyperLogLogState number of groups exceed limit %d set by khyperloglog-agg-group-limit

What it means

KHyperLogLog aggregations that group results into a GroupedKHyperLogLogState enforce a maximum number of distinct groups via the khyperloglog-agg-group-limit config. When the aggregation needs more groups than this limit, ensureCapacity throws NOT_SUPPORTED to bound memory use.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/type/khyperloglog/KHyperLogLogStateFactory.java:90

        private long size;
        private final long groupLimit;

        public GroupedKHyperLogLogState(long groupLimit)
        {
            this.groupLimit = groupLimit;
        }

        @Override
        public void setGroupId(long groupId)
        {
            this.groupId = groupId;
        }

        @Override
        public void ensureCapacity(long size)
        {
            if (groupLimit > 0 && size > groupLimit) {
                throw new PrestoException(NOT_SUPPORTED, format("GroupedKHyperLogLogState number of groups exceed limit %d set by khyperloglog-agg-group-limit", groupLimit));
            }
            khlls.ensureCapacity(size);
        }

        @Override
        public KHyperLogLog getKHLL()
        {
            return khlls.get(groupId);
        }

        @Override
        public void setKHLL(KHyperLogLog value)
        {
            if (getKHLL() != null) {
                size -= getKHLL().estimatedInMemorySize();
            }
            size += value.estimatedInMemorySize();
            khlls.set(groupId, value);

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Increase khyperloglog-agg-group-limit in the cluster configuration (or session property) to cover expected group cardinality.
  2. Reduce cardinality of the GROUP BY key (coarser buckets, bucketing, pre-aggregation).
  3. Split the query into batches or filter the input so groups stay under the limit.

Example fix

// before (config.properties)
khyperloglog-agg-group-limit=10000
// after
khyperloglog-agg-group-limit=1000000
Defensive patterns

Strategy: try-catch

Validate before calling

// Before running the query, check expected group cardinality against the limit:
long distinctGroups = execute("SELECT approx_distinct(group_col) FROM src").getLong(0);
long limit = getSessionProperty("khyperloglog-agg-group-limit");
boolean safe = distinctGroups <= limit;

Try / catch

try (QueryResult r = runQuery(khllQuery)) {
    // process results
} catch (PrestoException e) {
    if (e.getErrorCode() == NOT_SUPPORTED.toErrorCode() &&
        e.getMessage().contains("khyperloglog-agg-group-limit")) {
        // raise the limit (SET SESSION khyperloglog_agg_group_limit = ...) and retry, or reduce group cardinality
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Running a KHyperLogLog aggregate (khyperloglog_agg) with GROUP BY where the number of distinct group keys exceeds the configured khyperloglog-agg-group-limit at runtime.

Common situations: High-cardinality grouping columns (user IDs, URLs) with a cluster configured with a small conservative group limit; queries that worked on samples but explode on full data.

Understand the failure class

Background: Presto NOT_SUPPORTED error: what "not supported" means and how to fix it — this error's family across 3 libraries.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/dd545acf98eee57c. Report an issue: GitHub.