Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wUvuW-001YBE-2L for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jun 2026 00:26:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wUvuV-0040UP-1M for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jun 2026 00:26:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wUvuV-0040UH-00 for pgsql-hackers@lists.postgresql.org; Thu, 04 Jun 2026 00:26:11 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wUvuT-00000000zRN-0zq5 for pgsql-hackers@lists.postgresql.org; Thu, 04 Jun 2026 00:26:10 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-36d9794d82aso50345a91.0 for ; Wed, 03 Jun 2026 17:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780532768; cv=none; d=google.com; s=arc-20240605; b=TYapmhV+4DTn5v59IfYVyHN8y6S1LoJvkuTGPR61jEl050wmdb0KNOpaDpCgCVOZhP hq4JHN8MysEZZzWxhH7C6xkU90+CQ+LYVjeh2cRC7LmpQ4x4f8zP+87u1Pb3FG8fBjyw ocwWoVzo4ijbxq5emu759hqXKiJEWSyX9VanAYLrUTSvW/Z7a6sELnntTCrFYalI4cfs iOtFBNJi15yGtag+i2PCGszEsgC4H70WWYaYKOlMPPUiM9IHFl+0zj0k4fQeYLEVX9yA RR2+pzdRwTrlKpr4Q4dNYrsAL/BY4NXI0t6gkmsdzm4ZSmPpmtq1M4UndMrZbJsk92qz tPTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=baN/qWX5JL84AM2DzKhKi/M/hzlUnGEGsMX+OODunQc=; fh=JqyJjZNPl/XofGNc69ZuC6JYqRC5MUsR23YXNEtyIYI=; b=ZhPbi8kem+jZq8Rxo1lObAxVfB2j+4Np0SQvPidAa6cU8odlGLwSjDdD6qxm9YSfhc 05UTcWoZjPwB5gwWsp+Fkzx4T5oeWLWYhTctdLdok5jdD+ol1fAtYS7jq5/+k0MiFIkt 9I/Q0I1mhpB8L6jpde6nyCtv6mt39ixQmATqGMzJ2AVTsTPMfw9nzRF+AAGzFg3E6jc7 afuEhKzKQOmaZzdU41OqPR6l4DV26juL9oXxtCtbhSWGA1d/xQ/6b3eWgiM8TIBGh86E EZ4UPRcSBsN/0sjcR48eHQwbHHQggxKNEGeDhwJzdKFpTe4mZw2VvMrcx9vovNGCSYCg fFyA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780532768; x=1781137568; darn=lists.postgresql.org; 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=baN/qWX5JL84AM2DzKhKi/M/hzlUnGEGsMX+OODunQc=; b=CX62mqUulYl+qSkCTaERWE+dY4rYp6MJs9ZTlEdUWegCYgy4sQruFI85RJ/puCw4tr sAnkCTNFk0jn/pk5ZN1bhD0hngTeizICqr6OO6PBANOQeawtwdamQZNRnbtcoXevrAHf WtoqRSyMoSmGuFCQfKwPBekESn9r4/AefAI3xqtrhXejaWPDpY38s38uCOSu8t00iC3/ WTcbF6CaJ0v8rAV1m7SWfks7nGwShGZSyqiAq3GS9BaMaQJNDnAflffJd8PqxUty6y9D DWvgY7tslcPoOAe2Zp0fW2q8+A2JLG9E/i3GO/XJgyhlr4MV3ddKBidUbxfmBmKi+6CA BFcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780532768; x=1781137568; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=baN/qWX5JL84AM2DzKhKi/M/hzlUnGEGsMX+OODunQc=; b=cjBpSV1Hjl5+CBmGxZbd5s82mn3j/IdcEqfy0nNurEobMEWfUvWDcef1YYGG6EAm4J gV63ZWAtb1uS/PF1uNMwt0gZB3IRrD4bT7mmS1fTQtY1FQtt/UM2sDVfB7FGpGKkc9FZ vgEcVkbUn/YZkSRocATLxLel1WGpt8LznEvJZEYRoFyD7or70J8Tl6B+o7SrXKI/XcWE PcRsX4hjvfNDE4Mf+MpXJzMlQuMpOOS8Z8R/grZtmX7hEn+lSkjq9yikUuv7d4EyUJg6 O2IfTFKIuQ3dlTGW98+qBdEQZfuz30VDfh8chmdwThgMp7tC+tkR4MtVmLhD85EudKMo E2dA== X-Gm-Message-State: AOJu0YxUNCsez6AShi6Nnyzd4uoobC+keoD85c8SdW48vmXnJqdQJjOt dF8MVXFgRmkCPZH1ci1n7lQCLy3EtiWKv5T6aY/SMxZP5VwwLXGUjjNZauHucJsaMDBcb1tsHK6 88Om5gkpVxnpCjeDQBBW/rpI/BE94XRxFVG5c X-Gm-Gg: Acq92OFFjtUJ03r4LRQBE1ZyZNTHckoB68hVHIhIl9Y9xSvqUX2pgFM4rh9/rYA9uX/ 6H/CUTpHdK9kaccna3pFJBXKNLQS831/Nstzze7PgbRn/kwQttsE9pYXY6GdwrVx64DdL8Tcqt/ nZODPvljeH/LVsBURqrZmB4eB2Fapg9KlxwpOCgRIcvMScuI+9gx7i4YtJNtkmMth78EYiWxhL1 PYAeOzWMtkY07hH2/ypT4xEea1240MvJd+SAJO8UzYM0+T/Snx+RVSdGdt28z6Z7hnxRxep8kaP HKeObBP4Av7A9/tnKdFbTj+hm1VJGBAyA1g7AMEZLpZeFKikdrgYV8y3I71GCbVkOQ/xYlsgDm4 = X-Received: by 2002:a17:903:1a83:b0:2b7:aa20:3c61 with SMTP id d9443c01a7336-2c1644b08c7mr58333235ad.33.1780532767983; Wed, 03 Jun 2026 17:26:07 -0700 (PDT) MIME-Version: 1.0 References: <178042284979.1017.17926732655528064040.pgcf@coridan.postgresql.org> In-Reply-To: <178042284979.1017.17926732655528064040.pgcf@coridan.postgresql.org> From: Amit Langote Date: Thu, 4 Jun 2026 09:25:51 +0900 X-Gm-Features: AVHnY4JS1H9gkaU1QxZkUTZ3iV_GMF_N2huQmBNikM8PPH02pDQ6NoB9WsxsF9Y Message-ID: Subject: Re: generic plans and "initial" pruning To: Ilmar Yunusov Cc: pgsql-hackers@lists.postgresql.org 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 Hi Ilmar, On Wed, Jun 3, 2026 at 2:55=E2=80=AFAM Ilmar Yunusov = wrote: > > I looked at v13, focusing on apply/build status and relation-lock behavio= r for > reused generic plans after initial partition pruning. > > I used the v13 series from Amit's 2026-05-29 message, on origin/master at > 4b0bf0788b066a4ca1d4f959566678e44ec93422. > > The series applies cleanly with git am, and git diff --check reports no > issues. > > I first built with: > > ./configure --prefix=3D"$PWD/pg-install" --without-readline --without-zli= b --without-icu > make -s -j8 > make -s install > > make -C src/test/regress check > > passed; all 245 tests passed, including plancache and partition_prune. > > I also built a cassert/debug tree with: > > ./configure --prefix=3D"$PWD/pg-install" --without-readline --without-zli= b --without-icu --enable-cassert --enable-debug 'CFLAGS=3D-O0 -g' > make -s -j8 > make -s install > > and ran: > > make -C src/test/regress check > > which also passed; all 245 tests passed. > > For the lock behavior, I used a list-partitioned table with force_generic= _plan. > After the generic plan had been built and then reused, EXECUTE held only = the > matching child partition lock. For example, EXECUTE q(1) held only the > following child lock: > > manual_prunelock_p1 > > EXPLAIN EXECUTE behaved the same way on a reused generic plan; EXPLAIN EX= ECUTE > q(2) removed the other subplans and held only the following child lock: > > manual_prunelock_p2 > > With enable_partition_pruning =3D off and a newly prepared statement, exe= cuting > the same SELECT held all child partition locks: > > manual_prunelock_p1, manual_prunelock_p2, manual_prunelock_p3 > > I also ran a bounded cassert/debug stress check around plan invalidation.= It > did 20 cycles where a child index was created and dropped before EXECUTE,= and > 20 similar cycles before EXPLAIN EXECUTE. In each cycle, the first execut= ion > after invalidation/replanning held all child partition locks, and the nex= t > execution reusing the generic plan held only the matching child partition= lock. > That matches my reading that the patch is reducing locks for reused gener= ic > plans, not for the execution that has to rebuild the plan. Thanks for thorough testing. > One behavior I wanted to confirm: prepared UPDATE execution still held al= l > child partition locks in my manual check, including on the second executi= on > where the generic plan was being reused. > > The test was: > > prepare upd(int, text) as > update stress_prunelock_p set b =3D $2 where a =3D $1; > > Then both: > > execute upd(3, 'updated-row-3'); > > and an all-pruned value: > > execute upd(99, 'no-row'); > > held: > > stress_prunelock_p1, stress_prunelock_p2, stress_prunelock_p3, > stress_prunelock_p4 > > pg_prepared_statements showed generic_plans increasing for this prepared > statement, so this was not a custom-plan case. > > Is this expected for ModifyTable/result relations in v13, or did I miss a= n > eligibility condition that prevents pruning-aware locking from being used= for > this prepared UPDATE case? I saw the recent firstResultRels discussion, b= ut I > was not sure whether those changes are intended only to make pruned > result-relation initialization safe, or whether actual prepared DML execu= tion > is expected to see reduced child partition locking as well. Yes, this is expected; the pruning-aware path currently only kicks in for the portal strategy used by SELECT. I hadn't noticed that UPDATE/DELETE ends up on a different strategy that bypasses the new pruning-aware locking path. I need to think about how best to handle this; the DML portal strategies defer executor startup to a later point, so it may require some restructuring. --=20 Thanks, Amit Langote