Skip site navigation (1) Skip section navigation (2)

Re: query planner and scanning methods

From: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
To: "Colin Copeland" <copelco(at)caktusgroup(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org, "team(at)caktusgroup(dot)com s" <team(at)caktusgroup(dot)com>
Subject: Re: query planner and scanning methods
Date: 2008-09-23 22:57:31
Message-ID: 396486430809231557j25541f06q845e017553fc44d2@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-performance
On Tue, Sep 23, 2008 at 3:25 PM, Colin Copeland <copelco(at)caktusgroup(dot)com> wrote:

>>> dimension=# EXPLAIN ANALYZE
>>> SELECT   DISTINCT ON ("dimension_book"."call")
>>>       "dimension_book"."title"
>>> FROM     "dimension_book"
>>>       INNER JOIN "dimension_library_books"
>>>         ON ("dimension_book"."id" = "dimension_library_books"."book_id")
>>> WHERE    ("dimension_book"."call" >= 'PA0000'
>>>        AND "dimension_library_books"."library_id" IN (12,15,20))
>>> ORDER BY "dimension_book"."call" ASC
>>> LIMIT 10 OFFSET 100;

> Yes, I was thinking about this too. How would one generate a list of pages
> from this, though? I can't predict values of dimension_book.call (it's not a
> serial number).

I can think of one very ugly way to get the first record for each
page.  Hopefully, you will not need to generate these list pages very
often.  Also, you could probably refine the following query in a
couple of ways to improve performance.

SELECT A."dimension_book"."call", SUM( B."dimension_book"."call" ) AS
OrderedRowNbr
FROM ( your_above_query_without_the_limits ) AS A
INNER JOIN ( your_above_query_without_the_limits ) AS B
ON A."dimension_book"."call" >= B."dimension_book"."call"
ORDER BY A."dimension_book"."call"
HAVING SUM( A."dimension_book"."call" ) % 10 = 0;


-- 
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Responses

pgsql-performance by date

Next:From: EinarsDate: 2008-09-24 00:53:49
Subject: Chaotically weird execution plan
Previous:From: Colin CopelandDate: 2008-09-23 22:25:17
Subject: Re: query planner and scanning methods

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group