I've been using postgresql's explain syntax to analyze queries. However, I tried to run it against a custom function, sproc, but it does not analyze it. Is there a way to use explain against a function? If not natively is there a way to programmatically export the function body and have the query analyzer fun against that?
1 Answer
Not really, and given PostgreSQL's pluggable procedural languages it's unlikely to happen in a general way. In any case, EXPLAIN for functions that are more than just a query with parameters is perhaps not well-defined as a concept.
A typical work-around is to extract the query-part and do PREPARE foo(...) ... SELECT followed by EXPLAIN EXECUTE foo(...). This lets you see the plan for a simple parameterised select.
auto_explainmodule: dba.stackexchange.com/questions/84414/…