Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAbVI-0005MF-9b for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Sep 2019 15:04:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iAbVH-0007VL-4E for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Sep 2019 15:04:23 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAbVG-0007V3-Qt for pgsql-hackers@lists.postgresql.org; Wed, 18 Sep 2019 15:04:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAbVA-00047s-Gi for pgsql-hackers@lists.postgresql.org; Wed, 18 Sep 2019 15:04:22 +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 x8IF4Dt0025977; Wed, 18 Sep 2019 11:04:13 -0400 From: Tom Lane To: Peter Eisentraut cc: pgsql-hackers@lists.postgresql.org Subject: Re: Nondeterministic collations vs. text_pattern_ops In-reply-to: References: <22566.1568675619@sss.pgh.pa.us> <57e4d38e-eb2c-9a77-5a7c-b94396187cf9@2ndquadrant.com> <3615.1568733452@sss.pgh.pa.us> Comments: In-reply-to Peter Eisentraut message dated "Wed, 18 Sep 2019 14:31:39 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25975.1568819053.1@sss.pgh.pa.us> Date: Wed, 18 Sep 2019 11:04:13 -0400 Message-ID: <25976.1568819053@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Eisentraut writes: > Here is a draft patch. > It will require a catversion change because those operator classes don't > have assigned OIDs so far. That's slightly annoying given where we are with v12. We could avoid it by looking up the opclass's opfamily and seeing if it's TEXT_BTREE_FAM_OID etc, which do already have hand-assigned OIDs. But maybe avoiding a catversion bump now is not worth the cost of an extra syscache lookup. (It'd give me an excuse to shove the leakproofness-marking changes from the other thread into v12, so there's that.) Speaking of extra syscache lookups, I don't like that you rearranged the if-test to check nondeterminism before the opclass identity checks. That's usually going to be a wasted lookup. > The comment block I just moved over for the time being. It should > probably be rephrased a bit. Indeed. Maybe like * text_pattern_ops uses text_eq as the equality operator, which is * fine as long as the collation is deterministic; text_eq then * reduces to bitwise equality and so it is semantically compatible * with the other operators and functions in the opclass. But with a * nondeterministic collation, text_eq could yield results that are * incompatible with the actual behavior of the index (which is * determined by the opclass's comparison function). We prevent * such problems by refusing creation of an index with this opclass * and a nondeterministic collation. * * The same applies to varchar_pattern_ops and bpchar_pattern_ops. * If we find more cases, we might decide to create a real mechanism * for marking opclasses as incompatible with nondeterminism; but * for now, this small hack suffices. * * Another solution is to use a special operator, not text_eq, as the * equality opclass member, but that is undesirable because it would * prevent index usage in many queries that work fine today. regards, tom lane