* of size BLCKSZ. Rather than assuming we know the exact amount of overhead
* imposed by page headers, tuple headers, etc, we leave 100 bytes for that
* (the actual overhead should be no more than 56 bytes at this writing, so
- * there is slop in this number). The upshot is that the maximum safe prefix
- * length is this:
+ * there is slop in this number). So we can safely create prefixes up to
+ * BLCKSZ - 256 * 16 - 100 bytes long. Unfortunately, because 256 * 16 is
+ * already 4K, there is no safe prefix length when BLCKSZ is less than 8K;
+ * it is always possible to get "SPGiST inner tuple size exceeds maximum"
+ * if there are too many distinct next-byte values at a given place in the
+ * tree. Since use of nonstandard block sizes appears to be negligible in
+ * the field, we just live with that fact for now, choosing a max prefix
+ * size of 32 bytes when BLCKSZ is configured smaller than default.
*/
-#define SPGIST_MAX_PREFIX_LENGTH (BLCKSZ - 256 * 16 - 100)
+#define SPGIST_MAX_PREFIX_LENGTH Max((int) (BLCKSZ - 256 * 16 - 100), 32)
/* Struct for sorting values in picksplit */
typedef struct spgNodePtr