我想使用的計算,是一個d距離從一個點(即地理位置的東西)遠點的查詢,所以查詢有些複雜:django查詢和存儲過程(MySQL)之間的性能差異?
DELIMITER //
CREATE PROCEDURE geodist (IN m_lat double, IN m_lng double, IN dist int, IN lim int)
BEGIN
DECLARE lon1 double; DECLARE lon2 double;
DECLARE lat1 double; DECLARE lat2 double;
-- calculate lon lat for the rectangle
SET lon1 = m_lon-dist/abs(cos(radians(m_lat))*69);
SET lon2 = m_lon+dist/abs(cos(radians(m_lat))*69);
SET lat1 = m_lat-(dist/69);
SET lat2 = m_lat+(dist/69);
-- run query;
SELECT post.id, 3956 * 2 * ASIN(SQRT(POWER(SIN((m_lat - post.geo_lat) * pi()/180/2), 2) +COS(m_lat * pi()/180) * COS(post.geo_lat * pi()/180) *POWER(SIN((m_lng - post.geo_lng) * pi()/180/2), 2))) as distance
FROM post_post as post
WHERE
post.geo_lng BETWEEN lon1 AND lon2
AND post.geo_lat BETWEEN lat1 AND lat2
HAVING distance < dist ORDER BY Distance limit lim;
END //
遠高於正是我的存儲過程會。由於我將使用這個來通過數千甚至數百萬行數據,我想知道在存儲過程中使用django查詢時性能會怎樣?我意識到,Django不支持存儲過程,所以這就是爲什麼我希望避免使用存儲過程。然而,那麼查詢將不會被編譯到數據庫中,並且計算將不得不在python中完成......等等。django查詢和從django調用的存儲過程之間的性能有什麼區別?
你問了這個問題3次。這是一個交叉點。 – Bytemain 2012-01-10 02:04:16