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 1p4gqW-0006HX-An for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Dec 2022 11:19:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p4gqV-0003ql-0X for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Dec 2022 11:19: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 1p4gqU-0003qc-LU for pgsql-hackers@lists.postgresql.org; Mon, 12 Dec 2022 11:19:42 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p4gqS-0005wx-4r for pgsql-hackers@postgresql.org; Mon, 12 Dec 2022 11:19:42 +0000 Received: by mail-pf1-x430.google.com with SMTP id c13so8313858pfp.5 for ; Mon, 12 Dec 2022 03:19:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/5hOWzF4lkgCC+at/t5KCvPxuRC0z83bVE03eiV6yYc=; b=MGRjfO77t+EQf9UuQxIB64qZ4FsBaz9zeG4bxlW4uZijc2fo4c4C4KT2FJayG2FNSR DAWUR+T/8cGijZzBegXVcBgVK/v7Z3eklG8k7ULzi6KhckkqBqMlNASfa49/3TM2+3W6 OaWogQ6+XQVyvDvuEp622TQvkWRfgm7Mm4PWoigzTHbejgmHhymZR9UHRWRwetPj5UB6 BHzKYeo3n6dYSBzvCM2HkpMBhKIlfwjazvIJtpBA7eD415Vdk3pwr3ZXXG6mhxLw7oh3 NdT0mIgLnb4CZSuaOkIYjOlzNBhDzcSHkEi1ZkJHSqsKmxOErs6U8gfSW+vTBqYLC4sG 2i9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=/5hOWzF4lkgCC+at/t5KCvPxuRC0z83bVE03eiV6yYc=; b=OHWPksqYyWNoZKwEuqLT0G1S8qXFlxWOFZ+OEkOtxvB5j/0wu8Rpu4J1DcNbKVqfJ1 7WUGezUiprHsaC6n1qiA/Vhr4Moff5HlTlj7/ksoiGV780DCXQUCTlIT3wwgvTP2KxSC OmW24XFSMrBOLR4UkY9PS9Jl/IYF/h2PD5ZG9L1dxagJKksFhOxeSbRUOsLw1OuXNt5/ FzM8b5RSLutV3VaefczA0ggQ1oy9kcXtZZCCTAtINBitUem3v1N8MUifxeswCv2M4lLE rTsKtUi24juHyqExAbrXKjIuleqeyCyctd8aSSJ0rOYE7PRTF85VlWBF2Bc4gBzHhOtX rkRA== X-Gm-Message-State: ANoB5pm0PiZJQfrf4BoBCFtrmOBqvQ9SrwFVeXwXZ1vqgAKI2Rvj1Iax LGVO9EY9el7+O/ioANrEULQ3RELUfO3lgMn6liE= X-Google-Smtp-Source: AA0mqf5yj+ZVTLYHmzniRIaoXHkoQj+vzv2CAhLeaiS4YghANMBWjaarqyIXsoQT/9SkLRL25x0qVwUQ8rnJbNZA06o= X-Received: by 2002:a05:6a00:f92:b0:576:c84c:b331 with SMTP id ct18-20020a056a000f9200b00576c84cb331mr21656141pfb.79.1670843977319; Mon, 12 Dec 2022 03:19:37 -0800 (PST) MIME-Version: 1.0 References: <20221209113744.q64sfm3pazvsuo5x@alvherre.pgsql> In-Reply-To: <20221209113744.q64sfm3pazvsuo5x@alvherre.pgsql> From: Amit Langote Date: Mon, 12 Dec 2022 20:19:19 +0900 Message-ID: Subject: Re: generic plans and "initial" pruning To: Alvaro Herrera Cc: Robert Haas , Jacob Champion , David Rowley , Tom Lane , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Dec 9, 2022 at 8:37 PM Alvaro Herrera wrote: > On 2022-Dec-09, Amit Langote wrote: > > > Pruning will be done afresh on every fetch of a given cached plan when > > CheckCachedPlan() is called on it, so the part_prune_results_list part > > will be discarded and rebuilt as many times as the plan is executed. > > You'll find a description around CachedPlanSavePartitionPruneResults() > > that's in v12. > > I see. > > In that case, a separate container struct seems warranted. I thought about this today and played around with some container struct ideas. Though, I started feeling like putting all the new logic being added by this patch into plancache.c at the heart of GetCachedPlan() and tweaking its API in kind of unintuitive ways may not have been such a good idea to begin with. So I started thinking again about your GetRunnablePlan() wrapper idea and thought maybe we could do something with it. Let's say we name it GetCachedPlanLockPartitions() and put the logic that does initial pruning with the new ExecutorDoInitialPruning() in it, instead of in the normal GetCachedPlan() path. Any callers that call GetCachedPlan() instead call GetCachedPlanLockPartitions() with either the List ** parameter as now or some container struct if that seems better. Whether GetCachedPlanLockPartitions() needs to do anything other than return the CachedPlan returned by GetCachedPlan() can be decided by the latter setting, say, CachedPlan.has_unlocked_partitions. That will be done by AcquireExecutorLocks() when it sees containsInitialPrunnig in any of the PlannedStmts it sees, locking only the PlannedStmt.minLockRelids set (which is all relations where no pruning is needed!), leaving the partition locking to GetCachedPlanLockPartitions(). If the CachedPlan is invalidated during the partition locking phase, it calls GetCachedPlan() again; maybe some refactoring is needed to avoid too much useless work in such cases. Thoughts? -- Thanks, Amit Langote EDB: http://www.enterprisedb.com