Answered by:
Query execution is very slow

Question
-
hi
i m using sql serever 2005 management express to excecute my queries in ssms but it seems query execution is very slow it takes 2000 to 3000 millisecond to excute 22000 records (with 39 columns) for select query following is my query please tell me where i have making mistake
SELECT Product.ProductID, Product.ProductName, Product.UOM, Product.ExpDate,
Product.CreationDate, Product.LastUpdate, Product.Location, Product.OpeningQty,
Product.Manufacturer, Product.MFGCode, Product.Packing, Product.UnitCost,
Product.CompanyPrice, Product.TradePrice, Product.SalesPrice, Product.[Group],
Product.OpeningDate, Product.Supplier, Product.MinQty, Product.MaxQty, Product.ReOrderLevel,
Product.BNo, Product.QtyOut, Product.GroupID, Product.SupplierID, Product.LastSalesDate,
Product.LastPurchaseDate, Product.StoreID, Product.Photo, Product.ProgramID, Product.DealerPrice,
Product.TPDisc, Product.WholesalePrice, Product.OpeningUC, Product.ImagePath, Product.ShowVal,
CASE WHEN StockBalances.QtyBalance IS NULL THEN 0 ELSE StockBalances.QTYBALANCE END AS QtyBalance,
Product.Active FROM Product LEFT OUTER JOIN StockBalances ON Product.ProductID = StockBalances.ProductID
WHERE (Product.Active = 1)
Sunday, May 8, 2016 7:03 PM
Answers
-
but problem is that when i run this query in vb.net the result has been slow more from qeury run in sql server ssms
Your original question only mentioned SSMS and suggest SSMS was slow executing the query. If it is fast in SSMS and slow in your VP application, it may be that either the execution plans are different or the application code is less efficient in processing the result set.
Different execution plans for the same query suggests different session settings. See Erland's thorough discussion about this. Check the plan cache to verify different plans.
If the same plan is used, there may be some attention to detail needed in the code to improve performance of result set processing.
Dan Guzman, Data Platform MVP, http://www.dbdelta.com
- Marked as answer by Sam ZhaMicrosoft contingent staff Thursday, May 19, 2016 12:26 PM
Tuesday, May 10, 2016 12:04 PM
All replies
-
2-3 seconds to return 22000 rows does not seem unreasonable to me. There is both client and server processing time involved to the elapsed time depends on both the query execution time and the time it takes SSMS to retrieve and render the result.
I see you are returning what appears to be an image (Product.Photo), which could be up to 2GB. Try running the query without that column to see if the time improves.
Dan Guzman, Data Platform MVP, http://www.dbdelta.com
- Proposed as answer by Abdullah Altıntaş Sunday, May 8, 2016 8:41 PM
Sunday, May 8, 2016 7:49 PM -
Hi,
Can we see your execution plan? May be it helps us...
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
www.abdullahaltintas.comSunday, May 8, 2016 8:43 PM -
but problem is that when i run this query in vb.net the result has been slow more from qeury run in sql server ssmsMonday, May 9, 2016 4:08 PM
-
but problem is that when i run this query in vb.net the result has been slow more from qeury run in sql server ssms
Your original question only mentioned SSMS and suggest SSMS was slow executing the query. If it is fast in SSMS and slow in your VP application, it may be that either the execution plans are different or the application code is less efficient in processing the result set.
Different execution plans for the same query suggests different session settings. See Erland's thorough discussion about this. Check the plan cache to verify different plans.
If the same plan is used, there may be some attention to detail needed in the code to improve performance of result set processing.
Dan Guzman, Data Platform MVP, http://www.dbdelta.com
- Marked as answer by Sam ZhaMicrosoft contingent staff Thursday, May 19, 2016 12:26 PM
Tuesday, May 10, 2016 12:04 PM