Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show more query information: duplicates, n+1 problems #389

Open
bertheyman opened this issue Apr 12, 2020 · 3 comments
Open

Show more query information: duplicates, n+1 problems #389

bertheyman opened this issue Apr 12, 2020 · 3 comments
Milestone

Comments

@bertheyman
Copy link
Contributor

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.

@itsgoingd
Copy link
Owner

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.

@bertheyman
Copy link
Contributor Author

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?

@itsgoingd
Copy link
Owner

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 itsgoingd added this to the Clockwork 6 milestone Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants