Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwEBy-0003KI-33 for pgsql-general@arkaria.postgresql.org; Mon, 04 Jan 2021 00:57:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kwEBu-0005kp-Nj for pgsql-general@arkaria.postgresql.org; Mon, 04 Jan 2021 00:57:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwEBu-0005ki-GA for pgsql-general@lists.postgresql.org; Mon, 04 Jan 2021 00:57:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwEBq-0006UK-QQ for pgsql-general@postgresql.org; Mon, 04 Jan 2021 00:57:44 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1040vdBb2765999; Sun, 3 Jan 2021 19:57:39 -0500 From: Tom Lane To: Jack Orenstein cc: pgsql-general@postgresql.org Subject: Re: Crashing on insert to GIN index In-reply-to: References: Comments: In-reply-to Jack Orenstein message dated "Sun, 03 Jan 2021 15:37:45 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2765997.1609721859.1@sss.pgh.pa.us> Date: Sun, 03 Jan 2021 19:57:39 -0500 Message-ID: <2765998.1609721859@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jack Orenstein writes: > I am defining a new type, FooBar, and trying to create a GIN index for it. > Everything is working well without the index. FooBar values are getting > into a table, and being retrieved and selected correctly. But I'm getting a > crash when I add a GIN index on a column of type FooBar. > Here is the operator class: > create operator class foobar_ops > default for type foobar using gin > as > operator 1 @@, > function 1 foobar_cmp(bigint, bigint), > function 2 foobar_item_to_keys(foobar, internal), > function 3 foobar_query_to_keys(foobar, internal, int2, internal, > internal), > function 4 foobar_match(internal, int2, anyelement, int4, internal, > internal), > function 5 foobar_partial_match(foobar, foobar, int2, internal); Hmm, don't you want a "STORAGE bigint" clause in there? > And the implementation: > int64_t* keys = (int64_t*) palloc(sizeof(int64_t)); As a general rule, ignoring the conventions about how to use Datums is a good way to cause yourself pain. It doesn't look like what you've shown us so far is directly broken ... as long as you don't try to run it on 32-bit hardware ... but bugs could easily be lurking nearby. More, the fact that this code looks nothing like standard coding for the task is not making your life easier, because you can't easily compare what you've done to other functions. It'd be much wiser to write this as Datum *keys = (Datum *) palloc(sizeof(Datum) * whatever); and then use Int64GetDatum() to convert your integer key values to Datums. Yes, I'm well aware that that macro is physically a no-op (... on 64-bit hardware ...) but you're best advised to not rely on that, but think of Datum as a physically distinct type. regards, tom lane