Re: Performance of "distinct with limit"

From: luis(dot)roberto(at)siscobra(dot)com(dot)br
To: Klaudie Willis <Klaudie(dot)Willis(at)protonmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Performance of "distinct with limit"
Date: 2020-08-28 11:59:08
Message-ID: 1880175167.48585037.1598615948304.JavaMail.zimbra@siscobra.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

If "n" is indexed, it should run quickly. Can you share the execution plan for your query?

De: "Klaudie Willis" <Klaudie(dot)Willis(at)protonmail(dot)com>
Para: "pgsql-general" <pgsql-general(at)lists(dot)postgresql(dot)org>
Enviadas: Sexta-feira, 28 de agosto de 2020 8:29:58
Assunto: Performance of "distinct with limit"

Hi,

Ran into this under-optimized query execution.

select distinct n from bigtable; -- Lets say this takes 2 minutes
select distinct n from bigtable limit 2 -- This takes approximately the same time

However, the latter should have the potential to be so much quicker. I checked the same query on MSSQL (with 'top 2'), and it seems to do exactly the optimization I would expect.

Is there any way to achieve a similar speedup in Postgresql?

Klaudie

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Klaudie Willis 2020-08-28 12:34:09 Re: Performance of "distinct with limit"
Previous Message Laurenz Albe 2020-08-28 11:40:43 Re: Postgres and alias