我正在尝试了解 postgresql 中的查询优化,并且我有一个包含一些查询的函数。其中一些是简单的查询,将一个值保存到一个变量中,然后下一个查询使用这个变量来查找一些东西。可以说:
function()...
select type into t
from tableA
where code = a_c;
select num into n
from tableB
where id = t;
end function...
还有很多。如果我想解释分析整个函数,我执行命令 explain analyze select function();这是正确的方法吗,还是我应该解释分析函数内的每个查询,如果是,用什么值?
最佳答案
考虑使用 auto_explain模块:
The auto_explain module provides a means for logging execution plans of slow statements automatically, without having to run EXPLAIN by hand. This is especially helpful for tracking down un-optimized queries in large applications.
打开auto_explain.log_nested_statements
:
auto_explain.log_nested_statements (boolean)
auto_explain.log_nested_statements causes nested statements (statements executed inside a function) to be considered for logging. When it is off, only top-level query plans are logged. This parameter is off by default. Only superusers can change this setting.
关于sql - postgreSQL 解释分析函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30545453/