@@ -190,11 +190,23 @@ gin_trgm_consistent(PG_FUNCTION_ARGS)
190190if (check [i ])
191191ntrue ++ ;
192192}
193- #ifdef DIVUNION
194- res = (nkeys == ntrue ) ? true : ((((((float4 )ntrue ) / ((float4 ) (nkeys - ntrue )))) >=trgm_limit ) ? true : false);
195- #else
193+
194+ /*--------------------
195+ * If DIVUNION is defined then similarity formula is:
196+ * c / (len1 + len2 - c)
197+ * where c is number of common trigrams and it stands as ntrue in
198+ * this code. Here we don't know value of len2 but we can assume
199+ * that c (ntrue) is a lower bound of len2, so upper bound of
200+ * similarity is:
201+ * c / (len1 + c - c) => c / len1
202+ * If DIVUNION is not defined then similarity formula is:
203+ * c / max(len1, len2)
204+ * And again, c (ntrue) is a lower bound of len2, but c <= len1
205+ * just by definition and, consequently, upper bound of
206+ * similarity is just c / len1.
207+ * So, independly on DIVUNION the upper bound formula is the same.
208+ */
196209res = (nkeys == 0 ) ? false : ((((((float4 )ntrue ) / ((float4 )nkeys ))) >=trgm_limit ) ? true : false);
197- #endif
198210break ;
199211case ILikeStrategyNumber :
200212#ifndef IGNORECASE
@@ -267,11 +279,11 @@ gin_trgm_triconsistent(PG_FUNCTION_ARGS)
267279if (check [i ]!= GIN_FALSE )
268280ntrue ++ ;
269281}
270- #ifdef DIVUNION
271- res = (nkeys == ntrue ) ?GIN_MAYBE : (((((float4 )ntrue ) / ((float4 ) (nkeys - ntrue ))) >=trgm_limit ) ?GIN_MAYBE :GIN_FALSE );
272- #else
282+
283+ /*
284+ * See comment in gin_trgm_consistent() about * upper bound formula
285+ */
273286res = (nkeys == 0 ) ?GIN_FALSE : (((((float4 )ntrue ) / ((float4 )nkeys )) >=trgm_limit ) ?GIN_MAYBE :GIN_FALSE );
274- #endif
275287break ;
276288case ILikeStrategyNumber :
277289#ifndef IGNORECASE