Re: Too much blocks read - Mailing list pgsql-performance

From Matthew Wakeling
Subject Re: Too much blocks read
Date
Msg-id alpine.DEB.2.00.0911181621320.684@aragorn.flymine.org
Whole thread Raw
In response to Too much blocks read  (Waldomiro <waldomiro@shx.com.br>)
List pgsql-performance
On Wed, 18 Nov 2009, Waldomiro wrote:
> So, I need to retrieve only the last value for some key. That key has about
> 20.000 tuples in this table.
>
> SELECT field1
> FROM table_7milions
> WHERE field1 = 'my_key'
> ORDER BY field1 DESC
> LIMIT 1

What's the point of this query? You are forcing Postgresql to read in all
the rows where field1 = 'my_key', so that they can be sorted, but the sort
will be completely unpredictable because all the values will be the same.
If you wanted to grab any row, then remove the ORDER BY, and it will just
return the first one it finds.

Matthew

--
 The best way to accelerate a Microsoft product is at 9.8 metres per second
 per second.
         - Anonymous

pgsql-performance by date:

Previous
From: Waldomiro
Date:
Subject: Too much blocks read
Next
From: Craig James
Date:
Subject: Re: Too much blocks read