我有一个Postgis查询,从位置选择给定半径内的所有点。
SELECT id
FROM mytable
WHERE ST_DWithin(location, ST_GeographyFromText('SRID=4326;POINT(12.1234 12.1234)'), 789)
OR ST_DWithin(location, ST_GeographyFromText('SRID=4326;POINT(23.4567 23.4567)'), 789)
OR ST_DWithin(location, ST_GeographyFromText('SRID=4326;POINT(34.5678 34.5678)'), 789)
当我用EXPLAIN
分析时,我可以看到
Bitmap Heap Scan on mytable (cost=964.16..1051.01 rows=1 width=4)
Recheck Cond: ((location && 'E61A301BC000002OBFUSCATEDDAT05123240'::geography) OR (location && '010020E610OBFUSCATEDDATAC9ACE4E0E3240'::geography) OR (location && '0101000OBFUSCATEDDATA8FC3042080020E613240'::geography) )
Filter: (((location && 'E61A301BC000002OBFUSCATEDDAT05123240'::geography) AND ('010020E610OBFUSCATEDDATAC9ACE4E0E3240'::geography && _st_e...SOMETHING
-> BitmapOr (cost=964.16..964.16 rows=1 width=0)
-> Bitmap Index Scan on global_points_gix (cost=0.00..4.42 rows=1 width=0)
Index Cond: (location && 'E61A301BC000002OBFUSCATEDDAT05123240'::geography)
-> Bitmap Index Scan on global_points_gix (cost=0.00..4.42 rows=1 width=0)
Index Cond: (location && '010020E610OBFUSCATEDDATAC9ACE4E0E3240'::geography)
-> Bitmap Index Scan on global_points_gix (cost=0.00..4.42 rows=1 width=0)
Index Cond: (location && '0101000020OBFUSCATEDDATA8FC3042080020E613240'::geography)
这让我觉得搜索积分非常快,但合并结果排除重复是很昂贵的。我对吗?如果我对它们没问题,我能以某种方式启用重复吗?我尝试将OR
替换为UNION SELECT
,但它没有成功。