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 1wEhxE-004JZa-1S for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Apr 2026 06:17:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wEhxD-0011Zw-24 for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Apr 2026 06:17:55 +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 1wEhxD-0011Zo-0Y for pgsql-hackers@lists.postgresql.org; Mon, 20 Apr 2026 06:17:55 +0000 Received: from mail-japaneastazolkn190110001.outbound.protection.outlook.com ([2a01:111:f403:d405::1] helo=TYVP286CU001.outbound.protection.outlook.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wEhxA-00000001sbc-45WE for pgsql-hackers@postgresql.org; Mon, 20 Apr 2026 06:17:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Q0zCAFOgdQC262tE2EoBbi2GMWFX0yeNlSFHuXRPPMQUD0EClAXG7VaZ9mt4MQebY8WsoUPjuGbvR9dgt8wfmPkpK+/5XS1mxIu1hG0iPi6gWQUS8NLLhO96qJ9XuqbcW0F2gBJQA70n/I4jSgMH+2FCQQ+XgfRwI9lJhtwuJxX40/bL7OcGIxqtjoDRkDAVVasibgpwMTkcoqf3l2OGLSgaEHPfybWlSZFiLMhj8AHf1Ls5QRP8LyvEUQcbdkwFTDIxXcfdR4SKiP63Ve+hSvxxXoMIadl7Dmd8OG9n13fYLrO8LFthWF3YUcKWBpuTSTSSC3TgGdLhTymSxMpLXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8a9wXzDkrYoqeIwnA8415SXK7N9u9p+glsWAEtIYJ3U=; b=pthbwkFXR/fabIUpkYH3MD/6nhKz/fOrWsTUwtNcb8sVRvhQ/9WQ1gA41Ips1k3hZSbBDadTumz3w12suwbxqrUESiKqmLJNMjAG06A9Pum4PqhImu9gnb9j9pghdxP6tJ102UbtpcPyPzZt2ZEJBsQTx/LBDLIlqIrgLmke7B88RvwF4G86AuJSuzI2HCo2i4ds8TQah8llulHKREGWWtOSWK2wGkd8IU3fqHNTBeWFrdrpoVuKvdvAO9hgqVQzCCQYKoDNkGpDbmMr942Irsu437UQz5SBHQNt0cEDUVB2jSSOoz7/MKJmzairrTZtG/057AzDLuZfj89Afm4GEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8a9wXzDkrYoqeIwnA8415SXK7N9u9p+glsWAEtIYJ3U=; b=AaxXTSShRVZWEsHzWcIN+OGUzwp4P86nKv6Se2Fq5pWjD1GuqucbYccVLiPTakmWv/Yf9WQ2Ns2lMylzD2pvYGRSkizBuddDZIX86ljp5lDNnkL3bHvkZiSJt4kL77DdGMLlaXENh5bFXYy4PK9wvrSUYtsBqVuKK7ONkdwscrjlFjkKH8YhxCShM4UvNiP1MyLvkAaeLC22aUDUwxiTQqMbPLgYQIhjiIh2LA3FgOabPrYvF7nVUpDfx67OPdXQQQp1CNxgSEy3ub90u3QerlVySCYXPsT8egbH8VRmPSIA8eON6DzF4SPU40zHt8rRrvUoVfE4jY+yP4WSvbTqOQ== Received: from TYYPR01MB14116.jpnprd01.prod.outlook.com (2603:1096:405:212::9) by TYRPR01MB13591.jpnprd01.prod.outlook.com (2603:1096:405:18c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9818.32; Mon, 20 Apr 2026 06:17:48 +0000 Received: from TYYPR01MB14116.jpnprd01.prod.outlook.com ([fe80::31dd:4ff2:eea8:c663]) by TYYPR01MB14116.jpnprd01.prod.outlook.com ([fe80::31dd:4ff2:eea8:c663%5]) with mapi id 15.20.9818.032; Mon, 20 Apr 2026 06:17:47 +0000 From: Chengpeng Yan To: David Rowley CC: PostgreSQL-development , cca5507 , Tom Lane Subject: Re: [PATCH] Fix hashed ScalarArrayOp semantics for NULL LHS with non-strict comparators Thread-Topic: [PATCH] Fix hashed ScalarArrayOp semantics for NULL LHS with non-strict comparators Thread-Index: AQHczaEqi+5p9wMBTka3ciLQwzUU6rXmX14AgAD10wCAACpDAA== Date: Mon, 20 Apr 2026 06:17:47 +0000 Message-ID: <5CDAD4B4-6DC6-4C31-8AC1-1F45EA6ED480@outlook.com> References: In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: TYYPR01MB14116:EE_|TYRPR01MB13591:EE_ x-ms-office365-filtering-correlation-id: 557b99cb-4018-4ded-3f8b-08de9ea48abe x-microsoft-antispam: BCL:0;ARA:14566002|8022599003|8060799015|461199028|31061999003|41001999006|19110799012|8062599012|15080799012|24121999003|22091999003|440099028|3412199025|102099032; x-microsoft-antispam-message-info: =?us-ascii?Q?OA98N+zUtFCClG/Zj3N15XhYSvU0VCcZwaa/+L62CFqOLN+LK2SV8Iy+y4v0?= =?us-ascii?Q?7AfVo0RkhGMlHH2v0UkXRW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?us-ascii?Q?bpb0KPVu0lHJ9ZkPaMIsqQ=3D=3D?= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Nmv+k1pVm+TIB0NxdyQuiotWush4+LkCjauzifKzQrurV4QX85iDvG+qBqPk?= =?us-ascii?Q?o2Fygqpari11J1ws6O25g2RXhA6DeMquL4V2CG4wOXVpcCbgS1Luw1kz16I9?= =?us-ascii?Q?+2+u0G4xiBN104lWTdowcKrgJB4MP8LSxPU4ON7zZz7K6ETurvruqmFf/62b?= =?us-ascii?Q?oNPoXWiXZ+50XCBn3XIuGDMqy9huLYx/0NQof2SyZxB5nQ77ggvdF/3stTO+?= =?us-ascii?Q?o79IQW4yychkBrxCKZmRWuTEUkvNVr5sFACVrmOFMkVhe9eVd0V2jG2eeWOn?= =?us-ascii?Q?6qCcDSo5wIEaiN9j9GmL9V5NsdxuWHJ6obdhgYesoHZoKbsa1WSztXMG2gM/?= =?us-ascii?Q?UuoHRNQsjR17tNIzXDfV3Yg1J95CWpAYuu4IYtyDlaq3pWGzdD9dNvm+xtvr?= =?us-ascii?Q?O2KcguJMwWwooaTSDNNgyUG1XJ4Ikd0Nxr3VmaLDv43Mz15SEioSruhyDL8y?= =?us-ascii?Q?XOmLUDSyNE8wq5jS3RJcIJSe0kTPwv0grG3tWV/tHWVDy4E6VDqZ6C2BzrXi?= =?us-ascii?Q?WDw9vUCOfboR4wRP81t5RQi8EIYXiCnbOiWBzMtt3lUoRrl83hxAdlHYesz6?= =?us-ascii?Q?MrYefpLXtgX1fPo5mjDkVEVjn5IplOituTVhETFOKPpeXn2HgBiLZjPZtgWr?= =?us-ascii?Q?3xkrnw6Gd858ruSc2LIDBeSWkgytw5at6xc+dVMI++HA/yvLQfZB35dJvVo2?= =?us-ascii?Q?h/8Rc20ZDFsxC8tMekf5ydCu5zzFAt7RFaKcqfTm7Zy0HFa/SrVrehFNu/ev?= =?us-ascii?Q?mH8QtBoHyxHuEvvM+Se6OZPYOAmj93E7zvEsr49BPab8r3eojid8gShNP3Gb?= =?us-ascii?Q?myp8FnTLLctQ6rVhOp5lEDBg02JTn/41xTxmDhOPA0fAmykt1Hcqmg7qqv7U?= =?us-ascii?Q?n9lCsydjIGQz2wyHTlh1CCr0cKPlnvPoy+dh/cbZI9D3OoZ+NufaeQfWO0Gr?= =?us-ascii?Q?m9LAsPF5wYe9xk35EiiPuJUM2fP5tIfipxcj/xPZ/dyn9n3q26pht/UQd51z?= =?us-ascii?Q?S50sTcepMOeIBPM9wzZ0zO3j21xRiLDePHFFAEidoyse38uUr/6N9illsUc7?= =?us-ascii?Q?aO90aJgwrM2AimeQ9+w4iOndgO0r+qWAni16bD/j12i78Q3eNsVMndbHacHb?= =?us-ascii?Q?vk77l71jdTN7W0QvcLzsZtyRuz9Mc3ec3XpeGCerAUqE+fRCteiGtnGjxB/N?= =?us-ascii?Q?X6znpeeGc/Z4NZHhLOTTEUCvg9qlo6fYZ8Eeb1rZNKZeIQqHKakiO/CZmE4q?= =?us-ascii?Q?CxBm6o/ZpikQXm3Ld6QSGNYKcQpQEukTuUgr93fN+t0OuEYA06JRl/f7WSA3?= =?us-ascii?Q?YSsQUESB7cr53S+i+diDX+Doxz0WEnCltpEoid3u2Aa+PKYxIsm5qFPa4k47?= =?us-ascii?Q?NWBGJflcodotm20Gr7Lmh2bH3uXmC9gxmQu/8LIgthWvD1NF2g=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-ID: <38852140E82EC2499BC1199C65241089@jpnprd01.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TYYPR01MB14116.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 557b99cb-4018-4ded-3f8b-08de9ea48abe X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Apr 2026 06:17:47.2049 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYRPR01MB13591 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Apr 20, 2026, at 11:46, David Rowley wrote: >=20 > Of course, it is possible to make the strict function do that, and > non-hashed IN / NOT IN handles it, so the hashed version shouldn't > have an excuse to not do the right thing. >=20 > I've attached a version that "probes" the equality function for its > NULL =3D NULL behaviour and its NULL =3D non-NULL behaviour and returns > whatever the result of the probe was at the appropriate time. >=20 > What I came up with does feel quite elaborate, so I'd quite like a 2nd op= inion. >=20 > The patch does assume that the non-strict function will return the > same thing for NULL =3D non-NULL as it will for non-NULL =3D NULL. > Technically, if you coded the function to do something different > there, the hashed vs non-hashed could differ in their result. My > thoughts there, if someone is expecting anything sane out of such an > equality function, then they're probably going to be disappointed due > to various other optimisations we have. Hi, Thanks for the discussion. I agree with Tom's concern that it does not seem safe to generalize from NULL =3D first-non-NULL to all non-NULL values. Unless I am missing one, I do not know of a planner/executor-visible contract that would justify that assumption. For the original NULL-LHS bug, a linear fallback still seems like the safest baseline fix to me. It is conservative, but it matches ExecEvalScalarArrayOp() without adding extra assumptions. The obvious downside is performance, although this path only triggers when the runtime LHS is NULL and the comparator is non-strict. It may also be possible to cache the NULL-LHS outcome once per expression, since the RHS array is constant in the hashed SAOP case, which might help reduce the cost of that fallback. ChangAo's example also seems to expose a separate correctness issue. If the comparator can return NULL even for non-NULL inputs, then a lookup hit seems sufficient, but a miss is no longer enough to distinguish FALSE for IN / TRUE for NOT IN from NULL. A conservative fix there would again be a linear fallback after miss, which should recover the right semantics, but that case does seem much more performance-sensitive. So I would be interested to hear what people think about both cases, especially if there is a better way to preserve correctness without paying the full linear-fallback cost. -- Best regards, Chengpeng Yan