我想使用一个查询来计算与点相距D距离的点(即地理位置),因此查询有点复杂:
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不支持存储过程,所以这就是为什么我希望避免使用存储过程。但是,然后查询将不会在db中编译,并且计算必须在python中进行...等等.django查询和从django调用的存储过程之间的性能差异是什么?