我正在开发一个谷歌地图应用程序以及Postgresql和PostGIS,它根据地图的当前视口和缩放级别获取标记(每个标记都有一个最小和最大缩放级别,它们将被提取)。查询运行时间为50到300毫秒。但是,视图中的处理始终需要1200毫秒,通常需要4000毫秒。以下是查询输出的示例:
Completed 200 OK in 3997ms (Views: 3800.2ms | ActiveRecord: 195.7ms)
我正在使用ActiveModelSerializers并且使用返回的字段进行调整会产生轻微的好处(例如删除可能会变长的描述字段),但没有任何重要意义。管道中似乎有一些东西花费了过多的时间。有没有人有任何想法可能会发生?
编辑:
我们正在使用Postgres 9.3版。这是EXPLAIN ANALYZE的转储:
[["Aggregate (cost=9467.65..9467.66 rows=1 width=0) (actual time=76.429..76.429 rows=1 loops=1)"],
[" -> Bitmap Heap Scan on markers (cost=2734.88..9457.31 rows=4136 width=0) (actual time=63.436..76.026 rows=4135 loops=1)"],
[" Recheck Cond: ((5 >= min_zoom) AND (point && '010300002...'::geography))"],
[" -> Bitmap Index Scan on index_markers_on_min_zoom (cost=0.00..983.17 rows=67833 width=0) (actual time=14.185..14.185 rows=68500 loops=1)"],
[" -> Bitmap Index Scan on index_markers_on_point (cost=0.00..1749.39 rows=67064 width=0) (actual time=38.530..38.530 rows=66232 loops=1)"],
[" Index Cond: (point && '0103000020E610.....'::geography)"],
["Total runtime: 77.015 ms"]]