Re: low cardinality column

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: rwu(at)cbnco(dot)com, pgsql-performance(at)postgresql(dot)org
Subject: Re: low cardinality column
Date: 2003-10-02 18:37:22
Message-ID: 200310021137.22119.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Rod Taylor 2003-10-02 18:50:44 Re: low cardinality column
Previous Message Rong Wu 2003-10-02 18:30:01 low cardinality column