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.94.2) (envelope-from ) id 1sHU1w-0085cB-CN for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jun 2024 19:53:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sHU1t-006Enq-Lh for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jun 2024 19:53:10 +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.94.2) (envelope-from ) id 1sHU1t-006EmY-5L for pgsql-bugs@lists.postgresql.org; Wed, 12 Jun 2024 19:53:10 +0000 Received: from wfout1-smtp.messagingengine.com ([64.147.123.144]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHU1q-0010VZ-FG for pgsql-bugs@lists.postgresql.org; Wed, 12 Jun 2024 19:53:08 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.west.internal (Postfix) with ESMTP id 5CCE71C00090; Wed, 12 Jun 2024 15:53:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 12 Jun 2024 15:53:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718221983; x= 1718308383; bh=S75e9fuOpkxHCuQXUv64LHPHy19HxGY7BggSuAqA//Y=; b=A TcRkZJE96p/WniEWabTY3DrRMOJ4vw+/HdyUiUE4g7pWL3/XguN95Te4bx4Mcz6E ftigbWfpR57nOtMbRqS8stwC8WvAluNGjq/wgEi4tqM8bkTgkpZksCLdxlCFtV1A dMYOK8JyenjrY3vSF3XuK8c9kvnc+fT90TRUzqXLuSrIdQ35Kr/SYVggE91TQ4LK beR2a4uSk5/eVkGburnuT4rJde1Q+vQYjxkj5UDnX8KHxRtk3liE29tNnEjmNn6D QQ6sXikDNNhPBbGJDYfdBM9W7fLnLV298OTRzlpRJNuiAl2AFOfrp9HC9M57w/sp J/yDyHsAwiQ12vUCry0WQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedugedgudegtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfggtggugfgjsehmkeerredttdejnecuhfhrohhmpeetlhhv rghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorh hgqeenucggtffrrghtthgvrhhnpedvgeejvdeguddvtdffkeeutdduieefueeltdekheeh udevveeuveffheekueegieenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtoh hmpdhkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Jun 2024 15:53:02 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1718221980; bh=dPaGtd8PvgRhFwRpsxdBT1rxzzu03PvxQuRe1lAM+04=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=YGCujm943zmafma7eyK5ig4e8WtloAFDLaKQ/lOc/AVDHlsthFiHFgFSW9sKMej7m 4o2rMTI26HENcICZq3Q1ccoOLN/wc3Zb8X1t5EYkSG6fPI6d6cWmfopE/vFqHBwWgE 3fVeD8ocsGWMjDaGHA/XyKa1vdfuqUW04M8uflvH6GPnVciiMZPOf18dLL2xPnl8Rv sWvqMStbQzEKITrTmbVWcSc928Gm7pkO8CHYzLK6ryD2OoZSF9vlKAztt5HA+K10uy lkS9QMAEho+WDjJaDDDI/yd8gLzVsqF+RWh0YIVrGrAFZUshWXxg8t5eX7lBM4xMhJ AYmsTb/TeO2tw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 3EFA7D1; Wed, 12 Jun 2024 12:53:00 -0700 (PDT) Date: Wed, 12 Jun 2024 21:53:00 +0200 From: Alvaro Herrera To: Tender Wang Cc: 1026592243@qq.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18377: Assert false in "partdesc->nparts >= pinfo->nparts", fileName="execPartition.c", lineNumber=1943 Message-ID: <202406121953.gfdukghim5d2@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="5lvbi5lqai2zuao4" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202406110902.awejvctiva7n@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --5lvbi5lqai2zuao4 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2024-Jun-11, Alvaro Herrera wrote: > ... and actually, the code that maps partitions when these arrays don't > match is all wrong, because it assumes that they are in OID order, which > is not true, so I'm busy rewriting it. More soon. So I came up with the algorithm in the attached patch. As far as I can tell, it works okay; I've been trying to produce a test that would stress it some more, but I noticed a pgbench shortcoming that I've been trying to solve, unsuccessfully. Anyway, the idea here is that we match the partdesc->oids entries to the pinfo->relid_map entries with a distance allowance -- that is, we search for some OIDs a few elements ahead of the current position. This allows us to skip some elements that do not match, without losing sync of the correct position in the array. This works because 1) the arrays must be in the same order, that is, bound order; and 2) the amount of elements that might be missing is bounded by the difference in array lengths. As I said, I've been hammering it with some modified pgbench scripts; mainly I did this to set up: drop table if exists p; do $$ declare i int; begin for i in 0..99 loop execute format('drop table if exists p%s', i); end loop; end $$; drop sequence if exists detaches; create table p (a int, b int) partition by list (a); set client_min_messages=warning; do $$ declare i int; declare modulus int; begin for modulus in 0 .. 4 loop for i in 0..99 loop if i % 5 <> modulus then continue; end if; execute format('create table p%s partition of p for values in (%s)', i, i); end loop; end loop; end $$; reset client_min_messages; create sequence detaches; which ensures the partitions are not in OID order, and then used this pgbench script \set part random(0, 89) select pg_try_advisory_lock(:part)::integer AS gotlock \gset \if :gotlock select pg_advisory_lock(142857); alter table p detach partition p:part concurrently; select pg_advisory_unlock(142857); \set slp random(100, 200) \sleep :slp us alter table p attach partition p:part for values in (:part); select pg_advisory_unlock(:part), nextval('detaches'); \endif which detaches some partitions randomly, together with the other one \set id random(0,99) select * from p where a = :id; script which reads from the partitioned table. This setup would fail really quickly with the original code, and with the patched code it can run a total of some 6700 detach/attach cycles in 60 seconds. This seems quite slow, and in fact looking at the total number of partitions in pg_inherits, we have either 99 or 100 partitions almost the whole time. That's why I'm trying to modify pgbench ... I think the problem is that pg_advisory_lock() holds a snapshot which causes a concurrent detach partition to wait for it, or something like that. I added a \lock command, but it doesn't seem to work the way I want it to. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "I'm always right, but sometimes I'm more right than other times." (Linus Torvalds) https://lore.kernel.org/git/Pine.LNX.4.58.0504150753440.7211@ppc970.osdl.org/ --5lvbi5lqai2zuao4 Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="v3-0001-Fix-partition-pruning-setup-during-DETACH-CONCURR.patch" Content-Transfer-Encoding: 8bit