Re: Optimizing DISTINCT with LIMIT - Mailing list pgsql-hackers

From David Lee Lambert
Subject Re: Optimizing DISTINCT with LIMIT
Date
Msg-id 200812060629.08223.davidl@lmert.com
Whole thread Raw
In response to Re: Optimizing DISTINCT with LIMIT  (Gregory Stark <stark@enterprisedb.com>)
Responses Re: Optimizing DISTINCT with LIMIT  (Grzegorz Jaskiewicz <gj@pointblue.com.pl>)
List pgsql-hackers
On Thursday 04 December 2008 15:09, Gregory Stark wrote:
> tmp <skrald@amossen.dk> writes:

> > Also, it is my impression that many people use LIMIT to minimize the
> > evaluation time of sub queries from which the outer query only needs a
> > small subset of the sub query output.
>
> I've seen lots of queries which only pull a subset of the results too --
> but it's always a specific subset. So that means using ORDER BY or a WHERE
> clause to control it.

I use "ORDER BY random() LIMIT :some_small_number" frequently to get a "feel" 
for data.  That always builds the unrandomized relation and then sorts it.  I 
guess an alternate path for single-table queries would be to randomly choose 
a block number and then a tuple number;  but that would be biased toward long 
rows (of which fewer can appear in a block).

-- 
David Lee Lambert ... Software Developer
Cell phone: +1 586-873-8813 ; alt. email <as4109@wayne.edu> or 
<lamber45@msu.edu>
GPG key at http://www.lmert.com/keyring.txt


pgsql-hackers by date:

Previous
From: "Fujii Masao"
Date:
Subject: Re: Sync Rep: First Thoughts on Code
Next
From: hubert depesz lubaczewski
Date:
Subject: visibility map - what do i miss?