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 1uqXzK-008GBu-1X for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Aug 2025 14:15:59 +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 1uqXzJ-009yAE-BD for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Aug 2025 14:15:57 +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.94.2) (envelope-from ) id 1uqXzJ-009y7k-0f for pgsql-hackers@lists.postgresql.org; Mon, 25 Aug 2025 14:15:57 +0000 Received: from mail-vk1-xa32.google.com ([2607:f8b0:4864:20::a32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uqXzH-001lzD-1e for pgsql-hackers@lists.postgresql.org; Mon, 25 Aug 2025 14:15:57 +0000 Received: by mail-vk1-xa32.google.com with SMTP id 71dfb90a1353d-53b17531009so1303857e0c.3 for ; Mon, 25 Aug 2025 07:15:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756131353; x=1756736153; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=BAZe0v7uwkmIwjl92Zdxh4xEGXkeEr1xSCCBmuJrOoM=; b=M2skEdIhSe1tvxBgHOvfR0Y8Cjy+KBkhi4sm048fFpT1cRpbHPFyhJcdtkWAYA1Rf2 Wb8ZJI51IH88h1eWV3Ff8BBB8RkGMw7fMkJfYHuJ/1m/nXYZ3HTGIeAY05ruVG7d9Gr/ 79jOokhwzCkxULN4g0YwOg/a7m+J6c68OwUR/b6+cfWVHppV8Sc1yfCmGrr4w8yg8Z5R KZPQi5GKVDkDpwgiDY8GGICPrJHacmMGNNlXuTfQ5WlKvdDxhpChv7VVf24rSEsyxVeo u9GL+d3mM/Wu+woLkRya0LRhk5E7s3NUGbQswIAT2yBZ7rbB0s1N4BSFhSGu2Ji0F90U IboA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756131353; x=1756736153; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BAZe0v7uwkmIwjl92Zdxh4xEGXkeEr1xSCCBmuJrOoM=; b=dLAIijPJkXfok6AmFT3ZvRdSmd3JehzHGJUdQa+cx9QRLr+cHNir2T9B9ltfwBZTMD b4aq//sOt0y0rNtSUnxrupM9ealPK8dW40VVoereglV2V5XJQnEU5uSNLY+48WAjlnRx Kqjmqj+mm1wf0cnDDuE2fEDynAxslXRlYdMmQ9VnAMgue/y9/JidTcYE9NzEXg9c+LaL CfaMubgn2TY6nWCG0MefbblVpxvaWycChVMorwDiU2vc4ZWHv1Hj6Zlx04yEXAB3fei3 /PTNGajmje4M4O28LuSdbXV6KNd428lrH/bmzKtskCFeX/2kts1Fp2UKtx88+11uvEU6 H4+Q== X-Forwarded-Encrypted: i=1; AJvYcCVDAUz4MRLIbYLA0eA3o53Qma3PTul9Jc0/AyD9CIQy6ioOk4Tc+JVtqiOcDOQVBsmvL4pFvT3X3Vr/v6Ho@lists.postgresql.org X-Gm-Message-State: AOJu0YxVyQszYRAJMb3LvFy+sOWktxE/OZs2jgBsSXij72Z/no5YDUL/ JxRf8n3ukBJYvA/PdJrNeZeT+lvOWzjuzW1/Njaxj0YD5bfm4bcIYF2FdZ/2nCcAwsdN172Sszw /29j/Xm4WlK1RV6UicYHVQu3MojjdSEI= X-Gm-Gg: ASbGncsadlpmHHIhnUp3DQ8oYkeP9TvH9/shCwaUUu1vfiTEgdpVWG6/lo5sNj1XAzx 6IaoPDe2+4mvm/+FRE9fzgw9HmV7l+ZbLt3xGQPzi03YCKVV20fewyaqfQjw7bRuVvDgH3SEAXz wt2oat16xFo5awOKvg5F8mhDi3zD9dyONzYPiP5vJQi0wB3MLbEH4IvgPzFcCXYez8FvlSQ9HKp 994MWWY5J6EDxgoQe+zaMJ/TVlRsm9+lEQAA2Ksug== X-Google-Smtp-Source: AGHT+IHNriN6dS4UFzKGlWpzLrlQ4E40W/rkXuLJOm3yKlYjBb/ol5OpcZEaSkzuYA1UAqN9ZV9/GhetMSGEJ9O43mM= X-Received: by 2002:a05:6122:d01:b0:531:3981:fdb9 with SMTP id 71dfb90a1353d-53c8a2eb01cmr3443708e0c.4.1756131352880; Mon, 25 Aug 2025 07:15:52 -0700 (PDT) MIME-Version: 1.0 References: <202508091333.qvgvo7ikuezm@alvherre.pgsql> <40729.1755799624@localhost> <9536.1756127358@localhost> In-Reply-To: <9536.1756127358@localhost> From: Mihail Nikalayeu Date: Mon, 25 Aug 2025 16:15:16 +0200 X-Gm-Features: Ac12FXzfmJpYPYBXpke9p4n9kDT6fj99T49WyBoA4knaryvafzq4PVjTEx5DsB4 Message-ID: Subject: Re: Adding REPACK [concurrently] To: Antonin Houska Cc: Alvaro Herrera , Fujii Masao , Robert Treat , Pg Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, Antonin! > I assume you are concerned with the patch part 0005 of the v12 patch > ("Preserve visibility information of the concurrent data changes."), aren't > you? Yes, of course. I got an idea while trying to find a way to optimize it. > Not sure I understand in all details, but I don't think SnapshotSelf is the > correct snapshot. Note that HeapTupleSatisfiesSelf() does not use its > 'snapshot' argument at all. Instead, it considers the set of running > transactions as it is at the time the function is called. Yes, and it is almost the same behavior when a typical MVCC snapshot encounters a tuple created by its own transaction. So, how it works in the non MVCC-safe case (current patch behaviour): 1) we have a whole initial table snapshot with all the xmin = repack XID 2) appling transaction sees ALL the self-alive (no xmax) tuples in it because all tuples created\deleted by transaction itself 3) each update/delete during the replay selects the last existing tuple version, updates it xmax and inserts a new one 4) so, there is no any real MVCC involved - just find the latest version and create a new version 5) and it works correctly because all ordering issues were resolved by locking mechanisms on the original table or by reordering buffer How it maps to MVCC-safe case (SnapshotSelf): 1) we have a whole initial table snapshot with all xmin copied from the original table. All such xmin are committed. 2) appling transaction sees ALL the self-alive (no xmax) tuple in it because its xmin\xmax is committed and SnapshotSelf is happy with it 3) each update/delete during the replay selects the last existing tuple version, updates it xmax=original xid and inserts a new one keeping with xmin=orignal xid 4) --//-- 5) --//-- > However, at the time we're replaying the UPDATE in the new table, the tuple > may have been already deleted from the old table, and the deleting transaction > may already have committed. In such a case, HeapTupleSatisfiesSelf() will > conclude the old version invisible and the we'll fail to replay the UPDATE. No, it will see it - because its xmax will be empty in the repacked version of the table.