*** a/doc/src/sgml/gist.sgml --- b/doc/src/sgml/gist.sgml *************** *** 377,383 **** my_decompress(PG_FUNCTION_ARGS) Returns a value indicating the cost of inserting the new entry into a particular branch of the tree. Items will be inserted ! down the path of least penalty in the tree. --- 377,385 ---- Returns a value indicating the cost of inserting the new entry into a particular branch of the tree. Items will be inserted ! down the path of least penalty in the tree. Value ! returned by penalty should be non-negative. Negative ! values returned by penalty are treating as zero. *** a/src/backend/access/gist/gistutil.c --- b/src/backend/access/gist/gistutil.c *************** *** 526,536 **** gistpenalty(GISTSTATE *giststate, int attno, --- 526,540 ---- if (giststate->penaltyFn[attno].fn_strict == FALSE || (isNullOrig == FALSE && isNullAdd == FALSE)) + { FunctionCall3Coll(&giststate->penaltyFn[attno], giststate->supportCollation[attno], PointerGetDatum(orig), PointerGetDatum(add), PointerGetDatum(&penalty)); + if (penalty < 0.0) + penalty = 0.0; + } else if (isNullOrig && isNullAdd) penalty = 0.0; else