diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c new file mode 100644 index 178f073..f2b4a17 *** a/contrib/pg_trgm/trgm_gist.c --- b/contrib/pg_trgm/trgm_gist.c *************** gtrgm_consistent(PG_FUNCTION_ARGS) *** 401,418 **** len = ARRNELEM(qtrg); trgm *ptr = GETARR(qtrg); BITVECP sign = GETSIGN(key); ! /* descend only if at least one trigram is present */ res = false; for (k = 0; k < len; k++) { CPTRGM(((char *) &tmp), ptr + k); ! if (GETBIT(sign, HASHVAL(tmp))) ! { ! res = true; ! break; ! } } } } else --- 401,424 ---- len = ARRNELEM(qtrg); trgm *ptr = GETARR(qtrg); BITVECP sign = GETSIGN(key); + bool *check; ! /* ! * trigramsMatchGraph implements monotonous boolean ! * function, i.e. false positives in "check" array can't ! * lead to false negative answer. That's why we can use ! * corresponding signature bits in the capacity of "check" ! * array. ! */ ! check = (bool *) palloc(len * sizeof(bool)); res = false; for (k = 0; k < len; k++) { CPTRGM(((char *) &tmp), ptr + k); ! check[k] = GETBIT(sign, HASHVAL(tmp)); } + res = trigramsMatchGraph(cache->graph, check); + pfree(check); } } else