Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Execution/Min in SQL Server Management Studio's Expensive Queries the number of executions or just an estimate?

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
}
like image 905
Dave Avatar asked Nov 04 '22 01:11

Dave


1 Answers

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?

like image 167
Dan Wich Avatar answered Nov 08 '22 05:11

Dan Wich