| From: | Bill Moran <wmoran(at)potentialtech(dot)com> |
|---|---|
| To: | |
| Cc: | rwu(at)cbnco(dot)com, Postgresql Performance <pgsql-performance(at)postgresql(dot)org> |
| Subject: | Re: low cardinality column |
| Date: | 2003-10-02 19:00:19 |
| Message-ID: | 3F7C75C3.4060904@potentialtech.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dror Matalon | 2003-10-02 19:15:47 | count(*) slow on large tables |
| Previous Message | Rod Taylor | 2003-10-02 18:50:44 | Re: low cardinality column |