Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 73F59B607B7 for ; Wed, 1 Jun 2011 22:33:39 -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 11687-08 for ; Thu, 2 Jun 2011 01:33:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qw0-f46.google.com (mail-qw0-f46.google.com [209.85.216.46]) by mail.postgresql.org (Postfix) with ESMTP id 7970FB607AC for ; Wed, 1 Jun 2011 22:33:32 -0300 (ADT) Received: by qwk3 with SMTP id 3so174179qwk.19 for ; Wed, 01 Jun 2011 18:33:32 -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:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=6MXRE1ctRq01KjJ+Q+KRcd/uMyYuAkTYMhpoqJPYcls=; b=b0rw3/Qq3PSmv0W8QFIdGFQtYRX+pSHvBFRPmgbP24g2RB7qJhqhe2yT+DqtdWqqWP 2SP2n0VlADo5zKId5XmzfHensHsLHzHYPQhxx+mzdI0UI5URUtQPNqyo38p3jQZVrG1k nbN7MrhjxM41F5ifihciFByJU73/ojjYLyp+o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=mqSKW1zTVC1GzaqiwlILIqGXY87ApIkmgKG2Y+RlKVcA8NDywrE+poNohguKKURDNs u2zJR44YX5f7ocaRnyG14qAj3t/LM7cRcOrUzkFA1O8lSi/xZh1fWR1OhS/IUoolFwMy poy65XPT8c+B2Y3sUohihMP1srwTzyJK3b/ow= MIME-Version: 1.0 Received: by 10.224.216.70 with SMTP id hh6mr114942qab.83.1306978412607; Wed, 01 Jun 2011 18:33:32 -0700 (PDT) Received: by 10.224.54.147 with HTTP; Wed, 1 Jun 2011 18:33:32 -0700 (PDT) In-Reply-To: References: Date: Wed, 1 Jun 2011 21:33:32 -0400 Message-ID: Subject: Re: CLUSTER versus a dedicated table From: Merlin Moncure To: Robert James 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: 201106/14 X-Sequence-Number: 43947 On Wed, Jun 1, 2011 at 7:54 PM, Robert James wrote= : > Hi. =A0I'm interested in understanding the differences between > CLUSTERing a table and making a dedicated one. > > We have a table with about 1 million records. =A0On a given day, only > about 1% of them are of interest. =A0That 1% changes every day (it's > WHERE active_date =3D today), and so we index and cluster on it. > > Even so, the planner shows a very large cost for the Index Scan: about > 3500. =A0If I instead do a SELECT INTO temp_table FROM big_table WHERE > active_date =3D today, and then do SELECT * FROM temp_table, I get a > planned cost of 65. =A0Yet, the actual time for both queries is almost > identical. > > Questions: > 1. Why is there such a discrepancy between the planner's estimate and > the actual cost? > > 2. In a case like this, will I in general see a performance gain by > doing a daily SELECT INTO and then querying from that table? My ad hoc > test doesn't indicate I would (despite the planner's prediction), and > I'd rather avoid this if it won't help. > > 3. In general, does CLUSTER provide all the performance benefits of a > dedicated table? If it doesn't, what does it lack? no. i suspect you may be over thinking the problem -- what led you to want to cluster in the first place? merlin