Re: bug: query returns different result with and without memoization.

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Yilin Zhang <jiezhilove(at)126(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, Jacob Brazeal <jacob(dot)brazeal(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: bug: query returns different result with and without memoization.
Date: 2026-11-02 02:41:56
Message-ID: CAHGQGwEYXUew25KgOJRwPvC=_o-tQ5Y5XMCOCLBEw_C1zaqqZA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Nov 2, 2026 at 11:32 AM Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> Codex reported me that, after this change, the same query can fail with
> enable_memoize enabled but succeed with it disabled, as shown below.
> Is this a bug?

Codex found another case where the same query fails with enable_memoize
enabled but succeeds with it disabled. Here are the steps to reproduce it:

--------------------------------------
CREATE TEMP TABLE mo AS
SELECT g % 100 + 1 AS k FROM generate_series(1, 10000) g;

CREATE TEMP TABLE mi AS
SELECT g AS k FROM generate_series(1, 10000) g;

CREATE UNIQUE INDEX ON mi (k);
ANALYZE mo;
ANALYZE mi;

SET enable_memoize = off;

SELECT count(*)
FROM mo JOIN mi USING (k)
WHERE CASE WHEN mi.k < 0
THEN mi.k = (SELECT 1 / (k - k) FROM mo LIMIT 1)
ELSE true END;

SET enable_memoize = on;

SELECT count(*)
FROM mo JOIN mi USING (k)
WHERE CASE WHEN mi.k < 0
THEN mi.k = (SELECT 1 / (k - k) FROM mo LIMIT 1)
ELSE true END;
--------------------------------------

Regards,

--
Fujii Masao

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhijie Hou 2026-11-02 02:51:25 Re: Avoid resetting subscription two_phase state to pending when already enabled
Previous Message Tianyi Gao 2026-11-02 02:41:20 Re: Use a hash table for the regexp cache