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 1ur9TB-001QoY-7l for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Aug 2025 06:17:18 +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 1ur9SB-00Cp8w-Oz for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Aug 2025 06:16:16 +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 1ur9SB-00Cp8o-8S for pgsql-hackers@lists.postgresql.org; Wed, 27 Aug 2025 06:16:16 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ur9S7-001y8b-1X for pgsql-hackers@lists.postgresql.org; Wed, 27 Aug 2025 06:16:14 +0000 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-61a8c134533so13143920a12.3 for ; Tue, 26 Aug 2025 23:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1756275368; x=1756880168; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:mime-version:comments :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cObXSdsdwRneT56NK2w4Ykngh3AUZwrsdoF63HqEVGo=; b=kPdBH0PvI7WKhWxmMsNeVu0IX7RUBpvHceOrm3hNGwllLM/MLZRn6sJ8XppsZdPn51 RAJEcESXJ0lwq8s+5Vif7xyp2mbhFLIB0p1K1oA6cz4RN5gvFWiuZXmS+1vj0zW0oMZY cgtPn3R7zXeTAlYokwIook6xVSl5AzS4qjd0c1JInwXdHZlXxGllIdeIWDKNmykY17Nf 6jeSEITNqagfefOjxqJjW/1uYcWTgZ5joBCQFNPrIen4S4gcpC9m960sbiYZlZmqa0bv qUbNgmIIHjEV420QrVNHlt3bOzCow2o/hXFVArqMgz0C5J2gL+ow2iMN50lBC1DSd7r8 A74g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756275368; x=1756880168; h=message-id:date:content-transfer-encoding:mime-version:comments :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=cObXSdsdwRneT56NK2w4Ykngh3AUZwrsdoF63HqEVGo=; b=SZVaNuCUWh3cMNTCbcZV9evM1dbZMtdA8fjdtHeUZlTSi4HJiUUforyUJjL6+3Jamr pJpchFUsCX1umN/2SQXSHrVKvM91lWTpeivWP4YFVr86o5V1S7KpWIFgwD+px3ZJP1Wk XxObhRYXdfjJMOhZAp3ZYnZuHx71bHgsb1gEU+eHEYh6UpWjjRutAMhpbUAkk616Nbar Xteb/3ySxNN2eIdyCS79SCJ/+a3MDPfq4nkomglHsHuZ31W/454qgecypumeEPTqGYSh viZ2T/lFIiR9tfB5GzW/JgpowJFMzamVv6/yZCqBIQPJOJmbrX7Eg8Cm482f4ZF47CVJ AZzg== X-Forwarded-Encrypted: i=1; AJvYcCVtc4JDChU8J4QWkLtE/ClWDYrA+vrGCk1SiYrUUv8CY8W296BLY1tRT6UukF8LUDqh7VQe9nVCFY0wem8i@lists.postgresql.org X-Gm-Message-State: AOJu0YwnIef9A93vs6OR+Mcx8aYhkPz798o5kDUvXtMZCcVvbW+Rf0vr JBNEsM81FVt8Mkv70waCc3r4cVz5LtIN2M6w60NmmsUtDNgFWF/SihUoc9UO9epzM4s= X-Gm-Gg: ASbGnctMEfo6tfa/tUU23T1u/483Ovn2VRyIP536nHRoTJ7/ksWJh8WJPSt0oq7vIKZ xP508yEmWe79lze5kEFlpTTnPRzP/aCbOSyNmdltaYIHehelwcNZ6L3tEhasVZlTJkFMGFq72Dj aSM/4dGGHIio5tWngAm6zQcKsonZVbZL7f4QGk7Wzml/ljCG+zvLP+TjeaiAAwPPcdpBP3vaj8t SEWsL5iCwwhz2M0YoXDIwZ9TuIvlPOmtdFqQtwwPoeYOXmEAfXaYM0bVkBWytBdP+DIC6EVxwDc +6xY9EGvNHW5rU3ojNzmSn0dIIV/hRGLzAxcf+VhUjkq4LTWE5YP3vWstslGB0YhrXWkGyzgmi4 eyC6VZPaXRzDAbsfi5TuN4RUKBCpYFYx8v5cU+S6RTVIEl8k= X-Google-Smtp-Source: AGHT+IEuiv0vEktwOROW7lh6JQ0fdQJceP3DZsdOil22PiD6k/vuKZCJMN+H/HwgOb1U7PrciX303A== X-Received: by 2002:a05:6402:518d:b0:61c:3c58:7128 with SMTP id 4fb4d7f45d1cf-61c3c587537mr9569854a12.18.1756275368368; Tue, 26 Aug 2025 23:16:08 -0700 (PDT) Received: from localhost (109-81-168-144.rct.o2.cz. [109.81.168.144]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-61c316f503dsm8449413a12.31.2025.08.26.23.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Aug 2025 23:16:07 -0700 (PDT) From: Antonin Houska To: Mihail Nikalayeu cc: Alvaro Herrera , Fujii Masao , Robert Treat , Pg Hackers Subject: Re: Adding REPACK [concurrently] In-reply-to: References: <202508091333.qvgvo7ikuezm@alvherre.pgsql> <40729.1755799624@localhost> <9536.1756127358@localhost> <21931.1756136535@localhost> <24483.1756142534@localhost> <4790.1756197960@localhost> <29527.1756215093@localhost> Comments: In-reply-to Mihail Nikalayeu message dated "Wed, 27 Aug 2025 02:38:00 +0200." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 27 Aug 2025 08:16:07 +0200 Message-ID: <6931.1756275367@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Mihail Nikalayeu wrote: > Hello, Antonin! >=20 > Antonin Houska : > > > > Where exactly should HeapTupleSatisfiesDirty() conclude that the tuple = is > > visible? TransactionIdIsCurrentTransactionId() will not do w/o the > > modifications that you proposed earlier [1] and TransactionIdIsInProgre= ss() is > > not suitable as I explained in [2]. >=20 > HeapTupleSatisfiesDirty is designed to respect even not-yet-committed > transactions and provides additional related information. >=20 > else if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmin(tuple))) > { > /* > * Return the speculative token to caller. Caller can worry about > * xmax, since it requires a conclusively locked row version, and > * a concurrent update to this tuple is a conflict of its > * purposes. > */ > if (HeapTupleHeaderIsSpeculative(tuple)) > { > snapshot->speculativeToken =3D > HeapTupleHeaderGetSpeculativeToken(tuple); >=20 > Assert(snapshot->speculativeToken !=3D 0); > } >=20 > snapshot->xmin =3D HeapTupleHeaderGetRawXmin(tuple); > /* XXX shouldn't we fall through to look at xmax? */ > return true; /* in insertion by other */ > } >=20 > So, it returns true when TransactionIdIsInProgress is true. > However, that alone is not sufficient to trust the result in the common c= ase. >=20 > You may check check_exclusion_or_unique_constraint or > RelationFindReplTupleByIndex for that pattern: > if xmin is set in the snapshot (a special hack in SnapshotDirty to > provide additional information from the check), we wait for the > ongoing transaction (or one that is actually committed but not yet > properly reflected in the proc array), and then retry the entire tuple > search. >=20 > So, the race condition you explained in [2] will be resolved by a > retry, and the changes to TransactionIdIsInProgress described in [1] > are not necessary. I insist that this is a misuse of TransactionIdIsInProgress(). When dealing with logical decoding, only WAL should tell whether particular transaction = is still running. AFAICS this is how reorderbuffer.c works. A new kind of snapshot seems like (much) cleaner solution at the moment. > I'll try to make some kind of prototype this weekend + cover race > condition you mentioned in specs. > Maybe some corner cases will appear. No rush. First, the MVCC safety is not likely to be included in v19 [1]. Second, I think it's good to let others propose their ideas before writing code. > By the way, there's one more optimization we could apply in both > MVCC-safe and non-MVCC-safe cases: setting the HEAP_XMIN_COMMITTED / > HEAP_XMAX_COMMITTED bit in the new table: > * in the MVCC-safe approach, the transaction is already committed. > * in the non-MVCC-safe case, it isn=E2=80=99t committed yet - but no one = will > examine that bit before it commits (though this approach does feel > more fragile). >=20 > This could help avoid potential storms of full-page writes caused by > SetHintBit after the table switch. Good idea, thanks. [1] https://www.postgresql.org/message-id/202504040733.ysuy5gad55md%40alvhe= rre.pgsql --=20 Antonin Houska Web: https://www.cybertec-postgresql.com