Re: Fix HAVING-to-WHERE pushdown with mismatched operator families

Fujii Masao <masao.fujii@gmail.com>

From: Fujii Masao <masao.fujii@gmail.com>
To: Richard Guo <guofenglinux@gmail.com>
Cc: Tender Wang <tndrwang@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2026-07-06T22:43:50Z
Lists: pgsql-hackers
On Mon, Jul 6, 2026 at 4:32 PM Richard Guo <guofenglinux@gmail.com> wrote:
>
> On Wed, Jul 1, 2026 at 2:59 PM Tender Wang <tndrwang@gmail.com> wrote:
> > I look through the v3 patch.  I didn't find an obvious issue. +1
>
> Thanks all for the reviews.  I've committed this patch and backported
> it to v18.

In HEAD, I found what looks like another case of the same issue. Is the
cause essentially the same as the one fixed by your commit?

    --------------------------
    CREATE TEMP TABLE t (id int, num numeric);
    INSERT INTO t VALUES (1, numeric '1.0'), (2, numeric '1.00');

    SELECT * FROM (
        SELECT DISTINCT ON (num) id, num FROM t ORDER BY num, id
    ) s WHERE scale(num) = 2;
    --------------------------

This query should return no rows. The subquery selects the first row
(id = 1, num = 1.0), and the outer WHERE clause should then filter
it out because scale(1.0) = 1, not 2.

But, in HEAD it returns:

     id | num
    ----+------
      2 | 1.00
    (1 row)

Regards,

-- 
Fujii Masao