Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ch4mM-0004U1-Mu for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Feb 2017 01:34:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ch4mM-0008Fy-2F for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Feb 2017 01:34:38 +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.84_2) (envelope-from ) id 1ch4mL-0008Fr-8l for pgsql-hackers@postgresql.org; Fri, 24 Feb 2017 01:34:37 +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.84_2) (envelope-from ) id 1ch4mE-00084X-TU for pgsql-hackers@postgresql.org; Fri, 24 Feb 2017 01:34:36 +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 v1O1YRGr025227; Thu, 23 Feb 2017 20:34:27 -0500 From: Tom Lane To: Andrew Dunstan cc: PostgreSQL-development Subject: Re: btree_gin and btree_gist for enums In-reply-to: <3b969375-dcb5-aa73-b8e9-cacd5c8d60ef@2ndQuadrant.com> References: <56EA8A71.8060107@dunslane.net> <56EACB8C.1040406@dunslane.net> <03f7d748-0f89-e8e1-094d-f04e1026b93d@dunslane.net> <27220.1478360811@sss.pgh.pa.us> <31412.1478366009@sss.pgh.pa.us> <60fb708c-8b3c-1337-934e-c1bfe2afc539@dunslane.net> <8258.1487886101@sss.pgh.pa.us> <3b969375-dcb5-aa73-b8e9-cacd5c8d60ef@2ndQuadrant.com> Comments: In-reply-to Andrew Dunstan message dated "Thu, 23 Feb 2017 16:45:00 -0500" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <25088.1487899876.0@sss.pgh.pa.us> Date: Thu, 23 Feb 2017 20:34:27 -0500 Message-ID: <25226.1487900067@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25088.1487899876.1@sss.pgh.pa.us> Andrew Dunstan writes: > On 02/23/2017 04:41 PM, Tom Lane wrote: >> BTW, while I'm looking at this ... isn't gin_enum_cmp broken on its face? > Yes, that's what I'm trying to fix. I'd forgotten where this thread started. For a minute there I thought we had a live bug, rather than a deficiency in code-under-development. After thinking about that, I believe that enum_cmp_internal is a rather considerable hazard. It might not be our only function that requires fcinfo->flinfo cache space just some of the time not all the time, but I don't recall anyplace else that could so easily undergo a reasonable amount of testing without *ever* reaching the case where it requires that cache space. So I'm now worried that it wouldn't be too hard for such a bug to get past us. I think we should address that by adding a non-bypassable Assert that the caller did provide flinfo, as in the attached. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="assert-that-enum-comparator-can-use-cache.patch"; charset="us-ascii" Content-ID: <25088.1487899876.2@sss.pgh.pa.us> Content-Description: assert-that-enum-comparator-can-use-cache.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/utils/adt/enum.c b/src/backend/utils/adt/enum.c index 8110ee2..b1d2a6f 100644 *** a/src/backend/utils/adt/enum.c --- b/src/backend/utils/adt/enum.c *************** enum_cmp_internal(Oid arg1, Oid arg2, Fu *** 263,268 **** --- 263,277 ---- { TypeCacheEntry *tcache; =20=20 + /* + * We don't need the typcache except in the hopefully-uncommon case that + * one or both Oids are odd. This means that cursory testing of code th= at + * fails to pass flinfo to an enum comparison function might not disclose + * the oversight. To make such errors more obvious, Assert that we have= a + * place to cache even when we take a fast-path exit. + */ + Assert(fcinfo->flinfo !=3D NULL); +=20 /* Equal OIDs are equal no matter what */ if (arg1 =3D=3D arg2) return 0; *************** enum_cmp(PG_FUNCTION_ARGS) *** 381,392 **** Oid a =3D PG_GETARG_OID(0); Oid b =3D PG_GETARG_OID(1); =20=20 ! if (a =3D=3D b) ! PG_RETURN_INT32(0); ! else if (enum_cmp_internal(a, b, fcinfo) > 0) ! PG_RETURN_INT32(1); ! else ! PG_RETURN_INT32(-1); } =20=20 /* Enum programming support functions */ --- 390,396 ---- Oid a =3D PG_GETARG_OID(0); Oid b =3D PG_GETARG_OID(1); =20=20 ! PG_RETURN_INT32(enum_cmp_internal(a, b, fcinfo)); } =20=20 /* Enum programming support functions */ ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers ------- =_aaaaaaaaaa0--