Performance of "distinct with limit" - Mailing list pgsql-general

From Klaudie Willis
Subject Performance of "distinct with limit"
Date
Msg-id OWDKCDGTl83E-ZuJ_Y_UkyuwH9GBZBNyxoxRiQWddd1giuWoH5YHm9hWL08PTfNKfsqUgUsf_CG6TS4tAC3tM3gOeI2A5S0HVdj7Ko1dvoU=@protonmail.com
Whole thread Raw
Responses Re: Performance of "distinct with limit"
List 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



pgsql-general by date:

Previous
From: Stelios Sfakianakis
Date:
Subject: Re: Postgres and alias
Next
From: luis.roberto@siscobra.com.br
Date:
Subject: Re: Performance of "distinct with limit"