mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Fix comparison of similarity to threshold in GIST trigram searches.
There was some very strange code here, dating to commitb525bf77
, that purported to work around an ancient gcc bug by forcing a float4 comparison to be done as int instead. Commit5871b8848
broke that when it changed one side of the comparison to "double" but left the comparison code alone. Commitf576b17cd
doubled down on the weirdness by introducing a "volatile" marker, which had nothing to do with the actual problem. Guess that the gcc bug, even if it's still present in the wild, was triggered by comparison of float4's and can be avoided if we store the result of cnt_sml() into a double before comparing to the double "nlimit". This will at least work correctly on non-broken compilers, and it's way more readable. Per bug #14202 from Greg Navis. Add a regression test based on his example. Report: <20160620115321.5792.10766@wrigleys.postgresql.org>
This commit is contained in:
@ -296,16 +296,9 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
|
||||
|
||||
if (GIST_LEAF(entry))
|
||||
{ /* all leafs contains orig trgm */
|
||||
double tmpsml = cnt_sml(qtrg, key, *recheck);
|
||||
|
||||
/*
|
||||
* Prevent gcc optimizing the tmpsml variable using volatile
|
||||
* keyword. Otherwise comparison of nlimit and tmpsml may give
|
||||
* wrong results.
|
||||
*/
|
||||
float4 volatile tmpsml = cnt_sml(qtrg, key, *recheck);
|
||||
|
||||
/* strange bug at freebsd 5.2.1 and gcc 3.3.3 */
|
||||
res = (*(int *) &tmpsml == *(int *) &nlimit || tmpsml > nlimit);
|
||||
res = (tmpsml >= nlimit);
|
||||
}
|
||||
else if (ISALLTRUE(key))
|
||||
{ /* non-leaf contains signature */
|
||||
|
Reference in New Issue
Block a user