Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 40D82634505 for ; Thu, 27 May 2010 05:03:46 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 20671-10 for ; Thu, 27 May 2010 08:03:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gw0-f46.google.com (mail-gw0-f46.google.com [74.125.83.46]) by mail.postgresql.org (Postfix) with ESMTP id 1CB706344D1 for ; Thu, 27 May 2010 05:03:32 -0300 (ADT) Received: by gwaa12 with SMTP id a12so1692152gwa.19 for ; Thu, 27 May 2010 01:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=dUq23HIrIBXbeLBafui9C+I9V7Q7UMV0Xv980mUDeiI=; b=kw2PSKd3BcX8AZQuzUpuKlhHhLc/WIwFvODlDLC4LMx7umjVVFsBG9XSsoeCqHxGw/ xeDUPwqCIOSueJZfa9pz8I9c+7Hnv6+VQxJsvKev+fYPlY2bRF6XzTbu7C+fipW1kmD+ LL0laVSd1wl/qocfdW32KAum7ZrfzobjGn1D8= 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=jUf2n0tYsNsIIiBCylnY71d6Ea24OIwWVBmcMVoqJBjxlRNeM/1wNZ9If3/Yied72r ayA1YpqekYF/vTHuM3Z+VLc6AJLZaEo1iDgRczycBtuUz7KDU4eDbqJXGbSPSP0Q7lrS B0/hv6QVddUp9QNU/o9i/KKwnwojCOon2qhwA= Received: by 10.150.62.18 with SMTP id k18mr10675421yba.64.1274947409108; Thu, 27 May 2010 01:03:29 -0700 (PDT) MIME-Version: 1.0 Received: by 10.151.112.8 with HTTP; Thu, 27 May 2010 01:03:09 -0700 (PDT) In-Reply-To: References: From: =?ISO-8859-1?Q?C=E9dric_Villemain?= Date: Thu, 27 May 2010 10:03:09 +0200 Message-ID: Subject: Re: Random Page Cost and Planner To: David Jarvis Cc: Bryan Hinton , 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=-0.001 tagged_above=-10 required=5 tests=BAYES_40=-0.001, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201005/215 X-Sequence-Number: 38799 2010/5/27 David Jarvis : > Hi, Bryan. > > I was just about to reply to the thread, thanks for asking. Clustering wa= s > key. After rebooting the machine (just to make sure absolutely nothing wa= s > cached), I immediately ran a report on Toronto: 5.25 seconds! > > Here's what I did: > > Created a new set of tables that matched the old set, with statistics of > 1000 on the station and taken (date) columns. > Inserted the data from the old hierarchy into the new set, ordered by > station id then by date (same seven child tables as before: one per > category). > > I wanted to ensure a strong correlation between primary key and station i= d. > > Added three indexes per table: (a) station id; (b) date taken; and (c) > station-taken-category. > Set the station-taken-category index as CLUSTER. > Vacuumed the new tables. > Dropped the old tables. > Set the following configuration values: > > shared_buffers =3D 1GB > temp_buffers =3D 32MB > work_mem =3D 32MB > maintenance_work_mem =3D 64MB > seq_page_cost =3D 1.0 > random_page_cost =3D 2.0 > cpu_index_tuple_cost =3D 0.001 > effective_cache_size =3D 512MB > > I ran a few more reports (no reboots, but reading vastly different data > sets): > > Vancouver: 4.2s > Yellowknife: 1.7s > Montreal: 6.5s > Trois-Riviers: 2.8s > > No full table scans. I imagine some indexes are not strictly necessary an= d > will test to see which can be removed (my guess: the station and taken > indexes). The problem was that the station ids were scattered and so > PostgreSQL presumed a full table scan would be faster. > > Physically ordering the data by station ids triggers index use every time= . > > Next week's hardware upgrade should halve those times -- unless anyone ha= s > further suggestions to squeeze more performance out of PG. ;-) I wonder what the plan will be if you replace sc.taken_* in : m.taken BETWEEN sc.taken_start AND sc.taken_end by values. It might help the planner... Also, I'll consider explicit ordered join but I admit I haven't read the whole thread (in particular the table size). Ho, and I set statistics to a highter value for column category_id, table station_category (seeing the same resquest and explain analyze without date in the query will help) > > Dave > > --=20 C=E9dric Villemain 2ndQuadrant http://2ndQuadrant.fr/ PostgreSQL : Expertise, Formation et Support