小编TmT*_*ron的帖子

为什么 log(greatest()) 这么慢?

我们有一些非常慢的复杂查询。我设法将查询简化为简单的复制。看来,组合greatestlog是原因,但我不明白为什么。

这是运行查询的完整sql-fiddle 示例- 您也可以View the execution Plans查询(按 sql-fiddle 页面上查询结果底部的链接)

所以这里是查询:

select count(value)
from (
         SELECT  log(greatest(1e-9, x)) as value
         from (select generate_series(1, 20000, 1) as x) as d
     ) t;
Run Code Online (Sandbox Code Playgroud)

我们只是生成一系列 20k 数字并使用log(greatest()). 此查询大约需要1.5秒。

我认为计算日志可能需要很长时间,但以下查询也很快(~5ms):

select count(value)
from (
         SELECT  log(x) as value
         from (select generate_series(1, 20000, 1) as x) as d
     ) t;
Run Code Online (Sandbox Code Playgroud)

正如测试我交换greatestlog-这也是快速(大约为5ms):

select count(value)
from …
Run Code Online (Sandbox Code Playgroud)

postgresql performance query-performance

3
推荐指数
1
解决办法
920
查看次数