Re: Question about double table scans for a table - Mailing list pgsql-bugs

From David Rowley
Subject Re: Question about double table scans for a table
Date
Msg-id CAApHDvqzcEeAuy8cV2xqL8uXRKGULMrvufCzCcFgoLv+EEjsWg@mail.gmail.com
Whole thread Raw
In response to Re: Question about double table scans for a table  (jian he <jian.universality@gmail.com>)
Responses Re: Question about double table scans for a table
List pgsql-bugs
On Fri, 28 Jul 2023 at 12:12, jian he <jian.universality@gmail.com> wrote:
> I think you query is equivalent to following:
>
> select
>     ps_partkey,
>     sum(ps_supplycost * ps_availqty) filter (where ps_supplycost > 0
> and ps_availqty > 0 ) as value

The FILTER clause is applied before aggregation.  HAVING is applied
after aggregation. This is not even nearly the same.

(You might have forgotten that numbers can be negative and also you
might have missed the * 0.0001000000.)

The original query seems to want all parts apart from the ones that
are below 1/10000th of the total ps_supplycost * ps_availqty for all
parts.

David



pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Fwd: BUG #18016: REINDEX TABLE failure
Next
From: Asier Lostalé
Date:
Subject: Re: BUG #18038: Aliases removed from view definitions