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 1w5V1h-003JMQ-24 for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 20:40:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5V1g-00GNjz-0T for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 20:40:28 +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 1w5V1f-00GNjq-2p for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 20:40:28 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5V1d-000000018HN-2CtE for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 20:40:28 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-486fb112c09so3017365e9.1 for ; Wed, 25 Mar 2026 13:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774471220; cv=none; d=google.com; s=arc-20240605; b=fqywQjc7BKQH5ugUVFSrEgx+Y/4QbK/m50nKDpd98WFYfBUEe1t74YWzAHPv2mri3N 1Qu5L0bjozdslKxy9lIXu+I3ey0Wm2iVGhtT1PXQlSAEm4huA6io5Czrkp5b5IcrfXEy aInYNaqigXpZlGgdZweEK9b1/9UqXF0CJ0OkE+rrXtD0sl6jIiCn3vQJD7w4De5YoWxJ 2IAQBKCtu4hOP2M1cLv+7ME7F0TWSGfLrLBLFdkpTMZlIytnY+mjiE3AI/nPsu0voCjh SWZ5IgGbApe60gMgjr8ZVM+S3ia+IkYM2PDxtCxFfUgkCpzPofipsj/Hpc+/Ls6F/qzt W2DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=Sr/wVH1gX9KkQrEUV9Abi25FmmrTJswQJtpecwtijfs=; fh=qD0veLTdIso5/FfUyV8M2xOQLDlYV7xCFOKjwNeW6+w=; b=dFRh2pR0otJ5o+Cvf4A4NB0oZhs0Q4DLAUEdWBizpvZUkkYn3cp8kxFNoKYPGjJL+d 3LRtBpc9h9fRZCTL8SzDoTNofhSpWcM+nZDqfiHwcQZIqmSYxlDi+4YsQXMJqJMGiVEo 1PKuzs0aNhULppIuD3o/fVDzvghaoOmjPSKqV4BXyXKik/m4d2Jf2M9vdkOxWiJCDCc6 On5TKP1gUTEivk6rPQmAOWx0Smx8gHQ2DJas0AgUR+9I/jxX39EZjD/+Zkc/CifO4S8k o6v7mj7+hXd82lJ4fL07Ep97mYZ9ZsrYkbAPb5Tk9wvhj2VbczZxNRIy/88zgKDMI3zt oBqg==; 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=1774471220; x=1775076020; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Sr/wVH1gX9KkQrEUV9Abi25FmmrTJswQJtpecwtijfs=; b=I2KybhGOgy0gwV7ml1I57XCOeAFYYxpwk5EUdewzxbRDwwRg9KVGnRaEEZ6bmKR4cZ wJJWahMPBKgOv3TgTUQEBOp4/Gdo/TRShHEO2r6Y3+Oe6L3IlmlF4X3W1LrB+VFolHNf jwvlCAz/DHjlaOb5eScnFruM92ciuKVIe8G8GAIPK2SME/7xcKwvBHq7uCROZ+VkIHpB QY7dBGwcO8nYj6lRaE1oSHc67G7aikE4d36Th6xZM8PexL8DLReg1TZLaHTMXCXXE+eK fJPIEsj5ucXznzmVzxW3mR97HvxmBLIOlcPfzhCRSrr7jVPm5MZPCui0VuArXvQN9Yxi s0Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774471220; x=1775076020; h=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=Sr/wVH1gX9KkQrEUV9Abi25FmmrTJswQJtpecwtijfs=; b=DQ21HDhV6cL+EoivER5Md5m/S+rLukSjQjVAd8H843QoTA69fWhr9ibSm5P8vdWacD WVT8pCzKrWtjf+aon85E4jfD2aZqXf+/+rdhsETbmbXzGV0WOxnaAsY0ts6WKcu7qjZj fH0Dt+laUSCXGmVH9dwoM7Rx8AURwjzNHH5mQVWPi4z+VeVi5rKzSbp7V/hpGorTLayE ZfIkYnhDM/i0OmCe8FkscnXEq0f3JGh516yH6h07iTMFZvC64uocPEfjGilvtx02cGfo n/iNJZFrHqI6OeHwXCkq3Wn/DjZLbixQmU8WbedPdlMtECViguDqUywzNUj4bvpmJePV av4Q== X-Forwarded-Encrypted: i=1; AJvYcCUQn3KCrNLGPp1ECIQV1f5+Wo9SKzkKKDwrqs7iJOHVlyj+2wZYI3lm2KqC5RMHS5SI2PYVxA5hcu7DpOWw@lists.postgresql.org X-Gm-Message-State: AOJu0YxDUZAYRTPvsCcHCByJco14DJD3Bx9zTf8KVcg04MsxzbrjnovU YMwobzrI/uJ6Pyltm+q44Z2ovZ7teOpZ7dF5dxlVuJudMedfpH/t3TkpkNq64nfDY7/jrVkvV4J g177kJu4aR+rq9GHgwznk0iSxIl8WyjM= X-Gm-Gg: ATEYQzyNBwopP2lJTXyro4lQvPq2SxFcteQGMZLC6XOfj7gHfRB5Lg3OsyfXWrl9NAP qfniXMcl6Gg+Hzo/5AEBgf15GeTTPjZikV+uYd26M7GBJfVOGfUTsuElVwIJhyX5SQzRM3E5nTF 16NR+RiZIL7jVkTPKPaafgKXYN2kIDq3UxC/+KdBTnrJuBTWh8PsCAkE+hxJt/R8Fd2G/s+5Kxy 1f4e19OkB54khKTyd2GDMyjOQVdJnYZ3nSCdMAQGGlFXJSaTZeHWUKwVjYhQJKjOLpjeDQqvZpT 96noqAEGIq/0xjctlq7BtpnlBs7O359EN+vOTRPXTJtomvaG39E/eFliBmdm5kr7egsfv5AJ X-Received: by 2002:a05:600c:1e8f:b0:487:55c:e0c1 with SMTP id 5b1f17b1804b1-48715feab3emr75319435e9.14.1774471219925; Wed, 25 Mar 2026 13:40:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Thu, 26 Mar 2026 09:40:08 +1300 X-Gm-Features: AQROBzD1V1178ZmvEdOjdebg9Q0VTB9FoJMUPUDhDceZU5Lz9V7Maa-DN2gQ7s4 Message-ID: Subject: Re: SQL-level pg_datum_image_equal To: Matthias van de Meent Cc: jian he , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 26 Mar 2026 at 03:46, Matthias van de Meent wrote: > Attached is v2, which adds the new function to the docs, in addition > to rebasing the patch onto master. In [1] I was looking into reported bugs with the datum_image code not behaving correctly. It turns out this is due to hash_numeric() using the wrong PG_RETURN_* macro, resulting in it not correctly sign-extending negative 32-bit ints. I did some analysis to see if there were any user-visible changes from fixing that in the back branches. I didn't find any. What you're adding here would add one. I think we might need to become more strict about using the correct return macro before we expose this stuff, else it's going to be a rather scary process to fix bugs when it could affect the datum_image_equal result. The thing about Memoize slowly finding all the bugs in the datum_image_* code is that we're free to fix these bugs, as the use case (the Memoize hash table) only lasts as long as the query. If we expose all of this to users, then they could persist things in tables. 6911f8037 fixed another problem that resulted in the datum_image code not doing the right thing. I also proposed a hack in [2] to fix the sign-extension problem. I had hoped that might be temporary, but if we were to expose this function at the SQL level, then I doubt we'd be brave enough to remove it. Consider the results of the following 2 queries, which only differ in that one uses a materialized CTE and the other does not. with cte(hash) as materialized (select hash_numeric(n) from (values('1234.124'::numeric),('1234.124'::numeric)) n(n)) select * from cte where pg_datum_image_equal(hash, hash_numeric('1234.124'::numeric)); -- wrong results with cte(hash) as (select hash_numeric(n) from (values('1234.124'::numeric),('1234.124'::numeric)) n(n)) select * from cte where pg_datum_image_equal(hash, hash_numeric('1234.124'::numeric)); hash ------ (0 rows) hash ------------ -612512148 -612512148 (2 rows) This would work correctly if I pushed the patch in [2]. But as of yet, I'm not sure about it. I at least think we should delay doing this until we've come up with a fix that we're confident in. David [1] https://postgr.es/m/CAApHDvrRR1VOk4i4CpNWeL48veFshfRAvDTuWxsiUhUqo0akwQ%40mail.gmail.com [2] https://postgr.es/m/CAApHDvreF-UiqBaHtRTQWQ6z1X9snstJW%2Bdfb2DU5GOb-uPEBg%40mail.gmail.com