3

I'm using MiniProfiler to check what NPoco is doing with SQL Server but I've noticed it reports duplicate queries even when the SQL parameters have different values.

Eg: if I fetch a string from a database by ID, I might call:

SELECT * FROM PageContent WHERE ID=@ID

...twice on the same page, with two different IDs, but MiniProfiler reports this as a duplicate query even though the results will obviously be different each time.

Is there any way I can get MiniProfiler to consider the SQL parameter values so it doesn't think these queries are duplicated? I'm not sure if this problem is part of MiniProfiler or if it's a problem in how NPoco reports it's actions to MiniProfiler so I'll tag both.

NickG
  • 9,315
  • 16
  • 75
  • 115

1 Answers1

2

I think that this is by design, and is in fact one of the reasons for the existence of the duplicate query detection.

If you are running that query twice on one page where the only difference is the param value, then you could also run it one time and include both param values in that query.

SELECT * FROM PageContent WHERE ID in (@ID1, @ID2)

So you are doing with two queries what you could do with one (you would have to of course filter on server side, but that is faster than two queries).

The duplicate query label is not for saying that you are running the absolute identical query more than once (though it would apply there as well). Rather it is highlighting an opportunity for optimizing your query approach and consolidating different queries into one (think about what an N+1 situation would look like).

If the default functionality doesn't meet your needs, you can always change it! The functionality that calculates duplicateTimings is located in UI/includes.js. You can provide your own version of this file that defines duplicates in a different way (perhaps by looking at parameter values in addition to the command text when detecting duplicates) by turning on CustomUITemplates inside MiniProfiler, and putting your own version of includes.js in there.

Community
  • 1
  • 1
Yaakov Ellis
  • 40,752
  • 27
  • 129
  • 174
  • Because it's not that simple :) I never know both IDs at the same time as they are in totally different user controls. Plus there will only ever be 2/3 per page. If there were hundreds, then I'd consider changing the architecture. – NickG Aug 06 '14 at 11:11
  • 1
    Understood. I was just explaining why it is the way that it is, in answer to your question above. I just added to my answer giving you a way to customize how you detect duplicates in your own install (I don't see us changing this right now in the main release, but this is the reason that `CustomUITemplates` exists). – Yaakov Ellis Aug 06 '14 at 11:22