0

我有 3500 万行的表。当我选择如图所示的行时,它不起作用并且需要很长时间并最终出现内存错误(我的内存是 32GB)。

我根据每月日期对表进行了分区,我有 64 个表,如图所示 表分区

但是查询不再起作用,并且需要很长时间,最终会出现内存错误。我该如何解决这个问题?

4

1 回答 1

1

这基本上是您的查询:

select s.*
from student s
where s.id = (select max(si.id)
              from studentIndex si
              where si.family = s.name and si.name_ship = s.name_ship
             )    and 
      try_convert(numeric(38, 12), s.Length ) between 18.485411 and 23.51031 and
      try_convert(numeric(38, 12), s.Weight ) between 21.77079 and 77.13644 and
      s.time > 1594326600;

这基本上是一个全表扫描,所以我不明白为什么它会用完成员。例外是相关子查询。为此,您需要在studentIndex(family, name_ship)-- 上建立一个索引,并确保这些列是同一时间的(否则,可能不会使用该索引)。

lengthwidth比较看起来很像地理坐标。我可能还会建议一个 GIS 解决方案。但是,如果这些是纬度和经度,则该区域非常大,因此 GIS 可能并没有那么有用。

于 2020-07-15T10:30:07.963 回答