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 1lOvAb-0000AX-HR for pgsql-committers@arkaria.postgresql.org; Wed, 24 Mar 2021 04:31:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lOvAa-00062c-Cb for pgsql-committers@arkaria.postgresql.org; Wed, 24 Mar 2021 04:31:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOvAa-00062V-77 for pgsql-committers@lists.postgresql.org; Wed, 24 Mar 2021 04:31:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOvAT-0001Ze-Rx; Wed, 24 Mar 2021 04:30:59 +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 12O4UnTt1030302; Wed, 24 Mar 2021 00:30:49 -0400 From: Tom Lane To: Robert Haas cc: Andres Freund , Amit Kapila , Amit Kapila , pgsql-committers Subject: Re: pgsql: Add a new GUC and a reloption to enable inserts in parallel-mode In-reply-to: References: <558385.1616423602@sss.pgh.pa.us> <20210323191307.twhewx7vqj2ocglv@alap3.anarazel.de> Comments: In-reply-to Robert Haas message dated "Tue, 23 Mar 2021 16:04:59 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1030300.1616560249.1@sss.pgh.pa.us> Date: Wed, 24 Mar 2021 00:30:49 -0400 Message-ID: <1030301.1616560249@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > On Tue, Mar 23, 2021 at 3:13 PM Andres Freund wrote: >> You cache it. > Yeah, exactly. I don't think it's super-easy to understand exactly how > to make that work well for something like this. It would be easy > enough to set a flag in the relcache whose value is computed the first > time we need it and is then consulted every time after that, and you > just invalidate it based on sinval messages. But, if you go with that > design, you've got a big problem: now an insert has to lock all the > tables in the partitioning hierarchy to decide whether it can run in > parallel or not, and we do not want that. Possibly-crazy late-night idea ahead: IIUC, we need to know a global property of a partitioning hierarchy: is every trigger, CHECK constraint, etc that might be run by an INSERT parallel-safe? What we see here is that reverse-engineering that property every time we need to know it is just too expensive, even with use of our available caching methods. How about a declarative approach instead? That is, if a user would like parallelized inserts into a partitioned table, she must declare the table parallel-safe with some suitable annotation. Then, checking the property during DML is next door to free, and instead we have to think about whether and how to enforce that the marking is valid during DDL. I don't honestly see a real cheap way to enforce such a property. For instance, if someone does ALTER FUNCTION to remove a function's parallel-safe marking, we can't really run around and verify that the function is not used in any CHECK constraint. (Aside from the cost, there would be race conditions.) But maybe we don't have to enforce it exactly. It could be on the user's head that the marking is accurate. We could prevent any really bad misbehavior by having parallel workers error out if they see they've been asked to execute a non-parallel-safe function. Or there are probably other ways to slice it up. But I think some outside-the-box thinking might be helpful here. regards, tom lane