Hi all
I am really new to mySQL, and have just completed my first web app using mySQL instead of Access. The problem is that users are reporting that the app is running very slowly and I suspect it may be something to do with the following query:
<cfquery name="GetOffers" datasource="#ThisDSN#">
SELECT products.ID AS PartID,
products.PartCode AS PCode,
products.Msg AS Msg,
offers.ID AS ID,
offers.OfferCode AS OfferCode,
offers.PriceBand AS PriceBand,
offers.PartTitle AS PartTitle,
offers.PricePrefix,
products.PartCode AS PartCode,
products.FreeText AS FT,
Left(offers.Description,#NoChars#) AS PartDesc
FROM products
LEFT JOIN offers ON products.ID = offers.PartID
LEFT JOIN publications ON publications.ID = offers.PubID
LEFT JOIN brands ON brands.ID = publications.BrandID
LEFT JOIN sites ON sites.ID = brands.SiteID
LEFT JOIN categories ON categories.ID = products.CatID
LEFT JOIN sections ON sections.ID = categories.SectionID
<CFIF URL.NEW is 1>
WHERE (StartDate >= #CREATEODBCDATETIME(DayB4Yesterday)#
AND EndDate > #CREATEODBCDATETIME(REQUEST.TODAYSTART)#)
OR products.New = 1
<CFELSE>
WHERE (StartDate <= #CREATEODBCDATETIME(REQUEST.TODAYSTART)#
AND EndDate > #CREATEODBCDATETIME(REQUEST.TODAYSTART)#)
</CFIF>
<CFIF REQUEST.EXPRESSION IS NOT "">
AND (
offers.OfferCode LIKE '%#REQUEST.EXPRESSION#%'
OR offers.Description LIKE '%#REQUEST.EXPRESSION#%'
OR offers.PartTitle LIKE '%#REQUEST.EXPRESSION#%'
)
</CFIF>
AND offers.DELETED = 0
AND sites.ID = #Request.SITE#
AND brands.ID = #REQUEST.BRAND#
<CFIF URL.SECTION GT 0>
AND sections.ID = #URL.SECTION#
</CFIF>
<CFIF URL.CATEGORY GT 0>
AND categories.ID = #URL.CATEGORY#
</CFIF>
<CFIF FA IS "SPECIALS">
AND offers.PriceBand = 3
</CFIF>
GROUP BY products.ID
ORDER BY products.PartTitle
</cfquery>
Huge isn't it?!
If anyone can see any immediate problems with it, I would be really grateful for any advice on how I can optimise it to make the app run a bit more quickly.
TIA for your help guys!
I am really new to mySQL, and have just completed my first web app using mySQL instead of Access. The problem is that users are reporting that the app is running very slowly and I suspect it may be something to do with the following query:
<cfquery name="GetOffers" datasource="#ThisDSN#">
SELECT products.ID AS PartID,
products.PartCode AS PCode,
products.Msg AS Msg,
offers.ID AS ID,
offers.OfferCode AS OfferCode,
offers.PriceBand AS PriceBand,
offers.PartTitle AS PartTitle,
offers.PricePrefix,
products.PartCode AS PartCode,
products.FreeText AS FT,
Left(offers.Description,#NoChars#) AS PartDesc
FROM products
LEFT JOIN offers ON products.ID = offers.PartID
LEFT JOIN publications ON publications.ID = offers.PubID
LEFT JOIN brands ON brands.ID = publications.BrandID
LEFT JOIN sites ON sites.ID = brands.SiteID
LEFT JOIN categories ON categories.ID = products.CatID
LEFT JOIN sections ON sections.ID = categories.SectionID
<CFIF URL.NEW is 1>
WHERE (StartDate >= #CREATEODBCDATETIME(DayB4Yesterday)#
AND EndDate > #CREATEODBCDATETIME(REQUEST.TODAYSTART)#)
OR products.New = 1
<CFELSE>
WHERE (StartDate <= #CREATEODBCDATETIME(REQUEST.TODAYSTART)#
AND EndDate > #CREATEODBCDATETIME(REQUEST.TODAYSTART)#)
</CFIF>
<CFIF REQUEST.EXPRESSION IS NOT "">
AND (
offers.OfferCode LIKE '%#REQUEST.EXPRESSION#%'
OR offers.Description LIKE '%#REQUEST.EXPRESSION#%'
OR offers.PartTitle LIKE '%#REQUEST.EXPRESSION#%'
)
</CFIF>
AND offers.DELETED = 0
AND sites.ID = #Request.SITE#
AND brands.ID = #REQUEST.BRAND#
<CFIF URL.SECTION GT 0>
AND sections.ID = #URL.SECTION#
</CFIF>
<CFIF URL.CATEGORY GT 0>
AND categories.ID = #URL.CATEGORY#
</CFIF>
<CFIF FA IS "SPECIALS">
AND offers.PriceBand = 3
</CFIF>
GROUP BY products.ID
ORDER BY products.PartTitle
</cfquery>
Huge isn't it?!
If anyone can see any immediate problems with it, I would be really grateful for any advice on how I can optimise it to make the app run a bit more quickly.
TIA for your help guys!