我不明白为什么当我为表创建太多分区时postgreSQL中的性能下降.
下面是测试查询和解释结果.
select count(*) from test_sql_stat_daily
where partition_key=1000000099;
Aggregate (cost=20000000011.88..20000000011.89 rows=1 width=0)"
Output: count(*)"
-> Append (cost=10000000000.00..20000000011.88 rows=2 width=0)"
-> Seq Scan on test_sql_stat_daily (cost=10000000000.00..10000000000.00 rows=1 width=0)"
Filter: (test_sql_stat_daily.partition_key = 1000000099)"
-> Seq Scan on test_sql_stat_daily_p0000000099 test_sql_stat_daily (cost=10000000000.00..10000000011.88 rows=1 width=0)" …Run Code Online (Sandbox Code Playgroud) 如何识别 Postgres 函数中的慢查询?
例如:
CREATE OR REPLACE FUNCTION my_function ()
RETURNS void AS $$
BEGIN
query#1;
query#2; --> slow query (duration 4 sec)
query#3;
query#4;
END
$$ LANGUAGE plpgsql;
Run Code Online (Sandbox Code Playgroud)
执行后,my_function()我在 Postgres 日志文件中得到如下内容:
持续时间:4.904 ms 语句:select my_function ();",,,,,,,,,"psql"
所以我无法识别函数中的慢速查询。