-
Notifications
You must be signed in to change notification settings - Fork 312
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
Add option to generate generic explain plans for Postgres #604
Add option to generate generic explain plans for Postgres #604
Conversation
I just realized I should probably call some things out to see what you guys think. In the mailing list discussion their proposal was a bit different. I believe they are saying we should take the actual prepared statement name from Ecto's cache and put it in the The issue I see with this is that a lot of the time people will be debugging bad queries locally or in a sandbox environment when the issue is happening in a production system. So it seems more valuable to be able to control what kind of plan you want to see. The caveat here is that So then we have the option to raise when |
Maybe we can make :generic_plan a special key of |
Oh It is useful to be able to see the explain for that because the default behaviour of Postgres is to use a generic plan after 5 executions of the same query if it's not much worse than the average of the first 5 runs (which are using plans specific to the values of the parameters). So being able to see both types plans give you the full picture while you're debugging. I would personally default to |
@greg-rychlewski alright, sounds good to me. One last question before you merge: should it be called |
Yeah definitely that's a lot better. I think just And then there are just two other things I was hoping to your opinion on:
|
|
Thanks for the good suggestions. When you have time would you be able to give it one more look over? Also I tried to get Postgres 16 working on the CI for the |
Yup, sounds good to me! |
This was brought up in the mailing list. A lot of the times Postgres will end up choosing a generic plan for the same parameterized query if it's used more than 5 times. At which point our current explain logic can be misleading because it's based on the plan created specifically for the supplied parameters.
There is a way you can get Postgres to generate the generic explain plan detailed here: https://www.cybertec-postgresql.com/en/explain-that-parameterized-statement/. Basically you have to use the
prepare
command explicitly. Otherwise it treats as a custom plan.Besides the integration tests, there's also another sanity test that can be done to convince ourselves it's working properly. First create an index on
:title
in the:posts
table then run this test: