From 06a0783e8748433e0dc7508f84eae9c79e3bc2f0 Mon Sep 17 00:00:00 2001 From: Pavel Borisov Date: Wed, 12 May 2021 12:35:03 +0400 Subject: [PATCH v4] When there are INCLUDEd columns in SpGist check, that tuple to be inserted fits the index page, more strictly to avoid endless loop and OOM when trying to insert it. --- src/backend/access/spgist/spgdoinsert.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/access/spgist/spgdoinsert.c b/src/backend/access/spgist/spgdoinsert.c index 4d380c99f0..b6b6d3c65a 100644 --- a/src/backend/access/spgist/spgdoinsert.c +++ b/src/backend/access/spgist/spgdoinsert.c @@ -1988,8 +1988,16 @@ spgdoinsert(Relation index, SpGistState *state, /* * If it isn't gonna fit, and the opclass can't reduce the datum size by * suffixing, bail out now rather than getting into an endless loop. + * + * For indexes with INCLUDE columns we do not know whether we can reduce + * index tuple size by suffixing its key part or we will go into the + * endless loop on pick-split (in case included columns data is big enough + * to not fit into index page in an unpacked size - which is the only way + * Sp-Gist can store data of included columns). So in this case we bail + * out if leaf tuple size is greater than page capacity irrespective + * whether we can shorten its key part by suffixing. */ - if (leafSize > SPGIST_PAGE_CAPACITY && !state->config.longValuesOK) + if (leafSize > SPGIST_PAGE_CAPACITY && (!state->config.longValuesOK || leafDescriptor->natts > spgFirstIncludeColumn)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("index row size %zu exceeds maximum %zu for index \"%s\"", -- 2.24.3 (Apple Git-128)