Category Product Count Performance

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
dc8johnson
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 87
Joined: Fri Nov 20, 2009 8:46 am

Category Product Count Performance

Post by dc8johnson » Wed Jul 14, 2010 10:49 am

We have a site that is checked daily for problems by McAfee Secure (http://www.mcafeesecure.com). We've noticed a large spike in SQL activity during a portion of their scan. Our database administrator ran a trace during one of these episodes and found the following query is responsible for 33% of the CPU usage and 94% of all page reads. This looks to be the query that is called to provide the Narrow by Category list with the product count.

Code: Select all

exec sp_executesql N'SELECT COUNT(DISTINCT P.ProductId) As TotalProducts FROM  (ac_Products P INNER JOIN ac_CatalogNodes PC ON P.ProductId = PC.CatalogNodeId) WHERE PC.CatalogNodeTypeId = 1 AND P.ProductId IN (SELECT DISTINCT P.ProductId FROM (ac_Products P INNER JOIN ac_CatalogNodes PC ON P.ProductId = PC.CatalogNodeId) WHERE P.StoreId = @storeId AND PC.CatalogNodeTypeId = 1 AND PC.CategoryId IN (SELECT CategoryId FROM ac_CategoryParents WHERE ParentId = @categoryId) AND P.VisibilityId = 0)',N'@storeId int,@categoryId int',@storeId=1,@categoryId=14
Our database administrator has reviewed this query and suggested that the following change would have no affect on the data output but would reduce the cost of the query by 2.9 times.

Code: Select all

exec sp_executesql N'SELECT COUNT(DISTINCT P.ProductId) As TotalProducts FROM (ac_Products P INNER JOIN ac_CatalogNodes PC ON P.ProductId = PC.CatalogNodeId) WHERE P.StoreId = @storeId AND PC.CatalogNodeTypeId = 1 AND PC.CategoryId IN (SELECT CategoryId FROM ac_CategoryParents WHERE ParentId = @categoryId) AND P.VisibilityId = 0',N'@storeId int,@categoryId int',@storeId=1,@categoryId=14
Since this query is part of the CommerceBuilder code, I am passing this on to you.

I hope this is useful.
David Johnson

User avatar
Kalamazoo
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 42
Joined: Wed Apr 01, 2009 6:10 pm

Re: Category Product Count Performance

Post by Kalamazoo » Sun Jul 25, 2010 12:41 pm

Hi David,

I am having server trouble with an AC7.03 store with this very issue. Can you let me know what version you are running by chance?

Thanks for the information.

Phil Chrisman

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Category Product Count Performance

Post by jmestep » Mon Jul 26, 2010 7:09 am

We found that out with a site with many products and it narrowed down to this in a category page
_SearchResultCount = ProductDataSource.NarrowSearchCount(_Keywords, this.CategoryId, _ManufacturerId, 0, 0, SortResults.SelectedValue.StartsWith("IsFeatured"));
or this
int totalProducts = ProductDataSource.NarrowSearchCount(_Keywords, category.CategoryId, _ManufacturerId, 0, 0);
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

dc8johnson
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 87
Joined: Fri Nov 20, 2009 8:46 am

Re: Category Product Count Performance

Post by dc8johnson » Fri Jul 30, 2010 2:48 pm

We are using 7.0.4 but I think it is the same query being used in 7.0.3.

Our site has about 20,000 active products and it is the total products that is the issue. We understand that the query isn't going to be fast. Our DBA reviewed the query and believes it can be optimized by changing as suggested.

I hope that clarifies things.
David Johnson

Post Reply