We are occasionally seeing a query come up as over 11,000 in Activity Monitor under Expensive Queries.
I see that in the code a query is being executed in a loop, which I realize is not the best approach (I didn't write it but might need to fix it).
I do not think the loop is creating 11,000 iterations, more like 20 at a time. So my question is that if code executes 20 queries in say 1/550 sec, would that appear as 11,000 executions per min? Or does Activity Monitor really mean the query is really executed 11,000 times?
DataTable JobsDT = new DataTable();
DataTable oqDT = new DataTable();
DataTable ePickupDT = new DataTable();
DataTable upDT = new DataTable();
JobsDT = Q.SelectRecords("SELECT [Quote]... etc etc etc" + ((Filters.Length > 0) ? Filters : "") + ") ORDER BY " + SortBy + " " + SortDirection);
oqDT=...;
ePickupDT=...;
upDT=...;
//Merge the datatables
DT.Merge(JobsDT);
DT.Merge(oqDT);
DT.Merge(ePickupDT);
DT.Merge(upDT);
//Build cart header
Cart += "<table id='CurrentOrdersDiv' style='font-family: Arial; font-size: small;' width='100%' cellpadding='2' cellspacing='0'>";
//Build cart body
for (int row = 0; row < DT.Rows.Count; row++)
{
try { Adjustment = (Q.SelectRecords("SELECT [PriceAdjustment] FROM [Media] WHERE [PriceAdjustment] > 0 AND [Quote] = " + Convert.ToInt32(DT.Rows[row]["Quote"])).Rows.Count > 0) ? true : false; } catch { }
//Create flags
}
I don't know this for sure, but I don't think Execution/Min "extrapolates". So in your example, if 20 queries occurred in a fraction of a second (and didn't occur again during that minute), I think Execution/Min would only be averaged towards 20. You could check sys.dm_exec_query_stats.execution_count to see if the 11000 number makes sense.
Perhaps your code only executes around 20 queries per run, but is run very frequently?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With