Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f89Di-0006H3-Du for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Apr 2018 18:51:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f89Dg-0006FJ-VE for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Apr 2018 18:51:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f89Dg-0006F5-Oy for pgsql-bugs@lists.postgresql.org; Mon, 16 Apr 2018 18:51:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f89Dd-0004nh-2V for pgsql-bugs@postgresql.org; Mon, 16 Apr 2018 18:51:16 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w3GIp6I0019694; Mon, 16 Apr 2018 14:51:06 -0400 From: Tom Lane To: Peter Geoghegan cc: Emre Hasegeli , Teodor Sigaev , PostgreSQL Bugs Subject: Re: Wrong Results from SP-GiST with Collations In-reply-to: References: Comments: In-reply-to Peter Geoghegan message dated "Mon, 16 Apr 2018 09:38:34 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19692.1523904666.1@sss.pgh.pa.us> Date: Mon, 16 Apr 2018 14:51:06 -0400 Message-ID: <19693.1523904666@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Geoghegan 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