X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1B3F352953 for ; Tue, 19 Apr 2005 21:42:33 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83475-05 for ; Wed, 20 Apr 2005 00:42:31 +0000 (GMT) Received: from flake.decibel.org (flake.decibel.org [67.100.216.10]) by svr1.postgresql.org (Postfix) with ESMTP id D644352957 for ; Tue, 19 Apr 2005 21:42:30 -0300 (ADT) Received: by flake.decibel.org (Postfix, from userid 1001) id 2845E15486; Tue, 19 Apr 2005 19:42:34 -0500 (CDT) Date: Tue, 19 Apr 2005 19:42:34 -0500 From: "Jim C. Nasby" To: Dave Held Cc: pgsql-performance@postgresql.org Subject: Re: Sort and index Message-ID: <20050420004234.GX58835@decibel.org> References: <49E94D0CFCD4DB43AFBA928DDD20C8F9026184B6@asg002.asg.local> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <49E94D0CFCD4DB43AFBA928DDD20C8F9026184B6@asg002.asg.local> X-Operating-System: FreeBSD 4.11-RELEASE i386 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.8i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.014 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/477 X-Sequence-Number: 11874 On Mon, Apr 18, 2005 at 10:44:43AM -0500, Dave Held wrote: > Since you are fetching the entire table, you are touching all the rows. > If the query were to fetch the rows in index order, it would be seeking > all over the table's tracks. By fetching in sequence order, it has a > much better chance of fetching rows in a way that minimizes head seeks. > Since disk I/O is generally 10-100x slower than RAM, the in-memory sort > can be surprisingly slow and still beat indexed disk access. Of course, > this is only true if the table can fit and be sorted entirely in memory > (which, with 1500 rows, probably can). Actually, the planner (at least in 7.4) isn't smart enough to consider if the sort would fit in memory or not. I'm running a test right now to see if it's actually faster to use an index in this case. -- Jim C. Nasby, Database Consultant decibel@decibel.org Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?"