Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 8D1B264FC15 for ; Tue, 23 Sep 2008 19:57:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 44235-06 for ; Tue, 23 Sep 2008 19:57:33 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gx0-f17.google.com (mail-gx0-f17.google.com [209.85.217.17]) by postgresql.org (Postfix) with ESMTP id 0C7C364FC04 for ; Tue, 23 Sep 2008 19:57:32 -0300 (ADT) Received: by gxk10 with SMTP id 10so4958222gxk.19 for ; Tue, 23 Sep 2008 15:57:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=GIS1HYQv4a31ElUt5c2sqCEmsc/+Kl9eIcRDYOErRzk=; b=Y4VBrQ6+bWmB7fg2IltHs5/tVKunris1kpYcu4wk+yiMHHpB75Do2hfI4FQnmAylKH rcGWk1cNL6G1ynDtqDz+7flHTHdjtjIkRfhAnoormTGp874VZp5HSqOAOYvikJv7RtlV k1UCxEv7ZPCodHPWXS18DDk4HdL1/jmZ7+lDU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=PDlkl/RrNZma6NaTxY7AKlsqOPMmc4TTf9oUi2MGxH3/uACuBB59LtS/lwZycHPg9w ODZ8EG+1/CQzhZjEGMyAWlZJjZLjirHrXFkegZrzjpauhQpXM+Cmqq3XhGktv55kv3dK jOQHNVKbew5E0TPao4BE6iH1Z57XnL5sw1EPA= Received: by 10.100.95.19 with SMTP id s19mr5117137anb.97.1222210651808; Tue, 23 Sep 2008 15:57:31 -0700 (PDT) Received: by 10.100.196.2 with HTTP; Tue, 23 Sep 2008 15:57:31 -0700 (PDT) Message-ID: <396486430809231557j25541f06q845e017553fc44d2@mail.gmail.com> Date: Tue, 23 Sep 2008 15:57:31 -0700 From: "Richard Broersma" To: "Colin Copeland" Subject: Re: query planner and scanning methods Cc: pgsql-performance@postgresql.org, "team@caktusgroup.com s" In-Reply-To: <6D0802D6-371A-470C-AB1C-3CC20E543061@caktusgroup.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <8559E6C3-47ED-40E4-99E6-C56B322310DA@caktusgroup.com> <396486430809231507t46edf20fxab469bedbd78e8cc@mail.gmail.com> <6D0802D6-371A-470C-AB1C-3CC20E543061@caktusgroup.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200809/204 X-Sequence-Number: 31517 On Tue, Sep 23, 2008 at 3:25 PM, Colin Copeland 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