Re: low cardinality column - Mailing list pgsql-performance

From Bill Moran
Subject Re: low cardinality column
Date
Msg-id 3F7C75C3.4060904@potentialtech.com
Whole thread Raw
In response to Re: low cardinality column  (Rod Taylor <rbt@rbt.ca>)
Responses Thanks - Re: low cardinality column
List pgsql-performance
Rod Taylor wrote:
> 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;

Despite this good suggestion, if you're using this technique to generate
the next transaction ID, you're going to have errors as concurrency rises.

Use a SERIAL, which guarantees that you won't have two processes generate
the same number.

--
Bill Moran
Potential Technologies
http://www.potentialtech.com


pgsql-performance by date:

Previous
From: Rod Taylor
Date:
Subject: Re: low cardinality column
Next
From: Dror Matalon
Date:
Subject: count(*) slow on large tables