Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 97F7164FC17 for ; Tue, 23 Sep 2008 19:07:54 -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 36558-01 for ; Tue, 23 Sep 2008 19:07:52 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.245]) by postgresql.org (Postfix) with ESMTP id 121B064FC0D for ; Tue, 23 Sep 2008 19:07:51 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id d30so199258and.33 for ; Tue, 23 Sep 2008 15:07:50 -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=JhL4KnYmOenl1hxtYVeWrzK3ajiDBHSqCiD2/DI+0rw=; b=QWRUjXPi2+TusIUKw8pROH3DqON18ZBBlDphgyeaTN9n1fSjmslDYpJtZgs3jyDBlm zDJuCOblMxRV4b89UzGJelFtUeg+ghXBVRCKpoPc/Is5aoWSRJvXmYVkyublRwkUXf/T oPLBoJNPsAZg5wxvYdaYkrjVb7wjnRtzl9cE0= 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=aW3U2J4BA3SxCcuh9s5pFaowLEKQuohnlywkXUCvaibhj8Hj7zqw5+xZInLFJAEn5f TniOBJWwFuueMItFdRJ58hP7/FgUOsijtog6GWbpByUvDW/Rg0Q30Mx0jSWpWwWbPkbs X7hdPAsrGRzKlYNOB0G0Q8CxbQ4zArq8+8fBY= Received: by 10.100.10.15 with SMTP id 15mr5063175anj.131.1222207670800; Tue, 23 Sep 2008 15:07:50 -0700 (PDT) Received: by 10.100.196.2 with HTTP; Tue, 23 Sep 2008 15:07:50 -0700 (PDT) Message-ID: <396486430809231507t46edf20fxab469bedbd78e8cc@mail.gmail.com> Date: Tue, 23 Sep 2008 15:07:50 -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: <8559E6C3-47ED-40E4-99E6-C56B322310DA@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> 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/202 X-Sequence-Number: 31515 On Tue, Sep 23, 2008 at 2:22 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; Ya offset works by scanning over the first 100 rows. When the offsets get big, it become a performance looser. You can guarantee a faster index scan if you recall the last 10th value from the previous query. Then remove the offset predicate and replace it with the following WHERE clause: WHERE ... AND dimension_book.call > _last_queried_10th_row-dimension_book_call, ... LIMIT 10; -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug