Re: low cardinality column - Mailing list pgsql-performance

From Josh Berkus
Subject Re: low cardinality column
Date
Msg-id 200310021137.22119.josh@agliodbs.com
Whole thread Raw
In response to low cardinality column  ("Rong Wu" <rwu@cbnco.com>)
List 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


pgsql-performance by date:

Previous
From: "Rong Wu"
Date:
Subject: low cardinality column
Next
From: Rod Taylor
Date:
Subject: Re: low cardinality column