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 1x7YTc-00000000TgT-2EzA for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Sep 2026 13:18:04 +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 1x7YTb-00000001JEw-3eOx for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Sep 2026 13:18:03 +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 1x7YSD-00000001Fle-1ZdE for pgsql-hackers@lists.postgresql.org; Fri, 18 Sep 2026 13:16:37 +0000 Received: from mail-wr2-x0f.google.com ([2a00:1450:4864:30::f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x7YSA-000000002BS-3axx for pgsql-hackers@lists.postgresql.org; Fri, 18 Sep 2026 13:16:37 +0000 Received: by mail-wr2-x0f.google.com with SMTP id ffacd0b85a97d-482f635552aso584633f8f.2 for ; Fri, 18 Sep 2026 06:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1789737394; x=1790342194; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:content-id:content-type :mime-version:comments:references:in-reply-to:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to:content-type; bh=/L7/Ki2U0024WUlke+aXHC8G5r9E1Jr0j0DyDBZnWrE=; b=mwPy3oHmKJWIC19NFeydiLnGIftK4dn5Z0zRA3sbIZz/Q29inOY6oI2ihaIpR4A5yn W8C9mNj+FqKvA7NQo0KXv0tGaid7BnFHGmPq7FoScFhknpmYXMq2PuA/+B5m0STIeYgL 60pb9mtgM3VCFJT38O9qTG2NpzIU6jwuqulco+LnH8MrWaYM3BASAoLzuqSNvxEMv6AN 7m5Z4AwkQd+2AvPsGR+oTi148420tNEbsj3gukWc6zSmAiX7x43adaHv3ukgb7CNPvFB Plnghlqxquwbbf5H8eTAi1YdybFEt0qmhnL94XWbAsmtHbnAr//+/S4mp7hpKVGEZ9+L rFJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789737394; x=1790342194; h=message-id:date:content-transfer-encoding:content-id:content-type :mime-version:comments:references:in-reply-to:subject:cc:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=/L7/Ki2U0024WUlke+aXHC8G5r9E1Jr0j0DyDBZnWrE=; b=BM65c9Le71kkuHswv4/btmiUK9gSRtVF7I9t68CZtNV6GZfGhUCq595aDXDlIRTbKc MuF6A6ZNhueZu32A1TIPvnulUmbuzscdvW5B0TTiTcg0zmLE1mJg81W9vee8yCQzrsf3 D5jPRv4r/q/HtHOff/LLFPx5rRrSPm2WlJf3Z+rw+qEdHH5y4IFpJerdFcwK5dLdT4Jx SEv6yjHV4sEoYJShTWKd74+zcKfceixBs8mE918KRNIyLoN8GmXhWr4eHJeCEL3BIu83 glWiO/vvPc4qWnaBhMZQvTuTgz//5EEuD9W50vwzjjnhlCiQNoIos0wflmhhreNLzR5S pehg== X-Forwarded-Encrypted: i=1; AKwUvBxAuFFuYJGcQEfiZln6i3bw5w/OmFSbbTSxwLN9/oXaYacJIIpDGOwvKa0nFeDj6DG8rZRV1knXu8RMlq7J@lists.postgresql.org X-Gm-Message-State: AFuF++kNeF0fTY3vqrINjoeZtdtqhdAZNPTFb9ZW7JBK3LG9y6EPq4Ng I7BhxJc2xBl3rjgJ+wKkNcoHR4VMi+NP+DnBKc70b5ExglDg4GPX8OigLu2Q3gY3rqo= X-Gm-Gg: AYBFou22ZbHy/JWM7xr4Gq0BZ5wG2e2J5yLX/PtmDNJJiEzq40IIkt+ME/UU7KFastN +rJJQPW6+a8z0oY5JHZYfr/pFBaV9WV7aPyC2KfULIbeIZhCia19458CO+QP7SRNUqge6lCuKE2 RUufvCqOLy5yC8KfaAO3/MWn49poFfAiOmYo9xoN14Yyj023xBZLtHmc0eVql3VvpVj+KQsd33P hw8qNLrB16x3E0mAmpXLmUfKhMgif4ASeCH1/cDGuUHaBEVxJezE8cfYr3lMJSqouKI/Vjl3/qn rIn0hO7gECHQwtsxVuLUPk/Mq7M4G5lKgU/sKYhwwhTQrfe5MKB6L75Jo92R2f+aBKSfEv0auPI A/h2kTZL1EANqUccsbQJosPMCfH/1NUKwxkuKr5asMOVB23EQNSMGX7VtkGF4RBljrtQ2kdDTQ/ gkV8ODXP+8Ys2BXWDV/YhFCVhozjTuhSB2NtgGL5CE3vcJ2cnL0BM8Me9bcmeF/RVzd76dvO9VR Kvj0Awgp0iJ X-Received: by 2002:a05:6000:186b:b0:487:81c:b5e2 with SMTP id ffacd0b85a97d-4871e244c0cmr3517389f8f.5.1789737393944; Fri, 18 Sep 2026 06:16:33 -0700 (PDT) Received: from localhost (109-81-170-190.rct.o2.cz. [109.81.170.190]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4872008023dsm3977357f8f.29.2026.09.18.06.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 06:16:33 -0700 (PDT) From: Antonin Houska To: Alvaro Herrera cc: Rui Zhao , Andres Freund , pgsql-hackers@lists.postgresql.org, Mihail Nikalayeu Subject: Re: Race conditions in logical decoding In-reply-to: References: Comments: In-reply-to Alvaro Herrera message dated "Fri, 18 Sep 2026 14:28:55 +0200." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7387.1789737392.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Fri, 18 Sep 2026 15:16:32 +0200 Message-ID: <7388.1789737392@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alvaro Herrera wrote: > On 2026-Sep-17, Antonin Houska wrote: > = > > > + for (int i =3D 0; i < nrunning; i++) > > > + { > > > + TransactionId running_xid =3D running->xids[i]; > > > + > > > + if (bsearch(&running_xid, snap->xip, snap->xcnt, > > > + sizeof(TransactionId), xidComparator) !=3D NULL) > > > + XactLockTableWait(running_xid, NULL, NULL, XLTW_None); > > > + } > > > + } > > = > > I don't understand why you check all transactions in procarray, instea= d of > > only those in snap->xip. > = > Hmm, but he does: for all the transactions that are running, only those > that are found by bsearch() in the snap->xip array are waited for. Is > that not what we want? > = > I guess we could do it the other way around: iterate for each item on > snap->xip and search for those in running->xids. Is that what you > suggest? > = > We don't know offhand which array is largest; it would be better to > iterate on the smaller one and bsearch the largest. (Or maybe if both > are sorted, scan them simultaneously.) I don't find any reference to > say that running_xid is sorted. Maybe I miss the point, but what's wrong about modifying the existing loop that inverts the meaning of the ->xip array /* * snapbuild.c builds transactions in an "inverted" manner, which means i= t * stores committed transactions in ->xip, not ones in progress. Build a * classical snapshot by marking all non-committed transactions as * in-progress. This can be expensive. */ for (xid =3D snap->xmin; NormalTransactionIdPrecedes(xid, snap->xmax);) { ... } by calling XactLockTableWait() for each XID we find in the array (i.e. eac= h committed transaction)? > I don't understand these two paragraphs: > = > * A subtransaction is covered by its top-level transaction, which is i= n > * snap->xip as well, or was purged from it because it is below xmin an= d > * thus finished long ago. Me neither. AFAIU SnapBuildCommitTxn() adds both top-level transaction and subtransactions to the builder's array of committed transaction. > * Historic snapshots do not need this: between xmin and xmax they rely= on > * xip alone, and transactions below xmin had left the procarray by the > * time the xl_running_xacts record that set xmin was written. I think this is related to the note that HeapTupleSatisfiesHistoricMVCC() = does not really use CLOG in the 3rd paragraph in [1]. [1] https://www.postgresql.org/message-id/CAHWVJhHXyLtS-8mdL9WhEWfsERb%3DF= N7JdPD0GYAXgTmCnqbYGw%40mail.gmail.com -- = Antonin Houska Web: https://www.cybertec-postgresql.com