Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id DF27DB5DBBE for ; Fri, 13 May 2011 17:51:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 10956-09 for ; Fri, 13 May 2011 20:51:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com [209.85.216.181]) by mail.postgresql.org (Postfix) with ESMTP id E6A8BB5DBB6 for ; Fri, 13 May 2011 17:51:29 -0300 (ADT) Received: by qyg14 with SMTP id 14so1675512qyg.19 for ; Fri, 13 May 2011 13:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=4AsWF5BSbz40SOuKW8o3pC5v1vn2pq46MPObYC/JcxQ=; b=xyS6DE+rF9sDkFFl/EohSOykzT64VWSyTQnbgpN/1xum+6YL55f0fFVD1A5LcRYKL2 fVFTD+ks+WLCTKU8IE3J7x592WeWvSgxkumqkfRdU6vtJDFV9IhoGeHJaE44GS16VN8D 2SqfrOY66PY6Ial53bG4WLEnm+6Gsik6mWqe4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=VxWPcoKxI0n2MYOHxYvVVS0jOCmvOj58zoxcTD+y2V9MKW9NCDAmi0Yc8/JasTpLFw Wi3xMaqvghiGBLtnnufKhoxB6LzLUnTi/rRJbfd1qw+NI8/5d3D+SRL7JhsYq17bYf4N rybkgOJVZKCGlaqMK9zTqIm3kNW3w1gp6L+SQ= Received: by 10.229.64.84 with SMTP id d20mr1502710qci.206.1305319889120; Fri, 13 May 2011 13:51:29 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.84.16 with HTTP; Fri, 13 May 2011 13:51:08 -0700 (PDT) In-Reply-To: <4DCD90F5.2010501@agliodbs.com> References: <4DB6F4BB020000250003CEB9@gw.wicourts.gov> <2823.1305314437@sss.pgh.pa.us> <4DCD90F5.2010501@agliodbs.com> From: =?ISO-8859-1?Q?C=E9dric_Villemain?= Date: Fri, 13 May 2011 22:51:08 +0200 Message-ID: Subject: Re: reducing random_page_cost from 4 to 2 to force index scan To: Josh Berkus Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201105/214 X-Sequence-Number: 43723 2011/5/13 Josh Berkus : > >> I guess maybe the reason why it didn't matter for the OP is that - if >> the size of the index page in pages is smaller than the pro-rated >> fraction of effective_cache_size allowed to the index - then the exact >> value doesn't affect the answer. >> >> I apparently need to study this code more. > > FWIW: random_page_cost is meant to be the ratio between the cost of > looking up a single row as and index lookup, and the cost of looking up > that same row as part of a larger sequential scan. =A0For specific > storage, that coefficient should be roughly the same regardless of the > table size. =A0So if your plan for optimization involves manipulating RPC > for anything other than a change of storage, you're Doing It Wrong. > > Instead, we should be fixing the formulas these are based on and leaving > RPC alone. > > For any data page, there are actually four costs associated with each > tuple lookup, per: > > in-memory/seq =A0 | on disk/seq > ----------------+---------------- > in-memory/random| on disk/random it lacks some more theorical like sort_page/temp_page : those are based on a ratio of seq_page_cost and random_page_cost or a simple seq_page_cost (when working out of work_mem) memory access is accounted with some 0.1 in some place AFAIR. (and memory random/seq is the same at the level of estimations we do) > > (yes, there's actually more for bitmapscan etc. =A0but the example holds) (if I read correctly the sources, for this one there is a linear approach to ponderate the cost between random_page cost and seq_page_cost on the heap page fetch plus the Mackert and Lohman formula, if needed, in its best usage : predicting what should be in cache *because* of the current query execution, not because of the current status of the page cache) > > For any given tuple lookup, then, you can assign a cost based on where > you think that tuple falls in that quadrant map. =A0Since this is all > probability-based, you'd be assigning a cost as a mixed % of in-memory > and on-disk costs. =A0Improvements in accuracy of this formula would come > through improvements in accuracy in predicting if a particular data page > will be in memory. > > This is what the combination of random_page_cost and > effective_cache_size ought to supply, but I don't think it does, quite. > > -- > Josh Berkus > PostgreSQL Experts Inc. > http://pgexperts.com > > -- > Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org= ) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-performance > --=20 C=E9dric Villemain=A0 =A0 =A0 =A0 =A0 =A0 =A0=A0 2ndQuadrant http://2ndQuadrant.fr/=A0 =A0=A0 PostgreSQL : Expertise, Formation et Suppo= rt