optimizing subqueries with in operator
From: Richard Gjerde (richard_gjerde_at_yahoo.no)
Date: 05/11/04
- Next message: Ilya Margolin: "Re: parsing SQL"
- Previous message: Michael Cheng [MSFT]: "Re: Stopping multiple connections"
- Next in thread: Louis Davidson: "Re: optimizing subqueries with in operator"
- Reply: Louis Davidson: "Re: optimizing subqueries with in operator"
- Reply: Steve Kass: "Re: optimizing subqueries with in operator"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 11 May 2004 15:00:51 +0200
Can anybody help me with the following problem?
I have a table A with columns A_1, ..., A_n and I want to select those rows
where A_i has the same value as it has on those rows where A_k has a certain
value. I have tried the following query:
select * from A where A_i in (select A_i from A where A_k = 'some value')
The problem is that this query is terribly slow. If I know in advance that
the subquery only returns one row and use "=" instead of "in", it is much
more efficient, but I cannot in general assume this. I have tried various
other things like self join and using "exists", but I have not been able to
improve efficiency much. With a test table with random data and 3,5 million
rows this query takes more than one minute on MSsql while on Oracle after
optimizing it takes 0,1 seconds!
- Next message: Ilya Margolin: "Re: parsing SQL"
- Previous message: Michael Cheng [MSFT]: "Re: Stopping multiple connections"
- Next in thread: Louis Davidson: "Re: optimizing subqueries with in operator"
- Reply: Louis Davidson: "Re: optimizing subqueries with in operator"
- Reply: Steve Kass: "Re: optimizing subqueries with in operator"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|