Re: 200 times slower then MSSQL??

From: PFC <lists(at)boutiquenumerique(dot)com>
To: "Alexander Dolgin" <alex(at)dolgin(dot)dp(dot)ua>, pgsql-performance(at)postgresql(dot)org
Subject: Re: 200 times slower then MSSQL??
Date: 2005-01-26 21:10:19
Message-ID: opsk8afhjmth1vuj@musicbox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


> with about 8000 rows. For this table query:
>
> SELECT MAX(MsgSeqNum),MAX(LogTimestamp) FROM ELT_tcli_MessageLog
> WHERE LogTimestamp >= '0' AND IsFromCounterParty = 'Y' AND
> IsOutOfSequence = 'N'
> AND ConnectionName = 'DB_BENCHMARK'
> AND LogTimestamp IN (SELECT MAX(LogTimestamp)
> FROM ELT_tcli_MessageLog
> WHERE MsgSeqNum > 0 AND IsFromCounterParty =
> 'Y'
>
> AND IsOutOfSequence = 'N' AND
> ConnectionName = 'DB_BENCHMARK')
>

Can you explain (with words) what this query is supposed to return ? It
is probably possible to write it in an entirely different way.
Basically your problem is that max() in postgres does not use an index
the way you think it should.
"SELECT max(x) FROM t" should be written "SELECT x FROM t ORDER BY x DESC
LIMIT 1" to use the index. Depending on additional Where conditions, you
should add other columns to your index and also order-by clause.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message PFC 2005-01-26 21:24:34 Re: [SQL] OFFSET impact on Performance???
Previous Message Thomas F.O'Connell 2005-01-26 20:14:35 Re: Upgrading from from 7.4.2 to 8.0