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_Sql Execution Plan - Fatal编程技术网

Postgresql 有好计划的慢查询

Postgresql 有好计划的慢查询,postgresql,sql-execution-plan,Postgresql,Sql Execution Plan,我们有两台服务器,最新的将取代最旧的。除了一个查询外,它们的性能几乎相同。在两个不同的服务器上进行相同的查询(相同的数据库定义、相同的数据、刚刚从头开始重建的索引)在最新的实例中需要花费更多的时间 两个方案完全相同,qwery非常简单: Nested Loop (cost=0.00..17.83 rows=1 width=2262) (actual time=0.032..0.032 rows=0 loops=1) Buffers: shared hit=3 -> Ind

我们有两台服务器,最新的将取代最旧的。除了一个查询外,它们的性能几乎相同。在两个不同的服务器上进行相同的查询(相同的数据库定义、相同的数据、刚刚从头开始重建的索引)在最新的实例中需要花费更多的时间

两个方案完全相同,qwery非常简单:

 Nested Loop  (cost=0.00..17.83 rows=1 width=2262) (actual time=0.032..0.032 rows=0 loops=1)
   Buffers: shared hit=3
   ->  Index Scan using psan_para_fk_ix on parasetana a0  (cost=0.00..9.48 rows=1 width=1735) (actual time=0.030..0.030 rows=0 loops=1)
         Index Cond: (((ca)::text = 'r'::text) AND (idp = 36678502::numeric))
         Filter: (flg = '1'::bpchar)
         Buffers: shared hit=3
   ->  Index Scan using seta_pk on seta a1  (cost=0.00..8.33 rows=1 width=527) (never executed)
         Index Cond: (((a1.ca)::text = 'r'::text) AND (a1.idgrla = a0.idgrla ) AND (a1.prog = a0.prog_set))
         Filter: (a1.flgp = '0'::bpchar)
 Total runtime: 0.153 ms
(10 rows)
时间:2217.074毫秒

如您所见,总运行时间为0.2ms。新服务器和旧服务器都是如此。但是,旧服务器中的时间是30毫秒,而新服务器中的时间是30毫秒的200倍(2.2秒)

是什么导致了这种差异?postgresql文档说,在select语句中,总运行时间和时间应该几乎相同


谢谢

据我所知,这是一个使用嵌套循环和适当索引的简单连接。问题应该是由于第二个(大)表的缓存不好造成的。在这里,第二个表可能就所使用的索引而言聚集性很差。尝试使用
CLUSTER
命令查看是否有帮助


你也可以尝试改变计划。您可能需要的选项-交换联接顺序,使用哈希联接。

您是否分析或清空了有问题的表?是的,两者都有。表btw是从另一台服务器中的一个转储创建的,所以它从一开始就应该是最佳的。缓存时间不计入总运行时间(0.153毫秒)吗?文档中指出,总运行时间“不包括解析、重写或计划时间”[此外,什么会改变两台服务器之间的缓存策略?