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 1wSHka-0035RM-02 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 May 2026 17:09:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wSHkX-008sAM-39 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 May 2026 17:08:58 +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 1wSHkX-008sAE-1t for pgsql-hackers@lists.postgresql.org; Wed, 27 May 2026 17:08:58 +0000 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wSHkW-000000012jy-346y for pgsql-hackers@lists.postgresql.org; Wed, 27 May 2026 17:08:57 +0000 Received: by mail-qv1-xf34.google.com with SMTP id 6a1803df08f44-8b5cda2dab9so116002496d6.0 for ; Wed, 27 May 2026 10:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1779901736; cv=none; d=google.com; s=arc-20240605; b=Pwvd/xhq9I6GI43AXRT874jVbwNa8g4aeZhz/z2O8jIftOqOwyfr8/vzaFTqSups5y 2dEPWvvhSVUthZqKO/AQx2IrX/DB69rpi0sqNPD5WcO1bDWNakkZqKQXBUPsfox0o2zH l9ryIaejH+kPc2tzW504xkRNbhC4R+TiitNtjVFN0MCRTlAwNqnZCC3hRcbKC+vKMVjO Im/tN9MjtOAXGBhxXabTvW7vtYvtrMZXsQKml7X9ebjRAdMOHkutCISoJfCkgZbP2cSk TWbGjHUqrujwugV5cVb1mzvOPsbC9UjRBMkk+JY2ivq/ld4XOPiXVFwdcqtM/rwracw9 M1IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=KNnrCq9AgPw4RYG3+K9uy2HCBa/YD97ItRDNjwiLq5M=; fh=mXAR5TrBbOcUAqACeXTapJxG8ENd3O8hO5NcEdaDx6A=; b=amtX1UqdEj7IT6OZMUtKR1XVPk7w3r6qdjJ40+4m68Nx8TlzHhOUk9N9Q2Zm2yfuOM 9KKi6LATHGgCxA2UeeuA7MvgR45IP/N028g+NNwF5VgjbZHV2msV7wMVKr9WJbNCs24t dn7aTZn1TD1G+BLFrWXAjzqy7tKvmxSZIOrJKnerL/b5t27JkjqmbG3k1fufoP099nzw QYvKu1LputzltAjOMvESwf0Vl01HgsYTyCusD9YTOVoObKWAJH3m0rZwGm4Huo0pFcdl y0odqY3qeO8zVj1gwpPJzUaTMxwww8e4EXqDRvfmStn1Gs4/isUtfG6aP/zx88MiriT6 3hZQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779901736; x=1780506536; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KNnrCq9AgPw4RYG3+K9uy2HCBa/YD97ItRDNjwiLq5M=; b=qPd12OX119zZmmWJFW/yqslqQ9Zvh80rYV8XIaUW4lo9J7N3agfCfH4DeKtS9qIOE6 RH4/VWfSeLNKiN9hPV6at3nCL2HZNg7Twfrp9BmTCf2atJLkJ6e4nFnupYJb8XbCqg3w rFqIP+mKpwvW5XHg0Y/ipL7CYXdEBkvl9HdLOSfPh0Y+Gg3aZd4eVlxCgWA6DyhCYRLe LErgEqb3fDcs9pea30hK66J93afnaWqS4A4uDbl7ESNy1Fk148/QMU8XO2lwhfeAjHR1 MD+gDVl0thlUrtd5qU+dYWC50SbF2vTQofdoIoZoYR06Bdtd9BGnKJTHv1mutdRQ/ZLm qk2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779901736; x=1780506536; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=KNnrCq9AgPw4RYG3+K9uy2HCBa/YD97ItRDNjwiLq5M=; b=ZoBl0xS96KSlGroanQUTf/6bVl+qnvBfea8C7ZHVU7z2Bj7pJgX/FxIzAx3+M70ofY fdqrwnk3GZjewDcqw/JSTaKmVYnlSoU8Bqj3D9PBIt4yP71R+F1nw7+vCf+zssPGEIZ/ 1HhiriiJQ/uXBgijP4aKUGAJh64NE1R4MPn6YOm3ZyEJ9/bgYi+goJ9+OvGZKC+3toIf WcW/GM0phz8auIhMOVOYmG/RTg/BEWSIA9bvrND/H0X5ezam9u5umKmn0ejlTddPm1W6 Htw5wHxG5ecJ1sVabDyLuM/vGgZA2vktmoKcRoWXgNAZR6BgJoSfWwH1UFZ0irASgsgl YT/g== X-Forwarded-Encrypted: i=1; AFNElJ+BT8BC3mgwUfYgDu3fQp3tm8GhUGD0/LTYMwcQ7Dc415SHEok1yJ8/pNdo+FJpO3afbQUhzhQ2H04sMpAB@lists.postgresql.org X-Gm-Message-State: AOJu0YxJl8BZSlM5D7qEls8vJMc8QsVmE1h6rXkApb1Sk8ep6fdnzYeg cwf/vylFJHeeIjScvi3GipDfNpBL5x1YptqhxBuA0KYqQl0z0l6rNsNsmgeazhLthrDEvj1dc0g W8U6UZhGxwfwO2AogKx0mzYGCruNKcA0= X-Gm-Gg: Acq92OHzMXgZF0c7G+PVJtrP8CsxQ/Dp+YcTemVW6iiu8YH/Ibe56Z8jWNxrk9n+8/P 4imYg0q8YweWghj4qRkaSLSFfBuSvU/E+YA7gsTnD+XGqI4vYElqSI/USKlzu5USbObEsgBEzKN AI9o75DDtepyxA8MRu90N/RbhtmDAgoHgNOsMdA9dwFFP6JG2Hl0UkFahuX9ywaPhLuM5jqsYnF ND0W33kicFtiSGBfBZXT7w4MI1QWORnKatFFdR89TF7kGoqcT4sWXop4zQUN+Hpu3mvMPYdlfCV /IVsNgM1MNMmjGpXAA== X-Received: by 2002:a05:6214:33c7:b0:8b0:33a2:2520 with SMTP id 6a1803df08f44-8cc7be8b3aamr331323436d6.10.1779901735551; Wed, 27 May 2026 10:08:55 -0700 (PDT) MIME-Version: 1.0 References: <9697ad60-ec88-4446-89c1-dc02a3b8e89c@app.fastmail.com> <2645118.1770567884@sss.pgh.pa.us> In-Reply-To: From: lin teletele Date: Thu, 28 May 2026 01:08:46 +0800 X-Gm-Features: AVHnY4J79GSW8kaO2cNxLMJsot9eFIed5zgu9X_pD4lOqUDoD3KonK15agqWP28 Message-ID: Subject: Re: Use pg_current_xact_id() instead of deprecated txid_current() To: Shinya Kato Cc: Tom Lane , =?UTF-8?Q?=C3=81lvaro_Herrera?= , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Shinya, Thanks for the patches. I read v4-0001 and have a few small observations from going through the arithmetic functions. I tested the suggestions below locally on top of v4 =E2=80=94 they pass the existing xid regression = tests and produce identical output on the boundary cases listed in section 3. 1. xid8pl / xid8mi could reuse the helpers in common/int.h ---------------------------------------------------- xid8pl currently rolls its own overflow detection on a mixed-sign addition: result =3D val + (uint64) delta; if ((delta > 0 && result < val) || (delta < 0 && result > val)) ereport(ERROR, ...); This is correct, but it's the only place in the tree that takes this approach, and the (uint64)-of-a-signed-value plus sign-aware compare takes a moment to convince oneself of. common/int.h already provides pg_add_u64_overflow / pg_sub_u64_overflow, plus pg_abs_s64 which returns uint64 and explicitly handles INT64_MIN, so xid8pl could be written as: uint64 abs_delta =3D pg_abs_s64(delta); bool overflow; if (delta >=3D 0) overflow =3D pg_add_u64_overflow(val, abs_delta, &result); else overflow =3D pg_sub_u64_overflow(val, abs_delta, &result); if (overflow) ereport(ERROR, ...); And xid8mi symmetrically (add/sub swapped): uint64 abs_delta =3D pg_abs_s64(delta); bool overflow; if (delta >=3D 0) overflow =3D pg_sub_u64_overflow(val, abs_delta, &result); else overflow =3D pg_add_u64_overflow(val, abs_delta, &result); if (overflow) ereport(ERROR, ...); This keeps the code inside the standard PG overflow-check idiom, and as a side effect handles a delta of INT64_MIN cleanly (pg_abs_s64 returns 2^63 in that case without invoking UB). 2. INT64_MIN boundary in xid8_mi_xid8 ---------------------------------------------------- In the val1 < val2 branch: if (val2 - val1 > (uint64) PG_INT64_MAX + 1) ereport(ERROR, ...); PG_RETURN_INT64(-((int64) (val2 - val1))); The bound permits val2 - val1 =3D=3D 2^63 (e.g. '0'::xid8 - '9223372036854775808'::xid8). When val2 - val1 =3D=3D 2^63, the cast (int64)(val2 - val1) is implementation-defined (the value doesn't fit in int64), and -INT64_MIN is signed overflow (UB). In practice on two's-complement targets the answer comes out as INT64_MIN, which is the correct value, but it relies on UB. Pulling out the boundary explicitly keeps the same observable behavior without the UB: uint64 diff =3D val2 - val1; if (diff > (uint64) PG_INT64_MAX + 1) ereport(ERROR, ...); /* diff =3D=3D 2^63 maps to INT64_MIN */ if (diff > (uint64) PG_INT64_MAX) PG_RETURN_INT64(PG_INT64_MIN); PG_RETURN_INT64(-(int64) diff); 3. Test coverage ---------------------------------------------------- The regression tests in xid.sql exercise the positive overflow side nicely but miss a few boundaries on the negative side: -- xid8 - xid8 at the INT64_MIN boundary (#2 above) select '0'::xid8 - '9223372036854775808'::xid8; -- xid8 + int8 / xid8 - int8 with INT64_MAX / INT64_MIN deltas select '0'::xid8 + 9223372036854775807::bigint; select '0'::xid8 - (-9223372036854775807 - 1)::bigint; select '9223372036854775807'::xid8 - (-9223372036854775807 - 1)::bigint; It would be good to pin those down in the expected output. 4. Documentation ---------------------------------------------------- v4-0001 adds four user-visible operators but doesn't touch doc/src/sgml/. pg_lsn's arithmetic operators are documented in datatype.sgml around the "pg_lsn Type" section -- it would be nice for the new xid8 operators to get analogous coverage in the nearby xid8 paragraph. As a separate observation (probably better as a follow-up thread rather than expanding the scope of this one): xid8 currently has only hash and btree opclasses, no BRIN. Since xid8 is strictly monotonic and never wraps, BRIN minmax looks like a natural fit -- I'll raise that separately if there's interest. Regards, Teletele On Mon, May 25, 2026 at 4:10=E2=80=AFPM Shinya Kato wrote: > > On Thu, May 14, 2026 at 9:31=E2=80=AFPM Shinya Kato wrote: > > > > Rebased the patches. > > Rebased the patches, again. > > -- > Best regards, > Shinya Kato > NTT OSS Center