Thread: optimize sql

optimize sql

From
pgsql-sql@fc.emc.com.ph (pgsql-sql)
Date:
HI!

The SQL below is too slow.

SELECT name FROM office, office_application 
WHERE code = office_code 
AND name NOT IN
(SELECT DISTINCT name FROM office, office_application
WHERE active = 't' AND code = office_code);

Can anyone tell me how to optimize it?
Thanks.




Re: optimize sql

From
"Ross J. Reedstrom"
Date:
On Wed, Jul 26, 2000 at 10:11:15PM +0800, pgsql-sql wrote:
> HI!
> 
> The SQL below is too slow.
> 
> SELECT name FROM office, office_application 
> WHERE code = office_code 
> AND name NOT IN
> (SELECT DISTINCT name FROM office, office_application
> WHERE active = 't' AND code = office_code);
> 

How does the output of the above differ from:

SELECT name FROM office, office_application 
WHERE code = office_code 
AND active != 't';

Without knowing the table structures (which tables to active, code, 
and office_code belong to?) it's hard to suggest much else.

Ross
-- 
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu> 
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005