【发布时间】:2020-09-01 08:02:38
【问题描述】:
我正在使用postgres,但索引主题似乎也适合sql
我有 2 张桌子:
表 A:
name, id, geom, value, desc
地点:
geom is type of geometry
geom is indexed as geom_index
表 B:
lnn_name, geom
地点:
geom is type of geometry
geom is indexed as geom__lnn_index
我检查了以下查询的性能:
select desc, sum((st_distance(A.geom, B.geom)<300)::INT) as res
from tblA as A, tblB as B
where A.geom is not null
group by A.desc
无论有无索引,计算查询的时间似乎都一样
为什么索引无助于减少计算查询的时间?
我希望 geom 以一种可以减少查询时间的方式保存(点之间的长距离将被自动忽略)
【问题讨论】:
-
"我希望 geom 以一种可以减少查询时间的方式保存..." 不,索引所做的只是以不同的顺序保存相同的信息。可能有数据库可以帮助计算距离,但这不是索引的任务,
-
两件事 - 多少行?其次 - 查看查询计划,看看它们是否不同以及如何解决。
-
请edit您的问题并添加使用
explain (analyze, buffers, format text)生成的execution plan(不是只是一个“简单”解释)为formatted text,并确保保留计划的缩进。粘贴文本,然后将```放在计划前一行和计划后一行。还请包括所有索引的完整create index语句。
标签: sql postgresql postgis