这是一张积分表。约1M条记录
SELECT COUNT(*) as value FROM alasarr_social_mv s;
Output: 976270
看起来st_intersects强制使用空间索引,但&&却没有。
采样使用ST_Intersects
(282ms)
SELECT COUNT(*) as value
FROM alasarr_social_mv
WHERE ST_Intersects(
the_geom_webmercator,
ST_MakeEnvelope(-410961,4920492,-402305,4926887,3857)
)
Aggregate (cost=34370.18..34370.19 rows=1 width=0) (actual time=282.715..282.715 rows=1 loops=1)
-> Bitmap Heap Scan on alasarr_social_mv s (cost=5572.17..34339.84 rows=60683 width=0) (actual time=21.574..240.195 rows=178010 loops=1)
Recheck Cond: (the_geom_webmercator && '0103000020110F0000010000000500000000000000441519C1000000002BC5524100000000441519C1000000C069CB524100000000048E18C1000000C069CB524100000000048E18C1000000002BC5524100000000441519C1000000002BC55241'::geometry)
Filter: _st_intersects(the_geom_webmercator, '0103000020110F0000010000000500000000000000441519C1000000002BC5524100000000441519C1000000C069CB524100000000048E18C1000000C069CB524100000000048E18C1000000002BC5524100000000441519C1000000002BC55241'::geometry)
Heap Blocks: exact=4848
-> Bitmap Index Scan on alasarr_social_mv_gix (cost=0.00..5569.13 rows=182050 width=0) (actual time=20.836..20.836 rows=178010 loops=1)
Index Cond: (the_geom_webmercator && '0103000020110F0000010000000500000000000000441519C1000000002BC5524100000000441519C1000000C069CB524100000000048E18C1000000C069CB524100000000048E18C1000000002BC5524100000000441519C1000000002BC55241'::geometry)
Planning time: 0.192 ms
Execution time: 282.758 ms
采样使用&&
(414ms)
SELECT COUNT(*) as value
FROM alasarr_social_mv
WHERE the_geom_webmercator &&
ST_MakeEnvelope(-410961,4920492,-402305,4926887,3857)
Aggregate (cost=22535.97..22535.97 rows=1 width=0) (actual time=414.314..414.314 rows=1 loops=1)
-> Seq Scan on alasarr_social_mv (cost=0.00..22444.94 rows=182050 width=0) (actual time=0.017..378.427 rows=178010 loops=1)
Filter: (the_geom_webmercator && '0103000020110F0000010000000500000000000000441519C1000000002BC5524100000000441519C1000000C069CB524100000000048E18C1000000C069CB524100000000048E18C1000000002BC5524100000000441519C1000000002BC55241'::geometry)
Rows Removed by Filter: 798260
Planning time: 0.134 ms
Execution time: 414.343 ms
PostGIS版本
POSTGIS="2.2.2" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.11.0, released 2014/04/16" LIBXML="2.7.8" LIBJSON="UNKNOWN" (core procs from "2.2.2" need upgrade) RASTER (raster procs from "2.2.2" need upgrade) – alasarr 2 mins ago
2
不要将文本的屏幕截图粘贴到问题中。您可以将其复制并粘贴为代码吗?我看不懂它们对您的帮助。
—
埃文·卡洛尔
做完了 我认为现在情况会好一些
—
阿拉尔(Alasarr)'17
我试图将您的新查询计划移植到其中。随意升级计划,但尝试保留样式。
—
埃文·卡罗尔
你是对的!它在CTE内部工作
—
阿拉尔(Alasarr)'17