X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 57E299FA13E for ; Tue, 13 Jun 2006 18:31:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 28571-07 for ; Tue, 13 Jun 2006 18:31:18 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id E33229F9316 for ; Tue, 13 Jun 2006 18:31:17 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id 4CA1F5648A; Tue, 13 Jun 2006 16:13:49 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Tue, 13 Jun 2006 16:13:47 -0500 Date: Tue, 13 Jun 2006 16:13:47 -0500 From: "Jim C. Nasby" To: Shaun Thomas Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Confirmation of bad query plan generated by 7.4 Message-ID: <20060613211347.GB34196@pervasive.com> References: <9119.1150222168@sss.pgh.pa.us> <448EDFC4.8F27.00A9.0@leapfrogonline.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <448EDFC4.8F27.00A9.0@leapfrogonline.com> X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:060613:sthomas@leapfrogonline.com::xU1rbYrnT8a1To6Y:00000000000 0000000000000000000000003FaM X-Hashcash: 1:20:060613:tgl@sss.pgh.pa.us::naJQaI1l3BJlTn3o:00000000000000000000 000000000000000000000000AeL7 X-Hashcash: 1:20:060613:pgsql-performance@postgresql.org::Z6vqqiKRu1eqMouT:00000 0000000000000000000000006gP4 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/209 X-Sequence-Number: 19566 On Tue, Jun 13, 2006 at 03:54:44PM -0500, Shaun Thomas wrote: > >>> On 6/13/2006 at 1:09 PM, Tom Lane wrote: > > > I missed the part where you explain why you think this plan is > terrible? > > 412ms for what seems a rather expensive query doesn't sound so > awful. > > Sorry, I based that statement on the estimated/actual disparity. That > particular query plan is not terrible in its results, but look at the > estimates and how viciously the explain analyze corrects the values. > > Here's an example: > > -> Index Scan using idx_evt_dt on l_event_log e > (cost=0.00..2641742.75 rows=15752255 width=12) > (actual time=0.034..229.641 rows=38923 loops=1) > > rows=15752255 ? That's over half the 27M row table. As expected, the > *actual* match is much, much lower at 38923. As it turns out, Marcin > was right. Simply changing: > > now() - interval '2 days' > > to > > '2006-06-11 15:30:00' > > generated a much more accurate set of estimates. I have to assume > that > 7.4 is incapable of that optimization step. Now that I know this, I > plan on modifying my stored proc to calculate the value before > inserting > it into the query. Is there some compelling reason to stick with 7.4? In my experience you'll see around double (+100%) the performance going to 8.1... Also, I'm not sure that the behavior is entirely changed, either. On a 8.1.4 database I'm still seeing a difference between now() - interval and a hard-coded date. What's your stats target set to for that table? > -- > Shaun Thomas > Database Administrator > > Leapfrog Online > 807 Greenwood Street > Evanston, IL 60201 Heh, I grew up 3 miles from there. In fact, IIRC my old dentist is/was at 807 Davis. > Tel. 847-440-8253 > Fax. 847-570-5750 > www.leapfrogonline.com -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461