diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c index f52867df324..7c0a2d43446 100644 --- a/contrib/pg_trgm/trgm_gist.c +++ b/contrib/pg_trgm/trgm_gist.c @@ -774,7 +774,7 @@ Datum gtrgm_picksplit(PG_FUNCTION_ARGS) { GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); - OffsetNumber maxoff = entryvec->n - 2; + OffsetNumber maxoff = entryvec->n - 1; GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); OffsetNumber k, j; @@ -797,7 +797,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS) SPLITCOST *costvector; /* cache the sign data for each existing item */ - cache = (CACHESIGN *) palloc(sizeof(CACHESIGN) * (maxoff + 2)); + cache = (CACHESIGN *) palloc(sizeof(CACHESIGN) * (maxoff + 1)); for (k = FirstOffsetNumber; k <= maxoff; k = OffsetNumberNext(k)) fillcache(&cache[k], GETENTRY(entryvec, k)); @@ -824,7 +824,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS) } /* initialize the result vectors */ - nbytes = (maxoff + 2) * sizeof(OffsetNumber); + nbytes = maxoff * sizeof(OffsetNumber); v->spl_left = left = (OffsetNumber *) palloc(nbytes); v->spl_right = right = (OffsetNumber *) palloc(nbytes); v->spl_nleft = 0; @@ -860,8 +860,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS) union_l = GETSIGN(datum_l); union_r = GETSIGN(datum_r); - maxoff = OffsetNumberNext(maxoff); - fillcache(&cache[maxoff], GETENTRY(entryvec, maxoff)); + /* sort before ... */ costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff); for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) @@ -947,7 +946,6 @@ gtrgm_picksplit(PG_FUNCTION_ARGS) } } - *right = *left = FirstOffsetNumber; v->spl_ldatum = PointerGetDatum(datum_l); v->spl_rdatum = PointerGetDatum(datum_r);