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 1vXP4h-009RVF-0Q for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Dec 2025 19:26:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vXP4e-00CFi7-0u for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Dec 2025 19:26:37 +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.96) (envelope-from ) id 1vXP4d-00CFhy-2u for pgsql-hackers@lists.postgresql.org; Sun, 21 Dec 2025 19:26:36 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vXP4b-001x1V-2f for pgsql-hackers@lists.postgresql.org; Sun, 21 Dec 2025 19:26:36 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-37bb8bef4cdso32845411fa.3 for ; Sun, 21 Dec 2025 11:26:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766345192; x=1766949992; 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=fwJkgnBsBEx995lnIDw9OMrK3itlKHN/sRAwiztwQ1U=; b=mjikn3/8uQGG+DNkqwXyPsNLzPH/1i0jgVaoIaFmrgqQnJoWF0/R0+9p2C+E9IC4Ls QNUaTFaBPZKoFsss3uoM970odreX9eAF4OfmfQzKYQcSRlrLyjb8HQIbAS2+hojEyUTZ qJDl6BNK8LiDoJbV8hRjkjg2ctXbElwMAisHTb9j2QMSO0mfohyEPjW2wlU19C/PWtBE xZZZRAFoimIMoTVuoQZAZ4cxxDwL6a10JPWpuBDtsSs8lfwMq/jYhP+/t2huRPtis9Y6 mOEslah5alMtDOKKGg3p6hDgARIs56CrJ5q21xeDSd4K6wT2XNzWVSjgxaPZolps3Vvx hU2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766345192; x=1766949992; 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=fwJkgnBsBEx995lnIDw9OMrK3itlKHN/sRAwiztwQ1U=; b=o2as5z7qrHlVGuF9bHcIRNLnI+trdjwdp5duJ6LDArUchgKqFJPfFalQukIOB02D9j cwHKIrFULhxL7Jbqk+JU7FGCx+U9zFMwFfj9PrzCLtHchLD7QugpYWthcOZFSda42Van ICxpjNANSemkQXgFXbmXpz9zQosB/bS4IsEf/GBVvcBBNCq7rh13f1RjOaM/am1h+87t Qy6ardas3wtjZiUCWpaBttfjPZ+v08kkNynrsoJE3O64M1iFtIaxMTDh+GpJq78NB+H1 DeYILeEuLBsuB++INrL0tKfi+tIrRR0/83wzszzI1SthXT/uDH6yIMu6hZN8dtfIGEe5 e19w== X-Gm-Message-State: AOJu0YzRnFcn9ZzWZ19ZMdP2xpTSyG4lEX6+J03QP+OJAnTixaGszjLo dzsA0MiHb6N/LJIkgS57SEUrCwVJQKk60Ke9jAB91s/lYXmyypDKUPfYP04c/XCz0MWc8UOWwYP EqW8W6cJ6biMKjUd4fRCJXUgIDrjwgbw= X-Gm-Gg: AY/fxX6zLQfYXVgTbbj2WZHA4M3TaKDCDv9UF8iPeqAAx6d6f22Y81tWw5ugSSlKTDa 3XsOKbm1yOY7iM/EXA8JVwwxudugBJvU6b6lrsVKFNT7Zk/qCvBV0RoVMsJH77tZhiedjxWpIqY lxMYSBbvgmUgBhXMcjgXrwJuKB6z0dVuZiIbO6tpHNNyuOIwRyfaQV82pLX6uJfoBp0zHNxZlON sCimJjElr3XDDNxh1nFo5agw6gU20vpDQo9DRedzPUb1aAakdxhv7hQg4AOsYVs6kjtrT8E+i3+ rkUMUnX9Qw0fMDLMkLFn8IqBaA0ZTujtc/OJ7mHACaHjfegC7lctGXR+iy6zYjz+In3DxEuJhcl MtB0= X-Google-Smtp-Source: AGHT+IGGrbZ+EKeQT7GeyU7pl7OJTdnwdU8lFxjyScKgOjx+chbwegO7+WPkl+kSVemZF+C+n3Xu2+OM9kfk0z9rQpE= X-Received: by 2002:a2e:b8cc:0:b0:37f:d65c:a825 with SMTP id 38308e7fff4ca-381216cf873mr23381921fa.39.1766345191796; Sun, 21 Dec 2025 11:26:31 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Matthias van de Meent Date: Sun, 21 Dec 2025 20:26:18 +0100 X-Gm-Features: AQt7F2qlSgrhzBPD074FTCNzwYRC77pL2-QIWK72F6ZwaLqIQswFpntsZiSGiEE Message-ID: Subject: Re: SQL-level pg_datum_image_equal To: Corey Huinker Cc: PostgreSQL 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 On Sat, 20 Dec 2025, 17:07 Corey Huinker, wrote: > > On Wed, Dec 10, 2025 at 12:46=E2=80=AFPM Matthias van de Meent wrote: >> >> Hi, >> >> One of our customers has this workload where every so often they >> update the whole table to make sure it's up-to-date. In general, you'd >> probably want to use MERGE for such a workload and ignore all rows >> that already have only matching data, but there's a catch: PostgreSQL >> doesn't have an efficient way to check if the provided data is >> actually equal in all senses of the word, so we can't easily and >> cheaply determine whether an update is needed; which is one reason why >> the full table was updated every time. > > Have you ruled out the suppress_redundant_updates_trigger? Thank you for the reference, I wasn't aware of this trigger. Sadly, it does not work for our use case, as that only suppresses an update if the heap-formatted rows are binary identical, which is not guaranteed even if when all values are equivalent; as it doesn't take detoasting into account. It also doesn't minimize the pressure on the TOAST table, which is something else we're trying to do with the new function. The issue is that when you SET a column with a user-provided value, during trigger handling, HOT checking, and TOASTing, the binary representation of that user-provided value is the untoasted version (as it has not yet been inserted into any toast table and isn't represented as varatt_external), while the original row's value may be a toast pointer (represented as varatt_external). The checks in trigger handling, TOASTing, and HOT checking, the old tuple's value for that column (in its varatt_external representation) is compared against the new value (as normal varattrib_4b.va_4byte or varattrib_1b), and those will never be binary equal - their first byte is guaranteed to be different. Only if the value is pulled directly from the original column will the original column's TOAST pointer be used, and can a new toast table insertion be skipped (after which suppress_redundant_updates_trigger with its in-heap-row compare option might become useful). But, lacking a system that checks checks whether toasted values actually changed (and thus whether HOT applies, and whether an update has to happen), that trigger isn't up to the task at hand. Kind regards, Matthias van de Meent Databricks (https://www.databricks.com)