我處於需要收集某個100m方形距離內的某些緯度數據點的數據的情況。我目前正在運行一個查詢如下,這適用於較少的位置。下面的15個數據點的查詢需要大約10分鐘的時間才能運行,但這種方法不能用更多的數據點進行擴展。我運行了一個具有4000個緯度數據點(與美國地圖上的4000個位置相關)的類似查詢,並且查詢需要30個小時才能運行。我知道哪個語句按行逐行掃描整個表,這就是爲什麼查詢運行得真的很長。即使我選擇較少的所需列,查詢也需要很長時間才能運行。你們有沒有更好的方法來完成這一點。請指教。WHERE條款中的多個OR條件
create table crt1
as
select * from masterdata
where
(round(device_lat,4) >= 33.7306 and round(device_lat , 4) <= 33.7316 and round(device_lon,4) >= -117.8364 and round(device_lon , 4) <= -117.8354) or
(round(device_lat,4) >= 37.927 and round(device_lat , 4) <= 37.928 and round(device_lon,4) >= -122.517 and round(device_lon , 4) <= -122.516) or
(round(device_lat,4) >= 30.2711 and round(device_lat , 4) <= 30.2721 and round(device_lon,4) >= -97.7544 and round(device_lon , 4) <= -97.7534) or
(round(device_lat,4) >= 33.0673 and round(device_lat , 4) <= 33.0683 and round(device_lon,4) >= -117.2642 and round(device_lon , 4) <= -117.2632) or
(round(device_lat,4) >= 34.8271 and round(device_lat , 4) <= 34.8281 and round(device_lon,4) >= -82.3011 and round(device_lon , 4) <= -82.3001) or
(round(device_lat,4) >= 32.9258 and round(device_lat , 4) <= 32.9268 and round(device_lon,4) >= -96.8311 and round(device_lon , 4) <= -96.8301) or
(round(device_lat,4) >= 45.0917 and round(device_lat , 4) <= 45.0927 and round(device_lon,4) >= -93.4272 and round(device_lon , 4) <= -93.4262) or
(round(device_lat,4) >= 36.0214 and round(device_lat , 4) <= 36.0224 and round(device_lon,4) >= -115.0853 and round(device_lon , 4) <= -115.0843) or
(round(device_lat,4) >= 47.2156 and round(device_lat , 4) <= 47.2166 and round(device_lon,4) >= -122.2351 and round(device_lon , 4) <= -122.2341) or
(round(device_lat,4) >= 32.2492 and round(device_lat , 4) <= 32.2502 and round(device_lon,4) >= -110.8845 and round(device_lon , 4) <= -110.8835) or
(round(device_lat,4) >= 32.286 and round(device_lat , 4) <= 32.287 and round(device_lon,4) >= -110.9753 and round(device_lon , 4) <= -110.9743) or
(round(device_lat,4) >= 36.8477 and round(device_lat , 4) <= 36.8487 and round(device_lon,4) >= -119.7911 and round(device_lon , 4) <= -119.7901) or
(round(device_lat,4) >= 36.0842 and round(device_lat , 4) <= 36.0852 and round(device_lon,4) >= -79.8363 and round(device_lon , 4) <= -79.8353) or
(round(device_lat,4) >= 39.0612 and round(device_lat , 4) <= 39.0622 and round(device_lon,4) >= -77.1245 and round(device_lon , 4) <= -77.1235) or
(round(device_lat,4) >= 32.8389 and round(device_lat , 4) <= 32.8399 and round(device_lon,4) >= -117.1629 and round(device_lon , 4) <= -117.1619) or
(round(device_lat,4) >= 61.1948 and round(device_lat , 4) <= 61.1958 and round(device_lon,4) >= -149.9061 and round(device_lon , 4) <= -149.9051);
這是完全不可縮放的,任何你切片的方式。你正在尋找的是MySQL GIS擴展:https://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html – Piskvor
正確索引表,並使用單獨的選擇與他們之間的聯合。另外,如果您不需要執行輸入循環,而不是查詢,ROUND函數將會終止索引使用。 –
如何創建一個臨時表,首先使用圓角經度和緯度值的信息,然後對臨時表執行查詢 – Bobby