Re: rewrite in to exists?

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "LN Cisneros" <chulat(at)mail(dot)com>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: rewrite in to exists?
Date: 2003-09-18 05:23:37
Message-ID: 08cd01c37da5$04cd5ff0$2800a8c0@mars
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> 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

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Alexander Priem 2003-09-18 08:13:11 Many fields in one table or many tables?
Previous Message LN Cisneros 2003-09-18 04:59:29 rewrite in to exists?