Sql-server – Why does SQL Server Profiler show some completed statements in pairs (twice)

profilersql serversql-server-2016

In SQL Server profiler I am seeing pairs of completed statements. A pair is shown below. The TextData (query) is exactly the same. The SPIDs are different (86 & 88). The # of reads and writes are a little different.
(as an FYI, I am running a custom template where I am filtering out exec sp_reset_connection statements and showing just the completed statements).
I am seeing a bunch of these pairs of SQL:StmtCompleted and RPC:Completed and every pair contains the same SQL in TextData.

The statement shown was executed once by Entity Framework in the client.

My question: Is SQL Server actually running the queries twice? If yes, does this mean definitely the client is sending the query twice?

enter image description here

Best Answer

My question: Is SQL Server actually running the queries twice?

Yep! Given that the SPIDs are different, that means they were run from completely different connections. The fact that the duration and reads are different, as you mentioned, is also a good indicator that the query was run twice (possibly with different parameters).

If yes, does this mean definitely the client is sending the query twice?

I would say yes. You should look into your application code. Maybe more than one user was accessing the system at the same time, or the query is being run from multiple threads, or something else.

Since this is EF, I might think this was the N+1 query problem (disclosure: that's my blog), but that would normally be all on the same SPID.