clockwork icon indicating copy to clipboard operation
clockwork copied to clipboard

Show more query information: duplicates, n+1 problems

Open bertheyman opened this issue 5 years ago • 3 comments

Absolutely love the way clockwork works!

Would be really nice to expand the query information boxes with duplicates and n+1 problems to help developers spot these. Would that be possible? Let me know if there's anything I can do to help :) Might need some guidance though.

bertheyman avatar Apr 12 '20 17:04 bertheyman

thanks! we actually already do support n+1 query detection in the laravel integration.

check out this blog post to see what it looks like - https://underground.works/blog/clockwork-4.0-released-with-ui-improvements-requests-search-and-more

we do the detection server-side, that's the only way to detect the duplicates with a reasonable confidence.

itsgoingd avatar Apr 12 '20 18:04 itsgoingd

Oh great! Missed that one, was looking at old configuration.

Two more questions:

  1. It detects N+1 problems perfectly. Duplicates seem to slip trough (tested with the same query on two line son a controller and detect_duplicate_queries = true). Are both supported and do I have a problem with the duplicates? Or is it mostly aimed at N+1 and are these also meant by duplicate?
  2. When optimising queries, I often scan multiple requests with the database tab open by default. What are your thoughts on adding the problem queries in an extra box there to provide a full overview in that tab?

bertheyman avatar Apr 14 '20 07:04 bertheyman

1

this implementation is specifically aimed at programmer errors when using eloquent, eg. missing eager loads, etc. we actually hook into eloquent and compare stack traces and stuff, we don't even care about the sql itself.

alternatively we could simply look at all executed sql and find the duplicates that way. this is definitively a valid approach, but would lead to a lot more false positives.

eg. in a user admin view, you would load the current logged in user in the auth component and later the edited user, which produces the same sql with a different id condition. you wouldn't consider this a performance issue, as the queries are done in very different contexts.

that being said, it's really easy to implement "simple duplicates" detection, i can share some code if you would like to try it.

2

i can see how that would be helpful, i might have an idea on how it would look like i'd like to explore.

itsgoingd avatar Apr 14 '20 09:04 itsgoingd