【发布时间】:2018-10-16 18:07:50
【问题描述】:
我有以下输出
Merge Join (cost=31843.55..32194.92 rows=30215 width=36)
(actual time=496.720..510.071 rows=38381 loops=1)
Merge Cond: (movies.year = people.birth_year)
-> Sort (cost=9905.45..9918.62 rows=5268 width=22)
(actual time=151.781..152.690 rows=5634 loops=1) // <---- !!!! LOOKING HERE !!!!
Sort Key: movies.year
Sort Method: quicksort Memory: 729kB
-> Seq Scan on movies (cost=0.00..9579.81 rows=5268 width=22)
(actual time=145.826..149.340 rows=7640 loops=1) // <---- !!!! LOOKING HERE !!!!
Filter: (title > ’y’::text)
Rows Removed by Filter: 456425 // <---- !!!! LOOKING HERE !!!!
-> Sort (cost=21936.87..21953.89 rows=6808 width=18)
(actual time=344.918..347.980 rows=38465 loops=1)
Sort Key: people.birth_year
Sort Method: quicksort Memory: 423kB
-> Seq Scan on people (cost=0.00..21503.44 rows=6808 width=18)
(actual time=341.883..343.847 rows=4151 loops=1)
Filter: (name > ’zeke’::text)
Rows Removed by Filter: 1099324
Planning time: 0.450 ms
Execution time: 511.988 ms
我想知道title > 'y' 的选择性估计值。
这个计划说Rows Removed by Filter: 456425。
我们拥有的总行数是 464065。
由于过滤器删除了456425 行,因此我们选择了
464065 - 456425 = 7640 行中提到的 Seq Scan 行。
但是为什么最上面的Sort 显示实际行数为5634?它来自哪里?
我认为这可能与第二次排序操作有关,但它们是完全不同的分支。
有没有办法知道表是否适合内存?计划表明正在使用多少内存,但我没有看到它们表明所有这些是否适合内存。
【问题讨论】:
-
您应该保留执行计划的缩进,因为这对于理解它也很重要 - 缩进显示不同计划节点的嵌套级别
标签: postgresql sql-execution-plan