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.98.2) (envelope-from ) id 1xGJgC-00000002Dwz-03Hw for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Oct 2026 17:19:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xGJgB-00000009iU6-0302 for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Oct 2026 17:19:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xGJcz-00000009cPS-203E for pgsql-hackers@lists.postgresql.org; Mon, 12 Oct 2026 17:15:57 +0000 Received: from fhigh-b8-smtp.messagingengine.com ([202.12.124.159]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xGJcw-00000001jUF-2MJc for pgsql-hackers@lists.postgresql.org; Mon, 12 Oct 2026 17:15:57 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 8E6417A012F for ; Mon, 12 Oct 2026 13:15:51 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Mon, 12 Oct 2026 13:15:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm3; t=1791825350; x= 1791911750; bh=8U9ElH4WxvUtHu/RoPhVTuoK77tOBk8Qcrz8bI+N8Tw=; b=B rzvv4xp3immDNr7S6uQimvW1aBTRtRqF26TOOSBGeyPpno62BF4vQRPoiPBvj96r 1auicBMJIn3fSWM0pYkCVhCCwwaHYHPb4VXv3l4MlPLSpotUA9Nz4r4c38lxuxDa eh3wV6vmCtfQfUwIcTR0PN2ZTE9GHkCsFL0RL5qe2yJPeY2+gzL3tlxjFNuGd25d /alzJxrL15TrzFHODPTyKl30kkltLydi7QzgHbSEeFJyAZsZK78Wmzmn9CcnmQIt +KD9+nG09ThNF3AwLO65MS4sa3OacPJy4qbcFjPrqodl3jUIQE4A7nIBrMBh6PpP kc45C/nXRoBnPpO6pHvAA== 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-sender :x-me-sender:x-sasl-enc; s=fm2; t=1791825350; x=1791911750; bh=8 U9ElH4WxvUtHu/RoPhVTuoK77tOBk8Qcrz8bI+N8Tw=; b=c3+IADwJ9iXwYpxp5 u8NqtjRjA6Ih1ekOep50EojNCxl6uhrZ1m2ZkkWyOsixxyBvCEuF8jQhzKAXSFQk JbppTr6AYvSEnxNCMovbG0befDt9zYhwHsc98iSHBSa2H74b3iMB/CUvNPtZWH+/ dF1prHsIQJrzvmG987li94xV2KAXXBppprs3kY7TsLSH2yFPVUesHHxauk8oo90T Zgyr4iT8YTf+4Y0YJd482HsR5xj5mBURHk7TTeE+TXydw2/07pOu6BTpVanDhXg+ fktKEvKfbkpSXRTBDteA7YoeDm18ThYl1lDIU14WyMo6jumUYqyVmOu+phrRmbtP UuALw== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06; repo=github.com/dkim2wg/interop; date=2026-10-04; sw=lmtpprox; action=sign d=kurilemu.de a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1791825350; d=kurilemu.de; mf=PGFsdmhlcnJlQGt1cmlsZW11LmRlPg==; rt=PHBnc3FsLWhhY2tlcnNAbGlzdHMucG9zdGdyZXNxbC5vcmc+; s=fm3:rsa-sha256:dl3jGTYLZeIbAVAlo1/qsazOLguM4gt1V2jXbSw0w2mcK76 gWWJmPQMs2n0A99+QZKsmo7mXeEcpU6MVYgIWzAB8ogKJr8ctJZ64KPF5kbpdCpc YSexSbsgJ0IVA+9YkpimLP8XFBKXn9tk/9JBK3sA49ntrY3Kk5u1ewN5YGXHx+uZ zcXjgAQUXBJ+Iw/Uctw/TQW8K2SflsNb0fp5KRiTaFxtLDDbrHwAO+bV9BVaJNwd uZBhsuI5Ru7KzKyrx5BYJUUnCq3kSHUwTNUToZPc4xeobaqiTBzV3UtBb2/Ca3Y8 /tSdi8uBPOxgAD0QB1x38SvC+TYOPsh4ntQV+mg==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06; repo=github.com/dkim2wg/interop; date=2026-10-04; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-transfer-encoding, content-type,date,feedback-id,from,in-reply-to,message-id, mime-version,subject,to; Message-Instance: m=1; h=sha256:cLHPMftRmIKi7fZM7cJyTm9FB62I5ZPSNiBjrEzfm/c=:1QMgRqT0+7gaZZb33YtzPIyKE5qOAzJNl3v4Hpjre2w=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGzcEb1I4WfYJhKfd7tOGS9tDm/EdnTWDQu70q7XhToJeF5k+8zNVO9AF+8Fror+L /OzeiirGjyiVVPua0diaFgZJ+2+kAbN8ybiVTdNyYfmoSgLzY7KXsHN86idxnTJKtnNo6H fccUTkkpjnWs+kLsX2okWifROsYqW0XzIb9psTP5lZH5+Kepsok8ZOuroAJUU+KdZ1Gf3j Puaafp6paFIVacIqzrvBfUVEmZVmfeA5EDV36t3DoGc6Ryf05qtrCMlRly82Wg0grcfpec GxH33g0HUp1NxGQg4MrlUXawJKdGQMW9HKWz8AAwaLBw64uhKONcCQ49qJsUU67z+iqeJI ihcWy19KHfSmCKWQU1e8TOsDI8maCmeZDG2pk9biRwh3HXf5I/e/tSvlQe3dS7rLINpvpo agomH/chVj47LA8D2lMVn+bq0DucHnSsdKHMp/SNz7Vaz4VH/V5WFP9sIuFR8RN9geUQO+ VySq5Jy5egrAzp2t3qlvpM5wP5NA5dq40UnE/foSwcaZYGBlZYpW0oqExsWTbAWx6328pQ MqnYIrtxFlMtoarOlzN4S3+Ev9JxhuZa9NwnM55abc8hEEo20r9vdGZ2M9yoQyevwPDxbi BCtYpm6etvBRESmxnh1//EdjbS7ilKrvwjEnOgZ+Mmk/Zm84wSUb9ao5kTXA X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Oct 2026 13:15:48 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1791825345; bh=1QMgRqT0+7gaZZb33YtzPIyKE5qOAzJNl3v4Hpjre2w=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=Av7xdcHF6+ePmPLzDcDaaJMASJM2BTnxPJVhggLUisW1RnVxNDVtEsiW96SFz2OS8 RgjLqZl+I9YiDIaACKVQNNlc6NeuhCyuc0VY/Za+yh/6VzLkB8eFNfaBV45TFFQnfp U2Mj+yRPrXLK/CnRQoBFjgxo5O4e2fx4uU32ojLrqy1cPgrydeQGgKNiiy3Pk9l1d3 MZyztvbmM1o9lk5ImRy1unlZ9REjDh+HV6+OI0v6MQaMAmdgOjILcK+KZ+fIjJnEJ8 io1Ov1p2IpTA7B/1I3ZyLmlH9SC3MrrOsiu20bjRoZd8nGjI04N8PyhZdeGX2Nr5zT pOg/nmWqRoipQ== Received: by ida.kurilemu.internal (Postfix, from userid 1000) id 4BDF1B0018F; Mon, 12 Oct 2026 19:15:45 +0200 (CEST) Date: Mon, 12 Oct 2026 19:15:45 +0200 From: "alvherre@kurilemu.de" To: Zhijie Hou Cc: Bingshuai Li , "Hayato Kuroda (Fujitsu)" , Michael Paquier , Tom Lane , Alexander Lakhin , "pgsql-hackers@lists.postgresql.org" , "mark.dilger@enterprisedb.com" , Amit Kapila , Masahiko Sawada , Andrey Rachitskiy , "a.kozhemyakin@postgrespro.ru" Subject: Re: Bug in logical decoding with DDL and subtransactions Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Okay, I spent some more time trying to rewrite these comments in the new function so that they explain what we're doing in terms we use elsewhere in the code, and according to my understanding of how this works. The phrasing proposed by Bingshuai contains some terms that we don't use anywhere else, such as "a decoding pass" and other variations thereof, referring to the logical decoding "session". I would appreciate a review for correctness; if it's wrong, please propose fixes as minimal as possible (that is, not a complete rewrite). By the way, the assurance that with this coding we will never call bsearch() with a NULL subxact array seems a bit too trusting ... I think we should just add the "return false" if nsubxacts == 0 in TransactionIdInSubxactArray() just to be on the safe side. It costs nothing. (Well, nothing compared to the cost of doing a hash lookup for every single aborted subtransaction -- should we instead impose a cost on ReorderBufferBuildTupleCidHash?) /* * Remove TUPLECID changes from a top-level transaction's tuplecid list. * * 'xid' is a subtransaction being aborted, and 'subxacts' is the list of * its children -- which are, obviously, also being aborted. * * Unlike other types of changes, tuplecid ones are always queued on the * toplevel transaction (see ReorderBufferAddNewTupleCids), so we must search * for these changes by subxid. Because TIDs used by a catalog tuple written * by a subtransaction that aborts can be reused later by a future command * of the same transaction, we must remove these TUPLECIDs from the array, * otherwise the tuplecid hash of the historical snapshot would be corrupt. * * If the xid being aborted is not known to this reorderbuffer to be a * subxact, we return without doing anything, which is correct because there * cannot possibly be TUPLECIDs to clean up; the topxid would've been created * by ReorderBufferAddNewTupleCids(), and the association between the two is * known because we're in SNAPBUILD_FULL_SNAPSHOT mode (otherwise the NEW_CID * WAL records aren't decoded.) * * (This cleanup is pointless when xid is a top-level transaction. That case * is handled instead by ReorderBufferCleanupTXN() clearing the whole list.) * * XXX this whole exercise is only needed because of keeping the TUPLECID list * assigned to the toplevel transaction. Maybe it would be wiser to have a * per-subxact list instead. */ void ReorderBufferCleanupAbortedTupleCids(ReorderBuffer *rb, TransactionId xid, int nsubxacts, TransactionId *subxacts) { ReorderBufferTXN *txn; ReorderBufferTXN *toptxn; dlist_mutable_iter it; /* * Search the passed-in xids for the first known subtransaction, and use * it to find the toplevel transaction. */ txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr, false); for (int i = 0; txn == NULL && i < nsubxacts; i++) txn = ReorderBufferTXNByXid(rb, subxacts[i], false, NULL, InvalidXLogRecPtr, false); /* * Skip when nothing usable was found. No entry at all means no NEW_CID * record from these xids was decoded by this snapbuild so nothing was * queued, or that we entered FULL_SNAPSHOT after the subxid was assigned * as a child. In the latter case, we won't find the TUPLECIDs, but we * don't care. If this is a top-level xact, this cleanup is not * necessary. */ if (txn == NULL || !rbtxn_is_known_subxact(txn)) return; /* Get the top-level transaction whose tuplecid list we're to clean */ toptxn = rbtxn_get_toptxn(txn); dlist_foreach_modify(it, &toptxn->tuplecids) { ReorderBufferChange *change; change = dlist_container(ReorderBufferChange, node, it.cur); Assert(change->action == REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID); /* * Remove the entry if it was recorded on behalf of the aborting * subtransaction or one of its subcommitted children. The subxact * array is known sorted in logical order because it comes directly * from the xl_xact_abort WAL record, which has them sorted that way * by construction (Xid assign order.) */ if (change->data.tuplecid.subxid == xid || TransactionIdInSubxactArray(change->data.tuplecid.subxid, subxacts, nsubxacts)) { dlist_delete(&change->node); ReorderBufferFreeChange(rb, change, false); Assert(toptxn->ntuplecids > 0); toptxn->ntuplecids--; } } } -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Los dioses no protegen a los insensatos. Éstos reciben protección de otros insensatos mejor dotados" (Luis Wu, Mundo Anillo)