0

我有一个安装了 Postgis 的 Postgres 9.5 数据库。我创建了一个由大约 200 个表组成的物化视图。整个视图包含 3,447,885 条记录。每条记录都有一个几何类型的位置字段。当我查询位置为 ST_Within 边界框的所有记录时,返回 126,630 行需要 15.1 秒。

我在该字段上建立了一个 GIST 索引并运行查询,它仍然需要 15.1 才能返回 126,630 行。

示例查询:

SELECT ST_AsText (location) 
FROM myview 
WHERE ST_Within (location, ST_Geometry (....

我是否应该在这种尺寸的物化视图上看到显着的性能提升?有什么我可以寻找来表明性能问题的根源吗?

创建索引:

create index myview_location_gist on myview using gist (location);

解释分析:

'Bitmap Heap Scan on myview  (cost=130.56..11653.11 rows=1149 width=40) (actual time=18.377..564.760 rows=126330 loops=1)'
'  Recheck Cond: ('0103000020110F00000100000005000000D151D81DE90461C1831E458318835241D151D81DE90461C1D7A37045F81B53415C8FC23C79B860C1D7A37045F81B53415C8FC23C79B860C1831E458318835241D151D81DE90461C1831E458318835241'::geometry ~ location)'
'  Filter: _st_contains('0103000020110F00000100000005000000D151D81DE90461C1831E458318835241D151D81DE90461C1D7A37045F81B53415C8FC23C79B860C1D7A37045F81B53415C8FC23C79B860C1831E458318835241D151D81DE90461C1831E458318835241'::geometry, location)'
'  Rows Removed by Filter: 3'
'  Heap Blocks: exact=17361'
'  ->  Bitmap Index Scan on myview_location_gist  (cost=0.00..130.28 rows=3448 width=0) (actual time=15.923..15.923 rows=126333 loops=1)'
'        Index Cond: ('0103000020110F00000100000005000000D151D81DE90461C1831E458318835241D151D81DE90461C1D7A37045F81B53415C8FC23C79B860C1D7A37045F81B53415C8FC23C79B860C1831E458318835241D151D81DE90461C1831E458318835241'::geometry ~ location)'
'Planning time: 0.080 ms'
'Execution time: 570.068 ms'
4

0 回答 0