{"record":{"id":"53e6185e51961367","repo":"prestodb/presto","slug":"generic-insufficient-resources-53e618","errorCode":"GENERIC_INSUFFICIENT_RESOURCES","errorMessage":"Size of hash table cannot exceed 2147483647 entries (%s)","messagePattern":"Size of hash table cannot exceed 2147483647 entries \\((.+?)\\)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/histogram/GroupedTypedHistogram.java","lineNumber":288,"sourceCode":"    private void iterateGroupNodes(long groupId, NodeReader nodeReader)\n    {\n        // while the index can be a long, the value is always an int\n        int currentPointer = (int) headPointers.get(groupId);\n        checkArgument(currentPointer != NULL, \"valid group must have non-null head pointer\");\n\n        while (currentPointer != NULL) {\n            checkState(currentPointer < nextNodePointer, \"error, corrupt pointer; max valid %s, found %s\", nextNodePointer, currentPointer);\n            nodeReader.read(currentPointer);\n            currentPointer = nextPointers.get(currentPointer);\n        }\n    }\n\n    private void rehash()\n    {\n        long newBucketCountLong = bucketCount * 2L;\n\n        if (newBucketCountLong > Integer.MAX_VALUE) {\n            throw new PrestoException(GENERIC_INSUFFICIENT_RESOURCES, \"Size of hash table cannot exceed \" + Integer.MAX_VALUE + \" entries (\" + newBucketCountLong + \")\");\n        }\n\n        int newBucketCount = computeBucketCount((int) newBucketCountLong, MAX_FILL_RATIO);\n        int newMask = newBucketCount - 1;\n        IntBigArray newBuckets = new IntBigArray(-1);\n        newBuckets.ensureCapacity(newBucketCount);\n\n        for (int i = 0; i < nextNodePointer; i++) {\n            // find the old one\n            int bucketId = getBucketIdForNode(i, newMask);\n            int probeCount = 1;\n\n            int originalBucket = bucketId;\n            // find new one\n            while (newBuckets.get(bucketId) != -1) {\n                int probe = nextProbe(probeCount);\n                bucketId = nextBucketId(originalBucket, newMask, probe);\n                probeCount++;","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/aggregation/histogram/GroupedTypedHistogram.java#L270-L306","documentation":"GroupedTypedHistogram implements the histogram aggregation's key set as an open-addressing hash table backed by int bucket arrays. When the table doubles on rehash, the new bucket count must fit in a signed int; exceeding Integer.MAX_VALUE entries cannot be represented, so Presto throws GENERIC_INSUFFICIENT_RESOURCES instead of overflowing.","triggerScenarios":"A histogram(x) aggregation accumulating so many distinct key values that the internal hash table's bucket count doubled beyond Integer.MAX_VALUE — i.e. billions of distinct keys in one group.","commonSituations":"Histogramming a high-cardinality column (ids, timestamps, free text) in a single group; a forgotten GROUP BY so all rows land in one histogram; runaway distinct values from bad joins or data corruption.","solutions":["Reduce input cardinality: group more finely, or bucket/round keys before histogram(x).","Use a different summary (approx_distinct, TopN via histogram over cast keys) for very high cardinality.","Pre-aggregate upstream so a single histogram never sees billions of distinct keys."],"exampleFix":"// before\nSELECT histogram(user_id) FROM events; -- billions of distinct ids\n// after\nSELECT histogram(date_trunc('hour', ts)) FROM events; -- or GROUP BY region first","handlingStrategy":"validation","validationCode":"-- bound key cardinality before histogram\nSELECT approx_distinct(key) FROM t GROUP BY group_key ORDER BY 1 DESC LIMIT 1; -- if near billions, do not use histogram","typeGuard":null,"tryCatchPattern":"try { result = query(...); } catch (PrestoException e) { if (e.getErrorCode().getName().equals(\"GENERIC_INSUFFICIENT_RESOURCES\")) { /* fall back to lower-cardinality keys */ } else { throw e; } }","preventionTips":["Always GROUP BY so histograms stay per-group and small","Pre-bucket high-cardinality keys (date_trunc, width_bucket, substr)","Monitor distinct-count estimates before choosing histogram"],"tags":["presto","aggregation","histogram","resource-limit"],"backgroundTag":"result-size-limit-exceeded","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}