X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 042F3D1B4E1 for ; Sun, 26 Oct 2003 21:15:25 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 98583-06 for ; Sun, 26 Oct 2003 17:14:55 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 66146D1B51B for ; Sun, 26 Oct 2003 17:14:53 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id h9QLEqNu058132 for ; Sun, 26 Oct 2003 21:14:52 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h9QKqO6K055041 for pgsql-sql@postgresql.org; Sun, 26 Oct 2003 20:52:24 GMT From: Christopher Browne X-Newsgroups: comp.databases.postgresql.sql Subject: Re: index and min() Date: Sun, 26 Oct 2003 15:52:05 -0500 Organization: cbbrowne Computing Inc Lines: 25 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne User-Agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Reasonable Discussion, linux) Cancel-Lock: sha1:QRdjCTw6D2rg6CTpXWncZYlb6No= To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/336 X-Sequence-Number: 15736 In an attempt to throw the authorities off his trail, sarek@ozaba.cx transmitted: > SELECT min(inserttime) FROM acc_pb; which takes about 11 seconds to > complete. > > On the mssql server this takes less than 1 second. If you have NO index on inserttime, then the best that can be done is the sequential scan that you saw. If there is an index on inserttime, then the PostgreSQL idiom that provides a _massive_ speedup is the query: select inserttime from acc_pb order by inserttime limit 1; In theory, it ought to be a nifty idea to have a way of automatically transforming the min(inserttime) query into what I showed, but that is likely to be difficult to do in general, and nobody has yet proposed an implementation, so you'll have to do that yourself. -- let name="cbbrowne" and tld="acm.org" in String.concat "@" [name;tld];; http://www3.sympatico.ca/cbbrowne/x.html "Linux and other OSS advocates are making a progressively more credible argument that OSS software is at least as robust -- if not more -- than commercial alternatives." - Microsoft lamenting Open Source Software in the "Halloween Document"