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 84AB1D1B514 for ; Thu, 2 Oct 2003 18:40:53 +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 53979-01 for ; Thu, 2 Oct 2003 15:40:07 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 16945D1B4EF for ; Thu, 2 Oct 2003 15:40:06 -0300 (ADT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3707726; Thu, 02 Oct 2003 11:39:50 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: rwu@cbnco.com, pgsql-performance@postgresql.org Subject: Re: low cardinality column Date: Thu, 2 Oct 2003 11:37:22 -0700 User-Agent: KMail/1.4.3 References: <33423.207.164.182.8.1065119401.squirrel@mail.cbnco.com> In-Reply-To: <33423.207.164.182.8.1065119401.squirrel@mail.cbnco.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200310021137.22119.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/55 X-Sequence-Number: 3803 Rong, > I have a select like this: >=20 > SELECT MAX(transactionid) FROM cbntransaction WHERE transactiontypeid=3D0; Simple workaround: Create an mulit-column index on transactiontypeid, transactionid. SELECT transactionid FROM cbtransaction=20 WHERE transactiontypeid=3D0 ORDER BY transactionid DESC LIMIT 1; This approach will use the index. Of course, if the reason you are selecting the max id is to get the next id= ,=20 there are much better ways to do that. --=20 -Josh Berkus Aglio Database Solutions San Francisco