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 1osm5L-0001p1-Ed for pgsql-general@arkaria.postgresql.org; Wed, 09 Nov 2022 14:29:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1osm5K-0004r7-9d for pgsql-general@arkaria.postgresql.org; Wed, 09 Nov 2022 14:29:46 +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 1osm5J-0004qx-Vt for pgsql-general@lists.postgresql.org; Wed, 09 Nov 2022 14:29:45 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1osm5H-0005ln-N0 for pgsql-general@lists.postgresql.org; Wed, 09 Nov 2022 14:29:45 +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 2A9ETZ7A3968477; Wed, 9 Nov 2022 09:29:36 -0500 From: Tom Lane To: n.kobzarev@aeronavigator.ru cc: "'Laurenz Albe'" , pgsql-general@lists.postgresql.org Subject: Re: Unnecessary locks for partitioned tables In-reply-to: <01a401d8f440$c48bf320$4da3d960$@aeronavigator.ru> References: <012801d8f42c$06ea5af0$14bf10d0$@aeronavigator.ru> <01a401d8f440$c48bf320$4da3d960$@aeronavigator.ru> Comments: In-reply-to message dated "Wed, 09 Nov 2022 16:40:01 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3968475.1668004175.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 09 Nov 2022 09:29:35 -0500 Message-ID: <3968476.1668004175@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk writes: > Oh, I did not explicitly write that, in case of custom plan (first attem= pts or with force_custom_plan) database holds only a couple of locks! Why = in this case it is sufficient to lock only one partition and parent table = ? Because partition routing is done at planning time in that case, based on the actual values of the plan's parameters. A generic plan doesn't have the parameter values available, so it has to build plan nodes for every partition that could conceivably be accessed. So for queries of this kind (ie point queries against heavily partitioned tables) the generic plan is pretty much always going to lose. That doesn't bother me enormously --- there are other query patterns with similar behavior. If you know that your queries always need custom plans, I question the value of using PREPARE at all. regards, tom lane