Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
postgreSQL解释分析,实际时间和估算之间的关系_Postgresql - Fatal编程技术网

postgreSQL解释分析,实际时间和估算之间的关系

postgreSQL解释分析,实际时间和估算之间的关系,postgresql,Postgresql,我目前正在阅读本页以了解postgreSQL的解释分析,并试图了解估算成本与实际时间之间的关系 本页给出的一个简单示例如下: -> Nested Loop (cost=5.64..14.71 rows=1 width=140) (actual time=18.983..19.481 rows=4 loops=1) -> Hash Join (cost=5.64..8.82 rows=1 width=72) (actual time=18.876.

我目前正在阅读本页以了解postgreSQL的解释分析,并试图了解估算成本与实际时间之间的关系

本页给出的一个简单示例如下:

->  Nested Loop  (cost=5.64..14.71 rows=1 width=140) (actual time=18.983..19.481 rows=4 loops=1)
               ->  Hash Join  (cost=5.64..8.82 rows=1 width=72) (actual time=18.876..19.212 rows=4 loops=1)
               ->  Index Scan using pg_class_oid_index on pg_class i  (cost=0.00..5.88 rows=1 width=72) (actual time=0.051..0.055 rows=1 loops=4)
它说“如果你计算一下,你会发现0.055*4占了散列连接的总时间和嵌套循环的总时间之间的大部分差异(剩余部分可能是测量所有这些的开销)。”

我不确定这里的“差异”代表什么,我真的找不到任何接近0.055*4的差异。。我是不是傻到忽略了一些琐碎的结果

顺便说一句,我实际上是在写一份关于数据库的实验报告,所以一般来说,如果有人要求我写一些关于基于某些特定结果的估计时间和实际时间的简短评论,我能说些什么

这是我需要写结果的计划:

QUERY PLAN                                                               
---------------------------------------------------------------------------------------------------------------------------------------
 Nested Loop  (cost=39911.52..299300.41 rows=1 width=17) (actual time=4660.217..4952.328 rows=1 loops=1)
   Join Filter: (casts.mid = movie.id)
   Rows Removed by Join Filter: 2251735
   ->  Seq Scan on movie  (cost=0.00..29721.64 rows=5542 width=21) (actual time=0.637..316.651 rows=4201 loops=1)
         Filter: (year > 2010)
         Rows Removed by Filter: 1533210
   ->  Materialize  (cost=39911.52..269080.01 rows=6 width=4) (actual time=0.307..1.014 rows=536 loops=4201)
         ->  Hash Join  (cost=39911.52..269079.98 rows=6 width=4) (actual time=1288.827..4089.872 rows=536 loops=1)
               Hash Cond: (casts.pid = actor.id)
               ->  Seq Scan on casts  (cost=0.00..186246.47 rows=11445847 width=8) (actual time=0.293..1487.138 rows=11445847 loops=1)
               ->  Hash  (cost=39911.51..39911.51 rows=1 width=4) (actual time=414.130..414.130 rows=1 loops=1)
                     Buckets: 1024  Batches: 1  Memory Usage: 1kB
                     ->  Seq Scan on actor  (cost=0.00..39911.51 rows=1 width=4) (actual time=100.175..414.125 rows=1 loops=1)
                           Filter: (((fname)::text = 'Tom'::text) AND ((lname)::text = 'Hanks'::text))
                           Rows Removed by Filter: 1865033
 Total runtime: 4952.822 ms
看看实际时间:

-> Nested Loop ........ (actual time=18.983..19.481 rows=4 loops=1) ..... ..... -> Hash Join ....... (actual time=18.876..19.212 rows=4 loops=1) -> Index Scan ......... (actual time=0.051..0.055 rows=1 loops=4) PostgreSQL在
actos
表上执行顺序扫描,过滤掉1865033行,只找到一行。此扫描的总时间为100到414秒。
使用索引时,可以在几毫秒内找到一行。

成本和时间之间的关系非常粗略。如果成本更高,实际时间也可能更高(在同一台计算机上)。但成本是任意单位。它无法与时间相比。@biubiu3我在回答中添加了一条关于如何提高查询速度的注释。是的,实际上我尝试过通过向casts\u pid、casts\u mid、actor\u lname和movie\u id添加4个索引来给出最佳解决方案,结果大约为4ms。。在fname中添加索引对性能没有任何影响。无论如何,非常感谢
 ->  Seq Scan on actor  (cost=0.00..39911.51 rows=1 width=4) (actual time=100.175..414.125 rows=1 loops=1)
       Filter: (((fname)::text = 'Tom'::text) AND ((lname)::text = 'Hanks'::text))
       Rows Removed by Filter: 1865033