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 1v8k0P-002NOp-DR for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Oct 2025 18:44:17 +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 1v8jzP-001uJF-3H for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Oct 2025 18:43:14 +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 1v8jzO-001uJ7-NH for pgsql-hackers@lists.postgresql.org; Tue, 14 Oct 2025 18:43:13 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v8jzL-001lFI-2k for pgsql-hackers@postgresql.org; Tue, 14 Oct 2025 18:43:12 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-782e93932ffso5138278b3a.3 for ; Tue, 14 Oct 2025 11:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1760467391; x=1761072191; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=4U2naUf0moSxomsmQlUpDV7yfaiJdntsPfoxYl+kadU=; b=phn3Ju88xQjhjdZ/hZi9ZSsTkm9R9UM443aRpzjqPPfAZZUgxlpxVqAhOAkyrSTnS+ PCaLgZzNI3nLqZlmF3jn78J21DxQeiSxJkmImmKldjlniIzB9ZKNDYfbqbgS4Hap+568 CYF/5xpNJdmZ9KQq/RqjuPQrJU9YFK2dq4eROE+/0qKzxFNphO/pqr0ZQbQ/m8zOcmgK KIXCX5O4aLD7HmePowbcc5hmZ+TREIAvzML8Qo32N6cq6FOGMZ5w03WOk6kdyfVkh6gu BGJTAvxUfhDHpScSxjjxxZ2wocDz4Q6+vmmzKHUWz8QzgTkDdrqNf12iiHWKikR+NJJ3 1Xew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760467391; x=1761072191; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4U2naUf0moSxomsmQlUpDV7yfaiJdntsPfoxYl+kadU=; b=YIqDVRs+GoRUUr7g/8kA7qPJfHLgm64F4Wn2BUaDW4RBa1y+L3GIJMbC3fU1qBJYa5 oLgfBLl+ZbJwC60yY9rNafrDwWDwOFPs888bK4wC7BfXWXjlM+F4llYmV8Y395BcyH9Q clH/WdnqAh9cr6LzhamQUpFD78mZ3KJbnSiUjNQlzk50zmeZCKtoo+mNSbDTsRvx/6CD So4KwFaVZnD3Z+8t5QCFlrw0pU9HGG0SDVOE+c+LtwTVNUJSaUkNRQi1H4ndKwAt7f2R q5E7lonmOLvRG0Zqzco1UpJJgppPbhHI9mZ45zxrSemi8H+SywWzFlBaCjJ7xPYtkdRE vvUg== X-Gm-Message-State: AOJu0YwELumv3B2wdXeIdDRY18NfXlv7TUCSsN/kbuqwoveWvUZizpGe XV8/+qxW5l8Z8EfYJJoq/PAhgszT25cAmjytp8J2RskWDAe3xqowCKiNx0uhI/iuRXTErApk0SH NELw= X-Gm-Gg: ASbGnctm05zMbJeCHqv7TpFvGhLX4CyGcbqnFo7APnKGDs/LL5T4EqrHOddfLU/UvGh qXg434AmwMKgryDzEXc/ndTLedv+SmFiSxHUVS8PWY1g7w05SNGFOrfFpg93SkgIXt6D/bV1+kW xMYYeXshx2IrERH956DA5SGuwjEqknw0O6CVceGZz1A3j5iRmmgIciJPgFWPPxHTBDXljeyxUDe 0Ppq+KiZr9IhMhEjm4Nls/tOWlRXyDACKypnPeAW0J7JfrfcS0kciJp9eJu4B5/qde6stlPA9cm tFPEonq1brWlNYWZSQ6yxDkWpZdrZs7L/zwyya1lPe9evKImPMUJu2vjHib0WYRkIcAUr09xfwV 8s5ZT8r+K9L3WXDrokYgb2i/lKF/VRtSgbBdTod227dFex/cs8Z5d2ZcWBaZRSLwaAVarRWwCGw == X-Google-Smtp-Source: AGHT+IGAD9mX163JKvhmUEMKANu2hi5VkKFm+kOKQDMHUJxGG8RoFL6KJNrde4uCfVLkonfAH/sxbw== X-Received: by 2002:a05:6a21:50f:b0:32d:a931:c87c with SMTP id adf61e73a8af0-32da931c888mr31423428637.44.1760467390706; Tue, 14 Oct 2025 11:43:10 -0700 (PDT) Received: from jeff-ws-bridge.lan (c-24-7-19-3.hsd1.ca.comcast.net. [24.7.19.3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7992db82007sm15840187b3a.77.2025.10.14.11.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Oct 2025 11:43:10 -0700 (PDT) Message-ID: Subject: Re: Expanding HOT updates for expression and partial indexes From: Jeff Davis To: Greg Burd Cc: "pgsql-hackers@postgresql.org" Date: Tue, 14 Oct 2025 11:43:09 -0700 In-Reply-To: References: <97f0aa72-f172-4673-8b04-533f022c3149@app.fastmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3-0ubuntu1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-10-14 at 13:46 -0400, Greg Burd wrote: > I'm trying to knit this into the executor layer but that is tricky > because > the concept of HOT is very heap-specific, so the executor should be > ignorant of the heap's specific needs (right?). It's wrong for the executor to say "do a HOT update" but it's OK for the executor to say "this is the set of indexes that might have a new key after the update". If that set is empty, then the heap can choose to do a HOT update. > Right now, I am considering > adding a step in ExecUpdatePrologue() just after opening the indexes. Seems like a reasonable place. > The idea I'm toying with is to have a new function on all > TupleTableSlots... >=20 > That way for heap we'd have something like: > Bitmapset *tts_heap_getidxattr(ResultRelInfo *info, > TupleTableSlot *updated, > TupleTableSlot *existing, > Bitmapset *updated_attrs) > { > some combo of HeapDeterminColumnsInfo() and > ExecExprIndexesRequireUpdates() >=20 > returns the set of indexed attrs that this update changed > } Why is this a generic method for all slots? Do we need to reuse it somewhere else? I would have expected just a static method in nodeModifyTable.c that does just what's needed. And to be precise, it's the set of indexed attrs where the update might have created a new key, right? The whole point is that we don't care if the indexed attr has been changed, so long as it doesn't create a new index key. > Interestingly, summarizing indexes that don't overlap with changed > attributes won't be updated (and that's a good thing). Nice. > Problem is we're not yet accounting for what is about to happen in > ExecUpdateAct() when calling into the heap_update().=C2=A0 That's where > heap tries to fit the new tuple onto the same page.=C2=A0 That might be > possible with large tuples thanks to TOAST, it's impossible to say > before getting into this function with the page locked. I don't see why that's a problem. The executor can pass down the list of indexed attrs that might have created new keys after the update, then heap_update uses that information (along with other factors, like if it fits on the same page) to determine whether to perform a HOT update or not. > So, for updates we include the modified_attrs in the UpdateContext > which is available to heap_update(). It doesn't look like UpdateContext is currently available to heap_update(). We might need to change the signature. But I think it's fine to change the signature if it results in a cleaner design -- tableam extensions often need source changes when new major versions are released. > =C2=A0 If the heap code decides to > go HOT, great unset all attributes in the modified_attrs except any > that are only summarizing.=C2=A0 If the heap can't go HOT, fine, add > the indexed attrs back into modified_attrs which should trigger all > indexes to be updated. IIUC, that sounds like a good plan. > This gets rid of TU_UpdateIndexes enum and allows only modified > summarizing indexes to be updated on the HOT path.=C2=A0 Two additional > benefits IMO. I'm not sure that I understand, but I'll look at that after we sort out some of the other details. Regards, Jeff Davis