Performance of "distinct with limit"

From: Klaudie Willis <Klaudie(dot)Willis(at)protonmail(dot)com>
To: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Performance of "distinct with limit"
Date: 2020-08-28 11:29:58
Message-ID: OWDKCDGTl83E-ZuJ_Y_UkyuwH9GBZBNyxoxRiQWddd1giuWoH5YHm9hWL08PTfNKfsqUgUsf_CG6TS4tAC3tM3gOeI2A5S0HVdj7Ko1dvoU=@protonmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2020-08-28 11:40:43 Re: Postgres and alias
Previous Message Stelios Sfakianakis 2020-08-28 07:16:42 Re: Postgres and alias