Search Postgresql Archives

Re: Is "DISTINCT" making a diffence in: SELECT [DISTINCT] ... EXCEPT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2023-11-15 at 10:57 +0100, Dimitrios Apostolou wrote:
> SELECT [DISTINCT] ... EXCEPT ...
> 
> In this query I get the same results regardless of including DISTINCT or
> not. But I get different query plans, I get an extra HashAggregate node
> in the case of SELECT DISTINCT. Any idea why?

The DISTINCT is superfluous, because EXCEPT already removes duplicate rows.
However, the planner does not invest extra processing cycles to detect
that you wrote a superfluous DISTINCT, and it does not remove it.
As a consequence, you end up with a pointless extra execution plan node
that does not achieve anything except slowing down the query.

Remove the DISTINCT.

Yours,
Laurenz Albe






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux