From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: LN Cisneros <chulat@mail.com>
To: pgsql-performance@postgresql.org
Subject: Re: rewrite in to exists?
Date: Thu, 18 Sep 2003 13:23:37 +0800
Message-ID: <08cd01c37da5$04cd5ff0$2800a8c0@mars> (raw)
References: <20399973.1063861169740.JavaMail.root@rowlf.psp.pas.earthlink.net>
> I'm on 7.3.4 and this query gets horrible performance. Is there a way to
rewrite it with an exists or some way to get better performance?
>
> select code, id, name, date_of_service
> from tbl
> where date_of_service in
> (select date_of_service
> from tbl
> where xxx >= '29800'
> and xxx <= '29909'
> and code = 'XX')
> and client_code = 'XX'
> order by id, date_of_service;
????
Why can't you just go:
select code, id, name, date_of_service from tbl where xxx <= 29800 and xx >=
29909 and code='XX' and client_code='XX' order by id, date_of_service;
Or use a between clause is nice:
select code, id, name, date_of_service from tbl where xxx between 29800 and
29909 and code='XX' and client_code='XX' order by id, date_of_service;
But seriously - your query above is referencing 'tbl' twice - is that
correct, or is the tbl in the subselect supposed to be something different?
Chris
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: chriskl@familyhealth.com.au, chulat@mail.com
Subject: Re: rewrite in to exists?
In-Reply-To: <08cd01c37da5$04cd5ff0$2800a8c0@mars>
References: <20399973.1063861169740.JavaMail.root@rowlf.psp.pas.earthlink.net> <08cd01c37da5$04cd5ff0$2800a8c0@mars>
* 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