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 1pjgjA-0001Wa-Be for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Apr 2023 13:29:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pjgj9-0004vl-2b for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Apr 2023 13:29:35 +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 1pjgj8-0004vb-J3 for pgsql-hackers@lists.postgresql.org; Tue, 04 Apr 2023 13:29:34 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pjgj5-0008Ri-RJ for pgsql-hackers@postgresql.org; Tue, 04 Apr 2023 13:29:33 +0000 Received: by mail-pf1-x42a.google.com with SMTP id l14so21436778pfc.11 for ; Tue, 04 Apr 2023 06:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680614971; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IK4AJs7JgnljKwMeHWKarDEpzeIS88tCyT8S5IgMqNA=; b=Dy/e4PKuZLGWV9UESgAhbweCF4oBEwJcx8sSXstL28RcINOtO7c3+8nhnt2NBolz/L bxoUIsqT6Cw+ML0HWgNcR/C7q+hNtlKRV8Iw3TyP5QitaTAqNwEdnOrcxTz95GyhNC8v 49jyuPlSsyhXZQ/o3QdjUHUNQiDuYD4BjUSrrHzyW6GU45y2y17hleN+Q/V4Ynmc8Jsg mciFR3It6UO1JgR3LWkOJryE7HRT1IRHx4eCi9xmIurGx9qCnvujT3Saqo42u5vMr1Xr 72FqAPLYVuoT9ZUUc44Bpvd9K+hqMMWt9aJjJ87J0C+yJ6TdR/wJWi3RHZpNsbKZ9R2V zF9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680614971; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IK4AJs7JgnljKwMeHWKarDEpzeIS88tCyT8S5IgMqNA=; b=Ib0ZvBkZDRdbvw87E3fYR7MOJq0Wa5f0mQ0mFC7RRy+baV3xKpf3migXw4CVLdRry+ EL0ehd/7UegszIV6AK7suAWCuz1EIMQKXvE79c601FMQ+ceikiHg4m/46QIhXTwrxLfO jxWQ/MX4JsxPUaKdjxq9TFecnxlxy4we+QZMlPuc5Gfsl8ceFwuoBoO1l5Aza5noZQo9 G2EZ3ZgxkmrBsx6Za9CV6+4xfeUlSxFn3O3MptFshxA10vFicVfwJw04eZHBNB5B9YFb /ijkIanuPV1ejbFdtOeqGm9eIhQ5yXPmVJ8LMFh+SFRC5Orf4ymXI/hPN1o1SRAfIAE2 49nw== X-Gm-Message-State: AAQBX9dcHYo784RBasUdzgHFtufNtMM3yjDiuGLtPcieonT60RdYVZaY Gl1IBjkYRD1zMpJSP+PVjyyki6ZFOMzpN5Cjlxk= X-Google-Smtp-Source: AKy350YVvFhbSUW/DQXH//+USOkajsy0cbAogjzxujGAQhq3I0OrU2WyMovzLXMC/moGdrC3HpLRVbVAccxiZv5ieOY= X-Received: by 2002:a63:602:0:b0:508:9e77:5bb2 with SMTP id 2-20020a630602000000b005089e775bb2mr718726pgg.9.1680614970505; Tue, 04 Apr 2023 06:29:30 -0700 (PDT) MIME-Version: 1.0 References: <20221221101846.7zsi7lscnm5ediik@alvherre.pgsql> <1350682.1671635927@sss.pgh.pa.us> <4191508.1674157166@sss.pgh.pa.us> <349124.1674185509@sss.pgh.pa.us> <20230207180855.xy5m4puwh5gzd7xy@awork3.anarazel.de> <1274885.1680558101@sss.pgh.pa.us> In-Reply-To: <1274885.1680558101@sss.pgh.pa.us> From: Amit Langote Date: Tue, 4 Apr 2023 22:29:12 +0900 Message-ID: Subject: Re: generic plans and "initial" pruning To: Tom Lane Cc: Andres Freund , Alvaro Herrera , David Rowley , Jacob Champion , PostgreSQL-development , Robert Haas Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Apr 4, 2023 at 6:41=E2=80=AFAM Tom Lane wrote: > Amit Langote writes: > > [ v38 patchset ] > > I spent a little bit of time looking through this, and concluded that > it's not something I will be wanting to push into v16 at this stage. > The patch doesn't seem very close to being committable on its own > terms, and even if it was now is not a great time in the dev cycle > to be making significant executor API changes. Too much risk of > having to thrash the API during beta, or even change it some more > in v17. I suggest that we push this forward to the next CF with the > hope of landing it early in v17. OK, thanks a lot for your feedback. > A few concrete thoughts: > > * I understand that your plan now is to acquire locks on all the > originally-named tables, then do permissions checks (which will > involve only those tables), then dynamically lock just inheritance and > partitioning child tables as we descend the plan tree. Actually, with the current implementation of the patch, *all* of the relations mentioned in the plan tree would get locked during the ExecInitNode() traversal of the plan tree (and of those in plannedstmt->subplans), not just the inheritance child tables. Locking of non-child tables done by the executor after this patch is duplicative with AcquirePlannerLocks(), so that's something to be improved. > That seems > more or less okay to me, but it could be reflected better in the > structure of the patch perhaps. > > * In particular I don't much like the "viewRelations" list, which > seems like a wart; those ought to be handled more nearly the same way > as other RTEs. (One concrete reason why is that this scheme is going > to result in locking views in a different order than they were locked > during original parsing, which perhaps could contribute to deadlocks.) > Maybe we should store an integer list of which RTIs need to be locked > in the early phase? Building that in the parser/rewriter would provide > a solid guide to the original locking order, so we'd be trivially sure > of duplicating that. (It might be close enough to follow the RT list > order, which is basically what AcquireExecutorLocks does today, but > this'd be more certain to do the right thing.) I'm less concerned > about lock order for child tables because those are just going to > follow the inheritance or partitioning structure. What you've described here sounds somewhat like what I had implemented in the patch versions till v31, though it used a bitmapset named minLockRelids that is initialized by setrefs.c. Your idea of initializing a list before planning seems more appealing offhand than the code I had added in setrefs.c to populate that minLockRelids bitmapset, which would be bms_add_range(1, list_lenth(finalrtable)), followed by bms_del_members(set-of-child-rel-rtis). I'll give your idea a try. > * I don't understand the need for changes like this: > > /* clean up tuple table */ > - ExecClearTuple(node->ps.ps_ResultTupleSlot); > + if (node->ps.ps_ResultTupleSlot) > + ExecClearTuple(node->ps.ps_ResultTupleSlot); > > ISTM that the process ought to involve taking a lock (if needed) > before we have built any execution state for a given plan node, > and if we find we have to fail, returning NULL instead of a > partially-valid planstate node. Otherwise, considerations of how > to handle partially-valid nodes are going to metastasize into all > sorts of places, almost certainly including EXPLAIN for instance. > I think we ought to be able to limit the damage to "parent nodes > might have NULL child links that you wouldn't have expected". > That wouldn't faze ExecEndNode at all, nor most other code. Hmm, yes, taking a lock before allocating any of the stuff to add into the planstate seems like it's much easier to reason about than the alternative I've implemented. > * More attention is needed to comments. For example, in a couple of > places in plancache.c you have removed function header comments > defining API details and not replaced them with any info about the new > details, despite the fact that those details are more complex than the > old. OK, yeah, maybe I've added a bunch of explanations in execMain.c that should perhaps have been in plancache.c. > > It seems I hadn't noted in the ExecEndNode()'s comment that all node > > types' recursive subroutines need to handle the change made by this > > patch that the corresponding ExecInitNode() subroutine may now return > > early without having initialized all state struct fields. > > Also noted in the documentation for CustomScan and ForeignScan that > > the Begin*Scan callback may not have been called at all, so the > > End*Scan should handle that gracefully. > > Yeah, I think we need to avoid adding such requirements. It's the > sort of thing that would far too easily get past developer testing > and only fail once in a blue moon in the field. OK, got it. -- Thanks, Amit Langote EDB: http://www.enterprisedb.com