Re: ORDER BY time consuming - Mailing list pgsql-general

From Jim C. Nasby
Subject Re: ORDER BY time consuming
Date
Msg-id 20050821170122.GL95876@pervasive.com
Whole thread Raw
In response to ORDER BY time consuming  (Ben-Nes Yonatan <da@canaan.co.il>)
Responses Re: ORDER BY time consuming  ("Thomas F. O'Connell" <tfo@sitening.com>)
List pgsql-general
On Sun, Aug 21, 2005 at 12:04:01PM +0200, Ben-Nes Yonatan wrote:
> Hi All,
>
> I got a table with about 4.5 millions rows in it which is connected to
> another table with about 60 millions rows which are used as keywords for
> searching.
>
> I succeded to create fast queries on the first table that finds a row at
> the first table which is connected to up to 4 diffrent keywords at the
> second table and LIMIT the result to 12 (I want to allow the surfers of
> the site to press back and next to see more products so ill make it with
> OFFSET).
>
> I want to be able to order my result by a specific column but when I
> insert ORDER BY into the query (and any other query that I tried) it
> becomes extremly slow, what can I do to solve this problem?

Your question is too generic to answer specifically, but I suspect that
if you use your un-ordered query as a subquery in the FROM clause and
then order that it will work well. IE:

SELECT *
    FROM (SELECT ...) a
    ORDER BY f1, f2, f3
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software        http://pervasive.com        512-569-9461

pgsql-general by date:

Previous
From: "Jim C. Nasby"
Date:
Subject: Re: extract (dow/week from date)
Next
From: Madison Kelly
Date:
Subject: How to get '-' in katakana with canna server