Re: Wrong Results from SP-GiST with Collations
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Geoghegan <pg@bowt.ie>
Cc: Emre Hasegeli <emre@hasegeli.com>, Teodor Sigaev <teodor@sigaev.ru>,
PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Date: 2018-04-16T18:51:06Z
Lists: pgsql-bugs
Peter Geoghegan <pg@bowt.ie> writes:
> Has the operator class really been completely broken since SP-GiST was
> first introduced? I tend to doubt that. spg_text_inner_consistent()
> has the following code, which appears to acknowledge the problem with
> non-C collations:
You're on to something, but I think the bug is in
spg_text_leaf_consistent, which thinks it can do collation-aware
comparisons like this:
r = varstr_cmp(fullValue, Min(queryLen, fullLen),
VARDATA_ANY(query), Min(queryLen, fullLen),
PG_GET_COLLATION());
That's got nothing to do with reality for non-C collations, and it seems
rather pointless anyway, Why isn't this just
r = varstr_cmp(fullValue, fullLen,
VARDATA_ANY(query), queryLen,
PG_GET_COLLATION());
and then the bit below about
if (r == 0)
{
if (queryLen > fullLen)
r = -1;
else if (queryLen < fullLen)
r = 1;
}
needs to move into the "non-collation-aware" branch.
regards, tom lane
Commits
-
Fix broken collation-aware searches in SP-GiST text opclass.
- b15e8f71dbf0 11.0 landed
- d90b2904c711 9.6.9 landed
- cf73a5b34a90 9.3.23 landed
- 93053aca5400 9.5.13 landed
- 608d1f97114d 9.4.18 landed
- 3397c67272e2 10.4 landed
-
Add prefix operator for TEXT type.
- 710d90da1fd8 11.0 cited