From: Josh Berkus <josh@agliodbs.com>
To: rwu@cbnco.com
To: pgsql-performance@postgresql.org
Subject: Re: low cardinality column
Date: Thu, 2 Oct 2003 11:37:22 -0700
Message-ID: <200310021137.22119.josh@agliodbs.com> (raw)
In-Reply-To: <33423.207.164.182.8.1065119401.squirrel@mail.cbnco.com>
References: <33423.207.164.182.8.1065119401.squirrel@mail.cbnco.com>
Rong,
> I have a select like this:
>
> SELECT MAX(transactionid) FROM cbntransaction WHERE transactiontypeid=0;
Simple workaround:
Create an mulit-column index on transactiontypeid, transactionid.
SELECT transactionid FROM cbtransaction
WHERE transactiontypeid=0
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,
there are much better ways to do that.
--
-Josh Berkus
Aglio Database Solutions
San Francisco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: josh@agliodbs.com, rwu@cbnco.com
Subject: Re: low cardinality column
In-Reply-To: <200310021137.22119.josh@agliodbs.com>
References: <33423.207.164.182.8.1065119401.squirrel@mail.cbnco.com> <200310021137.22119.josh@agliodbs.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox