sql - postgreSQL 解释分析函数

标签 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...

还有很多。如果我想解释分析整个函数,我执行命令 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/

相关文章:

sql - 使用 SqlCe 和 EntityFramework 进行插入和更新的语法

ruby-on-rails - Postgresql jsonb (Rails) - 通过数组在单个 json 属性中查询多个值

java - 在postgresql中的UUID字段中存储非UUID字符串

Postgresql 嵌套选择 max(sum())

python - 将空输入从 HTML 表单转换为 Flask 中的 None 以在 PostgreSQL 中将它们存储为 NULL

postgresql - 检查 postgresql 中时态数据库的最小可变性

postgresql - 如何区分(和格式化) "empty"文本字段

sql - 在同一个表中具有多个对应值的行

mysql - 所选值的 SQL 平均值

sql server : can i insert a $ into a money field