Suz*_*ros 5 sql postgresql postgresql-9.4
我试图理解postgresql中的查询优化,我有一个函数,里面有一些查询.其中一些是简单的查询,它将值保存到变量中,然后下一个查询将此变量用于查找内容..让我们说:
function()...
select type into t
from tableA
where code = a_c;
select num into n
from tableB
where id = t;
end function...
Run Code Online (Sandbox Code Playgroud)
还有更多..如果我想解释分析整个函数我执行命令说明解析select function(); 这是正确的方法吗?或者我应该解释分析函数内的每个查询,如果是这样的话,用什么值?
考虑使用auto_explain模块:
auto_explain 模块提供了一种自动记录慢语句执行计划的方法,而无需手动运行 EXPLAIN。这对于跟踪大型应用程序中未优化的查询特别有用。
与auto_explain.log_nested_statements开启:
auto_explain.log_nested_statements(布尔值)
auto_explain.log_nested_statements 导致考虑记录嵌套语句(在函数内执行的语句)。当它关闭时,只记录顶级查询计划。该参数默认关闭。只有超级用户才能更改此设置。