X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 21365D1B487 for ; Mon, 22 Dec 2003 11:04:55 +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 94268-09 for ; Mon, 22 Dec 2003 07:04:07 -0400 (AST) Received: from serwer.skawsoft.com.pl (skawina.eu.org [80.48.213.66]) by svr1.postgresql.org (Postfix) with ESMTP id 236E4D1B4CF for ; Mon, 22 Dec 2003 07:04:04 -0400 (AST) Received: from klaster.net (core-1.citynet.pl [80.48.135.69]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id A53DF2B3CB; Mon, 22 Dec 2003 12:03:32 +0100 (CET) Message-ID: <3FE6CF91.6070300@klaster.net> Date: Mon, 22 Dec 2003 12:03:45 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.5) Gecko/20031007 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Ryszard Lach Cc: pgsql-performance@postgresql.org Subject: Re: "select max/count(id)" not using index References: <20031222103918.GA23673@siaco.id.pl> In-Reply-To: <20031222103918.GA23673@siaco.id.pl> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/282 X-Sequence-Number: 5142 Dnia 2003-12-22 11:39, Użytkownik Ryszard Lach napisał: > Hi. > > I have a table with 24k records and btree index on column 'id'. Is this > normal, that 'select max(id)' or 'select count(id)' causes a sequential > scan? It takes over 24 seconds (on a pretty fast machine): 'select count(id)' Yes, this is normal. Because of MVCC all rows must be checked and Postgres doesn't cache count(*) like Mysql. 'select max(id)' This is also normal, but try to change this query into: select id from some_table order by id desc limit 1; What is your Postgresql version? Regards, Tomasz Myrta