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 610329FB25A for ; Thu, 17 Aug 2006 17:13:28 -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 77707-07 for ; Thu, 17 Aug 2006 17:13:22 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mailout.zetnet.co.uk (mailout.zetnet.co.uk [194.247.47.231]) by postgresql.org (Postfix) with ESMTP id 248C19FA682 for ; Thu, 17 Aug 2006 17:13:22 -0300 (ADT) Received: from irwell.zetnet.co.uk ([194.247.47.48] helo=zetnet.co.uk) by mailout.zetnet.co.uk with esmtp (Exim 4.50) id 1GDoEz-0005jk-G7; Thu, 17 Aug 2006 21:13:21 +0100 Received: from [192.168.0.2] (55-038.adsl.zetnet.co.uk [194.247.55.38]) by zetnet.co.uk (8.13.6/8.13.6/Debian-1) with ESMTP id k7HKDKR4016124; Thu, 17 Aug 2006 21:13:20 +0100 Received: from 127.0.0.1 (AVG SMTP 7.1.405 [268.11.2/422]); Thu, 17 Aug 2006 21:13:11 +0100 From: "Peter Hardman" To: Tom Lane , pgsql-performance@postgresql.org Date: Thu, 17 Aug 2006 21:13:11 +0100 MIME-Version: 1.0 Subject: Re: PostgreSQL runs a query much slower than BDE and MySQL Message-ID: <44E4DBE7.22131.10181D0@peter.ssbg.zetnet.co.uk> In-reply-to: <18261.1155839607@sss.pgh.pa.us> References: <5321.1155820310@sss.pgh.pa.us> X-mailer: Pegasus Mail for Windows (4.31) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.011 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200608/288 X-Sequence-Number: 20473 On 17 Aug 2006 at 14:33, Tom Lane wrote: > I wrote: > > Anywy, your point about the sort being redundant is a good one, and > > offhand I'd have expected PG to catch that; I'll have to look into > > why it didn't. But that's not going to explain a 10x speed > > difference, because the sort isn't 90% of the runtime. > > I dug into this using some made-up test data, and was able to reproduce > the plan you got after changing the order of the pkey index columns > to (regn_no, transfer_date, flock_no) ... are you sure you quoted that > accurately before? Yes. Maybe the data I've uploaded to www.shetland- sheep.org.uk/pgdata/sheep_flock.zip will help reproduce the plan. > I found a couple of minor planner problems, which I've repaired in CVS > HEAD. You might consider using TEXT columns instead of VARCHAR(n), > because the only bug that actually seemed to change the chosen plan > involved the planner getting confused by the difference between > varchar_var and varchar_var::text (which is what gets generated for > sorting purposes because varchar doesn't have a separate sort operator). As someone else suggested, these fields ought really to be CHAR no VARCHAR. I chose VARCHAR because the data mostly is shorter than the maximum lengths (although probably not enough to matter). I'd not really got into the subtleties of different behaviour of CHAR and VARCHAR. > Regards,-- Peter Hardman Acre Cottage, Horsebridge King's Somborne Stockbridge SO20 6PT == Breeder of Shetland Cattle and Shetland Sheep ==