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 1w4Ynn-002JSk-33 for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Mar 2026 06:30:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4Ynm-00FrHb-1Q for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Mar 2026 06:30: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.96) (envelope-from ) id 1w4Ynl-00FrHT-35 for pgsql-hackers@lists.postgresql.org; Mon, 23 Mar 2026 06:30:14 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w4Ynk-00000000a0O-2x2s for pgsql-hackers@lists.postgresql.org; Mon, 23 Mar 2026 06:30:13 +0000 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-668c60b8f45so4639458a12.0 for ; Sun, 22 Mar 2026 23:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774247411; cv=none; d=google.com; s=arc-20240605; b=ayHFz1Vzri4TrwOYEiSKrhHSxjCiFvrFhf5LKMa7wk/iJKemAQbMqVSvsYmsjJsimo gFgb6pI+Qw050rVf1z+tFsclPIC0XpchrPgRc4qMVA6W0pOXIG5j0HClkt0uPxvRcPiG B950qwUjgrXPDYGHgDX63GkC7rZD8liXZQYTQmi49GZ2ccX+Rlk3+xFxGJJeMwLFLN5o zLdTDVmY+j9q8RQq9P5Q9LO0DWLnY8fxYeYkf7+gbgfD8PabZSfjo5pV5kSuM5F/7m+u eDLINdNKbIRrZBYvTB3LNI8WnwTNhwWNcKMOr8o/HMqKeDLZBaNV2nHX8IXcj1EyTid2 tE9A== 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:mime-version:dkim-signature; bh=7Yb3a7Q8CyNa+LBPL6gnX2P2FcQR/DyrLy5+sH3ZokE=; fh=zb4uyDrz8aGXP/a12bd3++ad5MRsuEO9xpPbkJ1eXV8=; b=WZaJGS17nUvPaYqCEx7VSiFd9BKe+bWnV3/MZdjPuKu15z/7mkwofUP2VT4TvMeh7F yUsNGS8+LryzllHFq6dizCIkI8jbWZVMyfV3IJjj+cE8pCfAAbI4B5yKUYitrtFxsxwL QAbrJd1YY3dbSYMiQ7K0ARMWYvdS7Nz2bIkaB7qx0qfxhdbesVbl+3yRaeB0RfpXoBWQ j3ROa2kosUnxVhcZoxVk9HplJS5voOW7s+7VzZB6MbYZn/1QNm7zASeoK5htb3R53Afg 7GemRbcO/NESNeyVh3VP+gUJANtVDomiv5u5vU3cpC1ubwuF25Vendg96PUnsm99i1CU FZMA==; 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=20230601; t=1774247411; x=1774852211; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=7Yb3a7Q8CyNa+LBPL6gnX2P2FcQR/DyrLy5+sH3ZokE=; b=N8rj1YGgNIa1Rzmdjsr6egHUXSeQXrAxcYPlTphBVGL0p+4rS9kE5OqlfmQM/HRZMO X29hnONbIuAYYYJ7A5LyqbLIKIBr7L4YSZs+KnMRWDVFrQTklKmm3lSVufmv1f9/WeCo QSsj58RLODAuYFzW6iSYQDLG1mfGGc6VlRl4yuBDO+EaNQowVemoWX0GHHyALAhzKEIR dD6u0tu2rCQIMG8V8aP56HLpczfmc8qmUVM4PdktvBbXrZF7oVB0ivE6ZJ6joB+Ev9H9 rpeAT6IPELpLrjt+ycdVrf8ENPkQwzTVuWaN/hRR+mFs3Vgeqa42tVXrlOn/s6g3RQ+F 5Bug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774247411; x=1774852211; h=cc:to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7Yb3a7Q8CyNa+LBPL6gnX2P2FcQR/DyrLy5+sH3ZokE=; b=qDMBtWvkzAlwqLDVOllc4R26aZKUyY/mIu2MVu2ZWpTT8V3aX+naa/yb9fpnJJpUJV 9/U7YpkG4Yv465O51zvsEPZDooorcngb0J5FqPbHbDGieSOZnE7ul23cFxTFuns5yzAK qrz+LtnnOReey36kZs6oerstGAdXPJqSOAHSfGS9XtcK8uSWtLt+lyCvtXhutTe5e1ix m+BOsFua7D1FyeOGATJaNKRxqp7v+EAVWHAguJEn1C/JBMbh32WVDk0wLeEtyw3IqOXH Oy28LwpYdbC4yn9zmy0HXJeRuK0eIjKKjiqggUm3cXKnBLCxpfjbz/cwJ4afJsW5bi5H b/cQ== X-Gm-Message-State: AOJu0Yz0M8cxM726IFv6ydsX3iiIQUNz8BcrSWpZEfKkc4gmyuOSTSSG H9v9hf7iDbp6M0e3x3yIwgneDDyyrXNpJuf5xlZVeCy92T4HAM3RUYUT9PHreIXzBUK4zIy/hoG nLPJOjrQg/ax5eblwuCpGEalAsnoMAeG4aj6jrvJrMQ== X-Gm-Gg: ATEYQzzhlm/l2D0xXHRVe69R7eqhSmaD4jyFJcQiiiMrf3Ed4EVG/+tWa3ev2a0mjjT aKTbgOhASNjmMnacz9Q8VZnUidHCAa2l6CADe3BZmb4/F4eQWlMyipL6fjoLqGoiYze2lHM93aR hib+Qo8EaugsVuqQVhs2voYq3KrCtaFEzN9iyDMi+iXmzqy+J00PEsEgwe1B9EV2Tl/qj921olZ 3SJnp3k+ibI4Xbg1z8TaINPCbffFk0akzEXRVPI5wfnl21jqkcNMOPhjXTeuznbJ83y4AqM0OsL DzaDA8vwN5OYAw== X-Received: by 2002:a17:907:a807:b0:b96:e3db:9e04 with SMTP id a640c23a62f3a-b982f4faea3mr729297566b.53.1774247410225; Sun, 22 Mar 2026 23:30:10 -0700 (PDT) MIME-Version: 1.0 From: Tender Wang Date: Mon, 23 Mar 2026 14:29:58 +0800 X-Gm-Features: AaiRm52boZTDY9-XEmGAG6baGHCJHO5NfQrb4qQkEnneZD0rCUbCqGYXCkauQ3c Message-ID: Subject: Fix "could not find memoization table entry" To: PostgreSQL Hackers Cc: David Rowley Content-Type: multipart/mixed; boundary="000000000000a19094064dab2ad3" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a19094064dab2ad3 Content-Type: text/plain; charset="UTF-8" Hi, Recently, I encountered an error: could not find memoization table entry on TPCH(S=1) test. The query was as follows: psql (19devel) Type "help" for help. postgres=# SELECT FROM partsupp AS ref_0, LATERAL (SELECT ref_0.ps_suppkey AS c3, (SELECT n_regionkey FROM nation LIMIT 1) AS c4 LIMIT ALL) AS subq_0 WHERE hash_numeric(ref_0.ps_supplycost) = subq_0.c4; ERROR: could not find memoization table entry postgres=# explain SELECT FROM partsupp AS ref_0, LATERAL (SELECT ref_0.ps_suppkey AS c3, (SELECT n_regionkey FROM nation LIMIT 1) AS c4 LIMIT ALL) AS subq_0 WHERE hash_numeric(ref_0.ps_supplycost) = subq_0.c4; QUERY PLAN ----------------------------------------------------------------------------------------- Nested Loop (cost=0.06..57942.04 rows=4000 width=0) -> Seq Scan on partsupp ref_0 (cost=0.00..25560.00 rows=800000 width=10) -> Memoize (cost=0.06..0.09 rows=1 width=4) Cache Key: hash_numeric(ref_0.ps_supplycost), ref_0.ps_suppkey Cache Mode: binary Estimates: capacity=80659 distinct keys=88915 lookups=800000 hit percent=80.63% -> Subquery Scan on subq_0 (cost=0.05..0.08 rows=1 width=4) Filter: (hash_numeric(ref_0.ps_supplycost) = subq_0.c4) -> Result (cost=0.05..0.06 rows=1 width=8) InitPlan expr_1 -> Limit (cost=0.00..0.05 rows=1 width=4) -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=4) (12 rows) The hash_numeric result type is int. If I forced binary_mode to logical, there was no error anymore. So I think this may be a bug. How to easily reproduce: 1. prepare tpch(s=1) data 2. Using gdb to set the mstate->mem_limit to 170 after the first tuple was put into the cache in func cache_lookup() 3. When putting the second tuple into the cache, the mem_used will exceed the mem_limit, so calling the cache_reduce_memory() to remove the first tuple. But it cannot find the first tuple in the hash table. I did some research about this issue. When we insert the first tuple into the cache, the first column(hash_numeric(ref_0.ps_supplycost)) value is: (gdb) p /x pslot->tts_values[i] $2 = 0xaf27c7c7 (gdb) p hkey $2 = 38469220 But in the cache_reduce_memory(), its value is like this: (gdb) p /x pslot->tts_values[i] $5 = 0xffffffffaf27c7c7 (gdb) p hkey $7 = 288723292 The hkeys returned by datum_image_hash() are different, so we can't find the entry in the hash table. In the datum_image_hash(), if typByVal is true, calling result = hash_bytes((unsigned char *) &value, sizeof(Datum)); I think we should use typLen here, not sizeof(Datum). I tried this way and didn't encounter any errors again. I added David to the cc list. He may know more about this module. -- Thanks, Tender Wang --000000000000a19094064dab2ad3 Content-Type: application/octet-stream; name="0001-Fix-could-not-find-memoization-table-entry.patch" Content-Disposition: attachment; filename="0001-Fix-could-not-find-memoization-table-entry.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_mn2ssk6o0 RnJvbSA0ZTUzZjc1ZTQ2ZmNiNDk3MDI4YzdjNjNmYjNmYjkzNjdkN2U1ZTVkIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBUZW5kZXIgV2FuZyA8dG5kcndhbmdAZ21haWwuY29tPgpEYXRl OiBNb24sIDIzIE1hciAyMDI2IDEzOjU5OjU5ICswODAwClN1YmplY3Q6IFtQQVRDSF0gRml4ICJj b3VsZCBub3QgZmluZC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