X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4CC84D1B4EA for ; Thu, 2 Oct 2003 19:01:26 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 53374-09 for ; Thu, 2 Oct 2003 16:00:40 -0300 (ADT) Received: from mta9.adelphia.net (mta9.adelphia.net [68.168.78.199]) by svr1.postgresql.org (Postfix) with ESMTP id 19FA2D1B522 for ; Thu, 2 Oct 2003 16:00:24 -0300 (ADT) Received: from potentialtech.com ([24.53.179.151]) by mta9.adelphia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20031002190022.URU20786.mta9.adelphia.net@potentialtech.com>; Thu, 2 Oct 2003 15:00:22 -0400 Message-ID: <3F7C75C3.4060904@potentialtech.com> Date: Thu, 02 Oct 2003 15:00:19 -0400 From: Bill Moran User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.3) Gecko/20030429 X-Accept-Language: en-us, en MIME-Version: 1.0 Cc: rwu@cbnco.com, Postgresql Performance Subject: Re: low cardinality column References: <33423.207.164.182.8.1065119401.squirrel@mail.cbnco.com> <1065120643.89807.40.camel@jester> In-Reply-To: <1065120643.89807.40.camel@jester> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/57 X-Sequence-Number: 3805 Rod Taylor wrote: > On Thu, 2003-10-02 at 14:30, Rong Wu wrote: > >>Hi, >> >>I have a select like this: >> >>SELECT MAX(transactionid) FROM cbntransaction WHERE transactiontypeid=0; > > > For various reasons (primarily MVCC and the ability to make custom > aggregates making it difficult) MAX() is not optimized in this fashion. > > Try: > > SELECT transactionid > FROM ... > WHERE ... > ORDER BY transactionid DESC > LIMIT 1; Despite this good suggestion, if you're using this technique to generate the next transaction ID, you're going to have errors as concurrency rises. Use a SERIAL, which guarantees that you won't have two processes generate the same number. -- Bill Moran Potential Technologies http://www.potentialtech.com