[PERFORM] low cardinality column

2003-10-03 Thread rwu . cbnco . com
Hi,

I have a select like this:

SELECT MAX(transactionid) FROM cbntransaction WHERE transactiontypeid=0;

in the query:
transactionid is the primary key of cbntransaction table,
But transactiontypeid is a low cardinality column, there're over 100,000
records has the same trnsactiontypeid.
I was trying to create an index on (transactiontypeid, transactionid), but
no luck on that, postgresql will still scan the table.
I'm wondering if there's solution for this query:
Maybe something like if I can partition the table using transactiontypeid,
and do a local index on transactionid on each partition, but I couldnt'
find any doc on postgresql to do that.

Thanks in advance,
rong :-)



---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [PERFORM] low cardinality column

2003-10-02 Thread Rod Taylor
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;


signature.asc
Description: This is a digitally signed message part