active_record-sql_analyzer
active_record-sql_analyzer copied to clipboard
Thoughts on an N+1 detection option?
How do you plan to detect N+1 queries?
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.
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 ...