Re: Wrong Results from SP-GiST with Collations - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Wrong Results from SP-GiST with Collations
Date
Msg-id 19693.1523904666@sss.pgh.pa.us
Whole thread Raw
In response to Re: Wrong Results from SP-GiST with Collations  (Peter Geoghegan <pg@bowt.ie>)
Responses Re: Wrong Results from SP-GiST with Collations
List 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


pgsql-bugs by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: BUG #15144: *** glibc detected *** postgres: postgres smsconsole[local] SELECT: double free or corruption (!pre
Next
From: Peter Geoghegan
Date:
Subject: Re: Wrong Results from SP-GiST with Collations