Re: Fix HAVING-to-WHERE pushdown with mismatched operator families - Mailing list pgsql-hackers

From Fujii Masao
Subject Re: Fix HAVING-to-WHERE pushdown with mismatched operator families
Date
Msg-id CAHGQGwGnPNX=nK+nXL0ihh+8WObQnFWjnPi5uvxBFvbtqN9WmQ@mail.gmail.com
Whole thread
In response to Re: Fix HAVING-to-WHERE pushdown with mismatched operator families  (Richard Guo <guofenglinux@gmail.com>)
Responses Re: Fix HAVING-to-WHERE pushdown with mismatched operator families
List 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



pgsql-hackers by date:

Previous
From: Andrey Rachitskiy
Date:
Subject: [PATCH] Limit PL/Perl scalar copies to work_mem
Next
From: "Tristan Partin"
Date:
Subject: Re: Add pg_stat_kind_info system view