pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PFC <lists@boutiquenumerique.com>
To: Alexander Dolgin <alex@dolgin.dp.ua>
To: pgsql-performance@postgresql.org
Subject: Re: 200 times slower then MSSQL??
Date: Wed, 26 Jan 2005 22:10:19 +0100
Message-ID: <opsk8afhjmth1vuj@musicbox> (raw)
In-Reply-To: <E1Ct8wq-0008En-00@lata.dp.ua>
References: <E1Ct8wq-0008En-00@lata.dp.ua>


> 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.



view thread (5+ messages)

Message-ID: <opsk8afhjmth1vuj@musicbox>
Permalink:  ../opsk8afhjmth1vuj@musicbox/
Also on:    postgresql.org/message-id/opsk8afhjmth1vuj@musicbox

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: lists@boutiquenumerique.com, alex@dolgin.dp.ua
  Subject: Re: 200 times slower then MSSQL??
  In-Reply-To: <opsk8afhjmth1vuj@musicbox>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox