active_record-sql_analyzer icon indicating copy to clipboard operation
active_record-sql_analyzer copied to clipboard

Thoughts on an N+1 detection option?

Open nerdrew opened this issue 9 years ago • 3 comments
trafficstars

nerdrew avatar Aug 12 '16 18:08 nerdrew

How do you plan to detect N+1 queries?

maniksurtani avatar Aug 12 '16 18:08 maniksurtani

Basic N+1 detection: compare a redacted query with the previous redacted query. It would only detect N+1 where there are no other queries in between, but that might be enough to catch some. You could also add callsite comparison to eliminate false positives.

nerdrew avatar Aug 12 '16 18:08 nerdrew

That would also require some memoizing of what the analyzer has seen, in a thread-local variable, and making sure it is properly scrubbed before the next run. I wonder if scoping such detection to a transaction (given the work @noamsml has been doing on #7) is the way to go ...

maniksurtani avatar Aug 12 '16 19:08 maniksurtani