我在PostgreSQL 9.3中使用PL / pgSQL函数,内部有几个复杂的查询:
create function f1()
returns integer as
$$
declare
event tablename%ROWTYPE;
....
....
begin
FOR event IN
SELECT * FROM tablename WHERE condition
LOOP
EXECUTE 'SELECT f2(event.columnname)' INTO dummy_return;
END LOOP;
...
INSERT INTO ... FROM a LEFT JOIN b ... LEFT JOIN c WHERE ...
UPDATE T SET cl1 = M.cl1 FROM M WHERE M.pkcols = T.pkcols;
...
end
$$ language plpgsql;
如果我跑步了EXPLAIN ANALYZE f1()
,我只会得到总时间,而没有详细信息。有没有一种方法可以获取该函数中所有查询的详细结果?
如果Postgres不应该优化函数中的查询,我也要寻求解释。
auto_explain.log_nested_statements
可能有帮助。参见postgresql.org/docs/9.3/static/auto-explain.html