mysql查询地理位置,数据库:查询地理位置数据的最佳性能方式?

I have a MySQL database. I store homes in the database and perform literally just 1 query against the database, but I need this query to be performed super fast, and that's to return all homes within a square box geo latitude & longitude.

SELECT * FROM homes

WHERE geolat BETWEEN ??? AND ???

AND geolng BETWEEN ??? AND ???

How is the best way for me to store my geo data so that I can perform this query of displaying all home within the geolocation box the quickest?

Basically:

Am I using the best SQL statement to perform this query the quickest?

Does any other method exist, maybe not even using a database, for me to query the fastest way a result of homes within a boxed geolocation bounds?

In case it helps, I've include my database table schema below:

CREATE TABLE IF NOT EXISTS `homes` (

`home_id` int(10) unsigned NOT NULL auto_increment,

`address` varchar(128) collate utf8_unicode_ci NOT NULL,

`city` varchar(64) collate utf8_unicode_ci NOT NULL,

`state` varchar(2) collate utf8_unicode_ci NOT NULL,

`zip` mediumint(8) unsigned NOT NULL,

`price` mediumint(8) unsigned NOT NULL,

`sqft` smallint(5) unsigned NOT NULL,

`year_built` smallint(5) unsigned NOT NULL,

`geolat` decimal(10,6) default NULL,

`geolng` decimal(10,6) default NULL,

PRIMARY KEY (`home_id`),

KEY `geolat` (`geolat`),

KEY `geolng` (`geolng`),

) ENGINE=InnoDB ;

UPDATE

I understand spatial will factor in the curvature of the earth but I'm most interested in returning geo data the FASTEST. Unless these spatial database packages somehow return data faster, please don't recommend spatial extensions. Thanks

UPDATE 2

Please note, no one below has truly answered the question. I'm really looking forward to any assistance I might receive. Thanks in advance.

解决方案

There is a good paper on MySQL geolocation performance here.

EDIT Pretty sure this is using fixed radius. Also I am not 100% certain the algorithm for calculating distance is the most advanced (i.e. it'll "drill" through Earth).

What's significant is that the algorithm is cheap to give you a ball park limit on the number of rows to do proper distance search.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值