Show possible triggers in EXPLAIN. #2
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
motivation
Recently I got few times into situation where I was trying to find out what is blocking DELETE queries. Running
EXPLAIN
(evenVERBOSE
one) wasn't useful, since the reason was slow trigger (missing index on foreign key column). I had to create testing entry and runEXPLAIN ANALYZE DELETE
to get this information.It will be really valuable for me to show triggers in
EXPLAIN
query since it will make clear for me there will be any trigger "activated" during execution ofDELETE
query and that can be the reason for slowDELETE
. I have added EXPLAIN option calledTRIGGERS
enabled by default. There's already autoexplain property for this.I understand it is not possible to show only triggers which will be really activated unless query is really executed.
EXPLAIN ANALYZE
remains untouched with this patch.I have seen initial discussion at https://www.postgresql.org/message-id/flat/20693.1111732761%40sss.pgh.pa.us to show time spent in triggers in
EXPLAIN ANALYZE
including quick discussion to possibly show triggers duringEXPLAIN
. Anyway since it doesn't show any additional cost and just inform about the possibilities, I still consider this feature useful. This is probably implementation of idea mentioned at https://www.postgresql.org/message-id/21221.1111736869%40sss.pgh.pa.us by Tom Lane:💚 All regression tests passed with this change locally.
before:
after