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 1lhZcL-0006gg-12 for pgsql-bugs@arkaria.postgresql.org; Fri, 14 May 2021 15:20:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lhZcJ-0001zn-NA for pgsql-bugs@arkaria.postgresql.org; Fri, 14 May 2021 15:20:43 +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 1lhZcJ-0001zf-Ge for pgsql-bugs@lists.postgresql.org; Fri, 14 May 2021 15:20:43 +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 1lhZcH-0003HT-Ep for pgsql-bugs@lists.postgresql.org; Fri, 14 May 2021 15:20:43 +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 14EFKZNo1885029; Fri, 14 May 2021 11:20:36 -0400 From: Tom Lane To: Eric Thinnes cc: Bharath Rupireddy , pgsql-bugs@lists.postgresql.org Subject: Re: Segmentation fault when calling BlessTupleDesc in a C function in parallel on PostgreSQL-(12.6, 12.7, 13.2, 13.3) In-reply-to: <105daf69-a864-2e83-1f93-a85e4ba80510@gmx.de> References: <99aaa2eb-e194-bf07-c29a-1a76b4f2bcf9@gmx.de> <105daf69-a864-2e83-1f93-a85e4ba80510@gmx.de> Comments: In-reply-to Eric Thinnes message dated "Fri, 14 May 2021 14:26:52 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1885027.1621005635.1@sss.pgh.pa.us> Date: Fri, 14 May 2021 11:20:35 -0400 Message-ID: <1885028.1621005635@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Eric Thinnes writes: > The function always delivers the same result with the same call > parameters except for the determination of the result types and the > generation of the TupleDesc, the function has no side effects. BlessTupleDesc certainly has side effects; that's pretty much the whole point of it. If you're marking this thing as parallel safe, I imagine that the problem boils down to "parallel worker locally registers a blessed tupdesc, but the leader has never heard of it, so fails to interpret the returned tuple". Perhaps a workaround is possible by using a named composite type instead of generating a rowtype on the fly? But that won't work if you want this to be polymorphic. Also, I recall that there are provisions in typcache.c in recent versions to support a shared pool of registered (i.e. blessed) tuple descriptors. That would likely solve your problem, but I've never looked into how to use that code. I doubt just calling BlessTupleDesc is enough. In particular, I imagine you need to make sure the leader process creates the tupdesc first, so it's available to all workers. regards, tom lane