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 1w15zr-002YUn-0t for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Mar 2026 17:08:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w15zp-005OgS-2M for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Mar 2026 17:08:22 +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 1w15zp-005OgG-1O for pgsql-hackers@lists.postgresql.org; Fri, 13 Mar 2026 17:08:21 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w15zl-00000001z4w-2pQA for pgsql-hackers@postgresql.org; Fri, 13 Mar 2026 17:08:20 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-38a2f92fab4so21909041fa.2 for ; Fri, 13 Mar 2026 10:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773421696; cv=none; d=google.com; s=arc-20240605; b=AN9nP7Yu+jNpWHDok2YwbekpyYFBD4DASes9rTh1JxyTX+o3APKf+JReh2aAeF8Qhq Y9Nrpfme4SB9y6YwUbbt8wif6At7glRXxkyJOoJDHJmi22THL/bHfPIHz8i8QGAlA1KH sk220prAKNFczA5sf3qoWPgLjsVZwC9jDAAfDvGopGSJLVNBXcSdn1axDvQk09Q16+Y2 cCcXP0FzDc2lFNmYSYm3xrySfJL6cjpT1OEotqMc0kUxKitwbDYyEqZWFRggcwx3Ytwf JzN/qF6DCV8MMQnT6jgbMJrf/WKiBlpcjWLe8pDlRPxaCk38dI65CNeJSXkV4k9WRWI1 3TYw== 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=1aSaUlVIkYq1NzmjvuI3sQMmZS1c/V5pjHr1J+qV1sQ=; fh=/qyGI373L4QqYaJCGDYzN/J8B+aK1IbGE6d/gT0zZfA=; b=YVilGbxZTVcr//DIPJzNdAkJLKsHF17GpIBTXX6ptPh9mS+O2f4HIeXNUSFI3uRg60 NH9/c7/Kvydg8Ggqhq+bii/s6THZ/VZwZfMnG5aokscE2KD5lmxVIJxqTGYldHMcl1kk 5FbCKWhpTISLQk4Iv35PkTdlJ0l9NmsLt7HAPl3uFbs2XdixFyaQWCP5ZHvcAck9e7/I ybZL8baRDArEz38duKooVcOgbIBre+EuhMfNPjB6TQKW9TOoK9tNaD+JBZISjgluV0Rf riqTsB6mLgCbQVdXAOBVCxUJ7uhovifTKA3SVe9exQyNfGB8oPhvFiyvIkiRcUqSiO+x nhEg==; darn=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=20230601; t=1773421696; x=1774026496; darn=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=1aSaUlVIkYq1NzmjvuI3sQMmZS1c/V5pjHr1J+qV1sQ=; b=Mf5qqGr6OWPTi+oKEz3N5rhtYFFHgZxb+IscAJygnxKNcYPw25+0r6ddPQlKAj4VKc HlPTBnEfKpQoGaRABYX3h7HXQSawfi25V53NOzI6sNla7SFmgutP7OXTmCfw5yRncC3I 4ERsxgo7vj+Mkghu4szYeTsO4v7tzj6fZhU6/JsVaT4gxdhoMa2J8VwEwyTjFNmtvrjE QG8a6IxxkVLuOqxoWLqzVhFeu1PxnC1/k6PxG0pHAKkWp7O6D4KKHOMoUWxGiondc1d5 db/TbJfYuz/13aJYngAm/GNXOEs4jVOitJNNSYqaMsfBfz0Kc9DG7nzWEWtMD51D34ZO mYrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773421696; x=1774026496; 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=1aSaUlVIkYq1NzmjvuI3sQMmZS1c/V5pjHr1J+qV1sQ=; b=UHu0CDDsLtH0Ge6u6DoleaXGwK1U6Z49sOB5Qgq5NJR8s2xBickOHFWS22+sOZK+Pu FSEY3/bZjyS+W3BG0NHFSC86uLBuGZ00UrOuoexbJb1t+1BGtJQ0sjtnVSRVbjCNs0NX mOCVTtu5oZtN0sapqldVVbDJ6IOOkEeRkJ27aK/AmynNqg4ERF8qXr2ppbwWmIfPRopQ EFYJ2UjzcFV1DjXxRZhbgPtHCiz3BptDCTll2oGuOiJBoV5cqudlv/5ug6o5C5kk1bTN RG/t5+tfpwODe3nmUuz/cnTlU7SME7WHq2hokBQcm2x8u4P4mpq5UNN+MmR7ogyJzZRP 1t1A== X-Forwarded-Encrypted: i=1; AJvYcCWsYKFWWwJwGa4ETkPaw8BwxZtspFy5vdVfo9qqVj11hlfq0dZD9G4yxkdXqTJC/9Jyr4pvAdIOVTNZOwzX@postgresql.org X-Gm-Message-State: AOJu0YyAiQ0GE526TRdCAjTmk5u9qh7pHAEHvxhEmq79aVnAsQ6DBSYE ywklwPuiagSmDWV/cqUVovZ1WYhQnBxoQ77VSpzGrsQjlwCqQzRg1XFyvJ3zSEBC6RezZcdJ6Qf dMzIECO2cijlsBzcCpEEkI5d/wATUbvk= X-Gm-Gg: ATEYQzyhQAkCbOyEy7DKUBfWmyzX85k2whqrigIySs5BD1flq99iQUjAvb9CGzsljmt L1z+sh+iy4R3nKJgYOp0gTlUvUNCfwkPzxEKNohyKY+G/kvQ6Psuzr/UfqxaVyWucg5GqobjfiC B8DcnmoFNy0FqyASVYXolXQsmQVqC3yoob1F/v17uqR9ZNoyZUSCXgPAHApiL5KYxK5xaAWGzk4 47HHSTiKTarjooNiFAbBax2j/gmSGRgIEzZrX1KfECCZcQcJ8VFEXeCobSv4iL3Y8M2ujElMZmk cNTHymdb+m32uNUcT2r0FGv78IXO6My7ZiU2zIBle1fC4ZFwolYYzVgRQxG3p0DCWecXxAFEFcu yi1Ee X-Received: by 2002:a05:651c:4406:10b0:38a:5478:4526 with SMTP id 38308e7fff4ca-38a8969a3c7mr11137571fa.12.1773421695728; Fri, 13 Mar 2026 10:08:15 -0700 (PDT) MIME-Version: 1.0 References: <8a2e78c3-2f63-455f-80a9-cbd9eebaa245@eisentraut.org> In-Reply-To: <8a2e78c3-2f63-455f-80a9-cbd9eebaa245@eisentraut.org> From: Matthias van de Meent Date: Fri, 13 Mar 2026 18:08:04 +0100 X-Gm-Features: AaiRm510vFZVxMLYIKPQ9jxDv7_VPcPXuEcv4SQag4GBtzDFoAaeFodrAvOjTis Message-ID: Subject: Re: tid_blockno() and tid_offset() accessor functions To: Peter Eisentraut Cc: Masahiko Sawada , Andres Freund , Ayush Tiwari , pgsql-hackers@postgresql.org 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 On Fri, 13 Mar 2026 at 14:27, Peter Eisentraut wrote= : > > On 12.03.26 17:51, Masahiko Sawada wrote: > > On Wed, Mar 11, 2026 at 2:50=E2=80=AFPM Andres Freund wrote: > >> > >> Hi, > >> > >> On 2026-03-11 14:48:08 -0700, Masahiko Sawada wrote: > >>> On Fri, Feb 27, 2026 at 10:59=E2=80=AFAM Ayush Tiwari > >>> wrote: > >>>> > >>>> Hi hackers, > >>>> > >>>> As of now we don't have any built-in way to extract the block and of= fset components from a TID. When people need to group by page (like for blo= at analysis) or filter by specific blocks, they usually end up using the `c= tid::text::point` hack: > >>>> > >>>> SELECT (ctid::text::point)[0]::bigint AS blockno, > >>>> (ctid::text::point)[1]::int AS offset > >>>> FROM my_table; > >>>> > >>>> This works, but it's pretty clunky, relies on the text representatio= n, and isn't great if you're trying to parse TIDs outside of SQL. > >>>> > >>>> The attached patch adds two simple accessor functions: > >>>> - `tid_blockno(tid) -> bigint` > >>>> - `tid_offset(tid) -> integer` > >>> > >>> How about adding the subscripting support for tid data type? For > >>> example, ctid[0] returns bigint and ctid[1] returns int. > >> > >> That just seems less readable and harder to find to me. I think it'd = also > >> make the amount of required code noticeably larger? > > > > Yeah, using the dedicated functions would be more intuitive than using > > magic numbers 1 and 2, and require less code. > > Also, you can use one-argument functions like field names, like > tid.tid_blockno, so it's definitely more intuitive that way. TIL. As for naming; I'd personally prefer to have 'heap' included in the names here (e.g. heaptid_blkno(tid) or heap_blkno[_of](tid)), because not all AMs may map tid.blkno exactly to a block number in the main fork. While PostgreSQL (in core) currently only knows about the heap AM, we should probably keep clear of pretending that all tableAMs produce TIDs that behave exactly like heap's do. Matthias van de Meent Databricks (https://www.databricks.com)