Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit25bfa7e

Browse files
committed
Improve the gin index scan performance in pg_trgm.
Previous coding assumes too pessimistic upper bound of similarityin consistent method of GIN.Author: Fornaroli Christophe with comments by me.
1 parenta9246fb commit25bfa7e

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

‎contrib/pg_trgm/trgm_gin.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,23 @@ gin_trgm_consistent(PG_FUNCTION_ARGS)
190190
if (check[i])
191191
ntrue++;
192192
}
193-
#ifdefDIVUNION
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+
*/
196209
res= (nkeys==0) ? false : ((((((float4)ntrue) / ((float4)nkeys))) >=trgm_limit) ? true : false);
197-
#endif
198210
break;
199211
caseILikeStrategyNumber:
200212
#ifndefIGNORECASE
@@ -267,11 +279,11 @@ gin_trgm_triconsistent(PG_FUNCTION_ARGS)
267279
if (check[i]!=GIN_FALSE)
268280
ntrue++;
269281
}
270-
#ifdefDIVUNION
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+
*/
273286
res= (nkeys==0) ?GIN_FALSE : (((((float4)ntrue) / ((float4)nkeys)) >=trgm_limit) ?GIN_MAYBE :GIN_FALSE);
274-
#endif
275287
break;
276288
caseILikeStrategyNumber:
277289
#ifndefIGNORECASE

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp