Re: Extremely slow IN clause
- From: "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
- Date: Wed, 20 Apr 2005 18:04:12 -0400
The use of a LEFT JOIN instead of an INNER JOIN in Query2 looks suspect to
me. Also, if you need only the ID value, then selecting the fields Field1,
Field2, Field3, Latest and Table2.[Other Fields] in Query2 are useless.
Most of the time, you shoud only select the required field(s), even if that
means writing another query.
However, this doesn't explain the big change in speed. Maybe a look at the
query plan used by Access will give you some insight on this:
http://builder.com.com/5100-6388_14-5064388.html
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
"Carl Rapson" <cr@xxxxxxxxxxx> wrote in message
news:%23Zv6xEbRFHA.508@xxxxxxxxxxxxxxxxxxxxxxx
> Sylvain,
>
> Query2 is a query object, not created in code. I refer to Query2 in the
> filter string:
>
> ...WHERE ID IN (SELECT ID FROM [Query2])...
>
> Query2 is built as follows:
>
> Base Query:
> SELECT DISTINCT Field1,Field2,Field3,MAX(Field4) AS Latest
> FROM Table2
> GROUP BY Field1,Field2,Field3;
>
> Query2:
> SELECT Field1,Field2,Field3,Latest,Table2.ID,Table2.[Other Fields]
> FROM [Base Query] LEFT JOIN [Table2]
> ON ([Base Query].Field1=Table2.Field1)
> AND ([Base Query].Field2=Table2.Field2)
> AND ([Base Query].Field3=Table2.Field3)
> AND ([Base Query].Latest=Table2.Field4)
>
> So Query2 returns only records from Table2 that have Field4=MAX(Field4).
>
> BTW, I tried your earlier suggestion about using a temporary table, and
> that speeds things up considerably. Before I build my filter string, I
> populate the temporary table with the ID values from Query2, then I use
> the temporary table in my filter string (WHERE ID IN (SELECT ID FROM
> temptable)). So it appears it's not the IN clause per se, but something
> about using Query2 in the IN clause that is so slow. I'm not completely
> happy with this way of doing it, but if I can't figure out how to speed up
> the IN clause I will probably continue to use it.
>
> Thanks again,
>
> Carl
>
> "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
> wrote in message news:uB%236nhSRFHA.3312@xxxxxxxxxxxxxxxxxxxxxxx
>> What's the code for Query2?
>>
>> Also, have you created a query object for Query2 or if you write its
>> entire code in filterstr?
>>
>> Finally, by using parameters directly in Query2, it is possible that you
>> will get some speed up.
>>
>> --
>> Sylvain Lafontaine, ing.
>> MVP - Technologies Virtual-PC
>>
>
>
.
- Follow-Ups:
- Re: Extremely slow IN clause
- From: Carl Rapson
- Re: Extremely slow IN clause
- References:
- Extremely slow IN clause
- From: Carl Rapson
- Re: Extremely slow IN clause
- From: Sylvain Lafontaine
- Re: Extremely slow IN clause
- From: Carl Rapson
- Re: Extremely slow IN clause
- From: Sylvain Lafontaine
- Re: Extremely slow IN clause
- From: Carl Rapson
- Extremely slow IN clause
- Prev by Date: Can a join query be accessed directly by a novice user?
- Next by Date: Re: Strange format of the result of caculated control..
- Previous by thread: Re: Extremely slow IN clause
- Next by thread: Re: Extremely slow IN clause
- Index(es):
Relevant Pages
|