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.96) (envelope-from ) id 1vWSqG-001kFU-18 for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Dec 2025 05:15:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vWSqF-006CGo-0Q for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Dec 2025 05:15:51 +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.96) (envelope-from ) id 1vWSqE-006CGg-2j for pgsql-hackers@lists.postgresql.org; Fri, 19 Dec 2025 05:15:51 +0000 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vWSqD-001Rxw-2q for pgsql-hackers@postgresql.org; Fri, 19 Dec 2025 05:15:50 +0000 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-c05d66dbab2so1440271a12.0 for ; Thu, 18 Dec 2025 21:15:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766121349; x=1766726149; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=jSxCKaw1jKR0SJNbPfOIx83QumDCh0iLLBA1ItfabjE=; b=IE1uNQo0IOZPYr1GNHavxL030FoWWe8fJZfv2yBzoqo39FbPIuUZd+8PBmRtF27C3f YkE/B0Bn1AdvfHDR+zb7e0q0Js9FFmyZz4o+t5MwyGpRv44NgsXW2/Wi6spE9qFOMriP WIE7iHxAwOm8wKVZ9w8HLcxIKwBg/vcqssmCql3lb+JIXiqHOcXqXf6aHLkf0YXThYBe 8X7afh1S9/IVGyZjYSJ46Yu2KCVIdUyoA3F1zgDaepNN72rBdok7sWDbksFq3qvC+q0S B1iOEmHH/VuAgJ7lGje0pPyBPpqEcB4MxaQ5Tc61NH4hLr1RYucvq8HCn2FGYo+yv2dK KmXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766121349; x=1766726149; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jSxCKaw1jKR0SJNbPfOIx83QumDCh0iLLBA1ItfabjE=; b=TYAdaWbVZ7zB29A4m/ZMbJdl9n1x69/X6H9wLOKvptxeFeg2lAG5HCc66M+CaRWZDZ I0QGPP2PKaymjX4k+H4a39N6PGC5/8NRgT7mTHjZ6JczfRas3lV7Z25ZRcUs1n2A+vNg mxP3XP9+xbTyXycIN/CtB13zh7ltPqX3PZ6ncC/b4UUqCKcyqdM07F/TKhyBcKrlssWy q9GjBCxCEsMXKOJnS1aIK3QedTnQo9eeU8nc8R5MuO5Z23+W37aMvdVN1PZIp96Vmo3r saEk3VTonymHi5IZrmPLE4CI3nhDVpHVTaPmMh5lG5hWSMO6Soo54HmP0qSwrlCTvzyo z4MA== X-Gm-Message-State: AOJu0YyxtthLTPc8d6LalrYmbg8jGcuBHh3vNb0OGajiO2cfNLpFmE78 DP6qXRx9AbGo71d1qsDgnmkSrxpvjAgPpLpUbm70gZA2g4ZLCbAziXlJ X-Gm-Gg: AY/fxX6JLW8mzTFJ+FYK3CghCvDX3GarVKgG5uZSkQcr9je+d37GXnpZhepPPude1LM N5eGFZwJAsUO7USvWO0rTkGsxz7BZILsPY0CRBw65u7DN+C9b9WXILjmjesGU/7HEMgxTdVwuGC Or5LIAU+mgGJBpjgcv/cNMlLJI7vgJ+B1zhYQp5//Il1xVBnpDtnOdgkAuGQYn6dZAj6eRLslXW dIIAqgyhax1vaxg5uTNzx8DLf35/4bqw0KoUzKimbGr4BGtaNdy1biq3wZUrgnBuuiCFbQdMOfj GTYUkATSS2KmluAF1VIhq3WyV+SuGMTzJ1yTiH2wGmNaSu7b3d/sexWFVRSqGDvKU1lh6CwVp9u dbRQudiDRhZ44I2AQ01rzgdiOWt2YmEhLzMdrBQs8MiZppVnjCM0fi7pqIa9P8ihIdh4wag4zyj mJP7velsu21UZics/Vr83m X-Google-Smtp-Source: AGHT+IFFE2hdGHCFUb99g6Nvw8zI7Kbs5yNGcOa30AE7TS4iqZNbGMiRZoCUTtLx6AgPljM/iPDSCg== X-Received: by 2002:a05:7301:c04:b0:2b0:4c6c:9fef with SMTP id 5a478bee46e88-2b05ecad97dmr1708567eec.38.1766121348474; Thu, 18 Dec 2025 21:15:48 -0800 (PST) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b05fffac8asm4083735eec.6.2025.12.18.21.15.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Dec 2025 21:15:46 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: A few patches to clarify snapshot management, part 2 From: Chao Li In-Reply-To: <08cbaeb5-aaaf-47b6-9ed8-4f7455b0bc4b@iki.fi> Date: Fri, 19 Dec 2025 13:15:10 +0800 Cc: "pgsql-hackers@postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <229C9534-5DF4-4A0F-BA02-EDE31A359984@gmail.com> References: <08cbaeb5-aaaf-47b6-9ed8-4f7455b0bc4b@iki.fi> To: Heikki Linnakangas X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Dec 19, 2025, at 07:30, Heikki Linnakangas wrote: >=20 > This is a continuation of the earlier thread with the same subject = [1], and related to the CSN work [2]. >=20 > I'm pretty happy patches 0001-0005. They make the snapshot management = more clear in many ways: >=20 > Patch 0001: Use a proper type for RestoreTransactionSnapshot's PGPROC = arg >=20 > Minor cleanup, independent of the rest of the patches >=20 Looks like this cleanup should have done earlier. The old comments says = that only reason to use void * is to avoid include a header file. But in = snapmgr.h, there already has a usage of =E2=80=9Cstruct HTAB=E2=80=9D = from 12 years ago. Maybe we can also do: ``` typedef struct PGPROC PGPROC; extern void RestoreTransactionSnapshot(MVCCSnapshot snapshot, PGPROC = *source_pgproc); ``` So the function declaration looks neater. snapmgr.h line 101 has done in = this way. If not pretty much burden, we can update HTAB as well. I believe 0001 is an independent self-contained commit that can be = pushed first. >=20 > Patch 0002: Split SnapshotData into separate structs for each kind of = snapshot >=20 > This implements the long-standing TODO and splits SnapshotData up into = multiple structs. This makes it more clear which fields are used with = which kind of snapshot. For example, we now have properly named fields = for the XID arrays in historic snapshots. Previously, they abused the = 'xip' and 'subxip' arrays to mean something different than what they = mean in regular MVCC snapshots. >=20 > This introduces some new casts between Snapshots and the new = MVCCSnapshots. I struggled to decide which functions should use the new = MVCCSnapshot type and which should continue to use Snapshot. It's a = balancing act between code churn and where we want to have casts. For = example, PushActiveSnapshot() takes a Snapshot argument, but assumes = that it's an MVCC snapshot, so it really should take MVCCSnapshot. But = most of its callers have a Snapshot rather than MVCCSnapshot. Another = example: the executor assumes that it's dealing with MVCC snapshots, so = it would be appropriate to use MVCCSnapshot for EState->es_snapshot. But = it'd cause a lot code churn and casts elsewhere. I think the patch is a = reasonable middle ground. >=20 The core of 0002 is the new union Snapshot: ``` +/* + * Generic union representing all kind of possible snapshots. Some = have + * type-specific structs. + */ +typedef union SnapshotData +{ + SnapshotType snapshot_type; /* type of snapshot */ + + MVCCSnapshotData mvcc; + DirtySnapshotData dirty; + HistoricMVCCSnapshotData historic_mvcc; + NonVacuumableSnapshotData nonvacuumable; } SnapshotData; ``` And my big concern is here. This union definition looks unusual, = snapshot_type shares the same space with real snapshot bodies, so that = once snapshot is assigned to the union, that type info is lost, there = would be no way to decide what exact snapshot is stored in SnapshotData. I think SnapshotData should be a structure and utilize anonymous union = technique: ``` typedef struct SnapshotData { SnapshotType snapshot_type; /* type of snapshot */ union { MVCCSnapshotData mvcc; DirtySnapshotData dirty; HistoricMVCCSnapshotData historic_mvcc; NonVacuumableSnapshotData nonvacuumable; } ``` If you agree with this, then 0002 will need some rework. A set of helper = micros/functions would need to be added, e.g. InitDirtySnapshot(), = DirtySnapshotGetSnapshot()... So that, I=E2=80=99d stop reviewing, and see what do you think. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/