Re: Why is this query so slow
- From: "John Spencer" <spencer@xxxxxxxxx>
- Date: Tue, 18 Sep 2007 08:19:42 -0400
Why bother with a LEFT JOIN since you are negating the effects of the left
join by applying criteria to the table on the right?
SELECT
Count(RISK_TBL_OFFERSLOT.FLOORAMOUNT)/2 AS Hours,
Avg([CAPAMOUNT]*1000) AS [Price ($/MWh)],
Avg(Abs([KW])/1000) AS [Capacity (MW)]
FROM tbl_ElecContractsTemp INNER JOIN RISK_TBL_OFFERSLOT
ON tbl_ElecContractsTemp.OfferCD = RISK_TBL_OFFERSLOT.OFFERCD
WHERE RISK_TBL_OFFERSLOT.VALIDTO=0
AND tbl_ElecContractsTemp.OfferCD Is Not Null
GROUP BY RISK_TBL_OFFERSLOT.OFFERCD;
Beyond that I can see no reason for the query to take a long time assuming
that there is not a large number of records and that you have indexes on
these three fields
tbl_ElecContractsTemp.OfferCD
RISK_TBL_OFFERSLOT.OFFERCD
RISK_TBL_OFFERSLOT.VALIDTO=0
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
"MarkS" <MarkS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:77188AA6-D632-4595-823B-7703900B9940@xxxxxxxxxxxxxxxx
Hi,
SELECT
Count(RISK_TBL_OFFERSLOT.FLOORAMOUNT)/2 AS Hours,
Avg([CAPAMOUNT]*1000) AS [Price ($/MWh)],
Avg(Abs([KW])/1000) AS [Capacity (MW)]
FROM tbl_ElecContractsTemp LEFT JOIN RISK_TBL_OFFERSLOT
ON tbl_ElecContractsTemp.OfferCD = RISK_TBL_OFFERSLOT.OFFERCD
WHERE (((RISK_TBL_OFFERSLOT.VALIDTO)=0)
AND ((tbl_ElecContractsTemp.OfferCD) Is Not Null))
GROUP BY RISK_TBL_OFFERSLOT.OFFERCD;
The tbl_ElecContractsTemp is a local access table and RISK_TBL_OFFERSLOT
is
remote linked table. With only one OfferCD in tbl_ElecContractsTemp I have
let the query run for 10 minutes before killing it. If I put the OfferCD
into
the query it runs in about 7 seconds.
Thanks MarkS
.
- Prev by Date: Re: Wierd behavior while inserting a record...
- Next by Date: Changing Combobox to text box
- Previous by thread: Re: Wierd behavior while inserting a record...
- Next by thread: Changing Combobox to text box
- Index(es):
Relevant Pages
|