[PATCH] Include triggers in EXPLAIN - Mailing list pgsql-hackers

From Josef Šimánek
Subject [PATCH] Include triggers in EXPLAIN
Date
Msg-id CAFp7Qwqo=iG0C7Xjcm7NAZK8eU6hsW_zTm+sNn9rk0_zweXYtA@mail.gmail.com
Whole thread Raw
Responses Re: [PATCH] Include triggers in EXPLAIN  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello!

Recently I got few times into situation where I was trying to find out what is blocking DELETE queries. Running EXPLAIN (even VERBOSE one) wasn't useful, since the reason was slow trigger (missing index on foreign key column). I had to create testing entry and run EXPLAIN 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 of DELETE query and that can be the reason for slow DELETE.

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 during EXPLAIN. 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.

After initial discussion with Pavel Stěhule and Tomáš Vondra at czech postgresql maillist (https://groups.google.com/forum/#!topic/postgresql-cz/Dq1sT7huVho) I was able to prepare initial version of this patch. I have added EXPLAIN option called TRIGGERS 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.

- patch with examples can be found at https://github.com/simi/postgres/pull/2
- DIFF format https://github.com/simi/postgres/pull/2.diff
- PATCH format (also attached) https://github.com/simi/postgres/pull/2.patch

All regression tests passed with this change locally on latest git master. I would like to cover this patch with more regression tests, but I wasn't sure where to place them, since there's no "EXPLAIN" related test "group". Is "src/test/regress/sql/triggers.sql" the best place to add tests related to this change?

PS: This is my first try to contribute to postgresql codebase. The quality of patch is probably not the best, but I will be more than happy to do any requested change if needed.

Regards,
Josef Šimánek
Attachment

pgsql-hackers by date:

Previous
From: Dmitry Dolgov
Date:
Subject: Re: Index Skip Scan
Next
From: Tomas Vondra
Date:
Subject: Re: 64 bit transaction id