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 1n2CH4-0007KC-67 for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Dec 2021 13:12:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n2CH3-0005Of-2b for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Dec 2021 13:12:17 +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 1n2CH2-0005OT-Nh for pgsql-hackers@lists.postgresql.org; Tue, 28 Dec 2021 13:12:16 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n2CGy-0006Xe-L3 for pgsql-hackers@postgresql.org; Tue, 28 Dec 2021 13:12:15 +0000 Received: by mail-pf1-x429.google.com with SMTP id s15so16185011pfk.6 for ; Tue, 28 Dec 2021 05:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DYw/Udmz2x91kxInWjSG0IN+iAqKzGuno6Pd0SZdkRE=; b=FYtDWKOr1xn236sZva1f+lobg5MHplh8t68tExB+uSurtBU1MzLLav1jHjzdpeUMCU 3BuqxaEWGPbcsNifSRgF3RnDd8A/xPabUW/mF4LMgCbIiLx++wPYlxlQXvVV6GSAe3YW LsgoyLfvkjsq/nCaVlhPUYnb4GoepuMImEMoc1pIr+Uh/voDzI5dcT6iYVLmE6GHh6H8 JTeVDGaxsk3lyT0hfSmbNZL/CR0B1IzvrK0sg8jd4GYJa9imR8msPAh2dxKL61XMorBM qrkWP2QcbS/fFJDuYF9/17zxnNVmQr2dw/K5GvFkffPjVOqtUn8qZ53p1X4U8X96gP+W GjIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DYw/Udmz2x91kxInWjSG0IN+iAqKzGuno6Pd0SZdkRE=; b=ORJYhge3Wl8oWSVgQ9NU/AUnOEd92XiNnq+kCvaPUvklgwKjnRjP51Z3Wvv+KdgOKR EzjZrNTn1FS/W4S4WPvg7xDaEepZwDDcpu6QxhLrSaSxuuYKC8KK48DC/a6sUQt7Oyd+ jAKa3WwImaDWzaNAx+90iczz4iMYRN3Zx78cSijcukYrmnNnfYFIMyvWBN4x34BDOAAX vIUAI+SKBj+OGcGhAiZxh1Kb85qNWeKsE4KKKt8L3kkpGvNpoO9iWVdOeT8OJ0Fxxzwh I4I6cmRyc1+QoXavxoE9nurKqVGocTLuH+YinSER0E9mJFYIENBn2DXVmS8A4tgHykSM EJuw== X-Gm-Message-State: AOAM531aM1ANg/XUM47T3uXbaS5/n7Pe5YCMoTLK3zyqV80+s0c5pTk5 X6nfDhRDSmDx3jPADwRz95DGP7Lpd4j3QPf6npsfSaFK X-Google-Smtp-Source: ABdhPJwNUSljcTPwaW4euBjdSwGrXtSE3/TJU9Qbs7peU1s3oQlZGk+JFrvPimlXukCCGE9tOkYzjLEyFjCUD/FBNHg= X-Received: by 2002:a63:4004:: with SMTP id n4mr18745254pga.216.1640697131374; Tue, 28 Dec 2021 05:12:11 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ashutosh Bapat Date: Tue, 28 Dec 2021 18:42:00 +0530 Message-ID: Subject: Re: generic plans and "initial" pruning To: Amit Langote Cc: 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 Sat, Dec 25, 2021 at 9:06 AM Amit Langote wrote: > > Executing generic plans involving partitions is known to become slower > as partition count grows due to a number of bottlenecks, with > AcquireExecutorLocks() showing at the top in profiles. > > Previous attempt at solving that problem was by David Rowley [1], > where he proposed delaying locking of *all* partitions appearing under > an Append/MergeAppend until "initial" pruning is done during the > executor initialization phase. A problem with that approach that he > has described in [2] is that leaving partitions unlocked can lead to > race conditions where the Plan node belonging to a partition can be > invalidated when a concurrent session successfully alters the > partition between AcquireExecutorLocks() saying the plan is okay to > execute and then actually executing it. > > However, using an idea that Robert suggested to me off-list a little > while back, it seems possible to determine the set of partitions that > we can safely skip locking. The idea is to look at the "initial" or > "pre-execution" pruning instructions contained in a given Append or > MergeAppend node when AcquireExecutorLocks() is collecting the > relations to lock and consider relations from only those sub-nodes > that survive performing those instructions. I've attempted > implementing that idea in the attached patch. > In which cases, we will have "pre-execution" pruning instructions that can be used to skip locking partitions? Can you please give a few examples where this approach will be useful? The benchmark is showing good results, indeed. -- Best Wishes, Ashutosh Bapat