我有以下数据库结构:
CREATE TABLE IF NOT EXISTS `business` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`address` varchar(255) NOT NULL,
`city` varchar(255) NOT NULL,
`state` varchar(255) NOT NULL,
`postal` int(11) NOT NULL,
`country` varchar(255) NOT NULL,
`lat` float NOT NULL,
`lng` float NOT NULL,
`name` varchar(255) NOT NULL,
`phone` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`website` varchar(255) NOT NULL,
`userID` bigint(20) NOT NULL,
`url` varchar(255) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`clicks` bigint(20) NOT NULL,
`oHours` varchar(255) NOT NULL,
`featured` tinyint(1) NOT NULL,
`imageThumb` varchar(255) NOT NULL DEFAULT 'default.jpg',
`imageOrig` varchar(255) NOT NULL DEFAULT 'default.jpg',
`flag` tinyint(1) NOT NULL,
`display` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=589846 ;
此表(业务)有 507,736 条记录
CREATE TABLE IF NOT EXISTS `businesscat` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`bizID` bigint(20) NOT NULL,
`catID` bigint(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=589863 ;
此表(businesscat)有 519,825 条记录
CREATE TABLE IF NOT EXISTS `category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`url` varchar(255) NOT NULL,
`icon` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
此表(类别)只有 5 条记录
所以,我的问题是我正在尝试使用 ff 计算最近的业务来获取 100 条记录:
SELECT business.name
, business.lng
, business.lat
, business.address
, business.city
, business.state
, business.postal
, business.phone
, business.url
, business.imageThumb
, businesscat.catID
, category.icon
, (((acos(sin((".$lat."*pi()/180))
* sin((business.lat*pi()/180))
+ cos((".$lat."*pi()/180))
* cos((business.lat*pi()/180))
* cos(((".$lng."-business.lng)*pi()/180))))
* 180/pi())*60*1.1515) AS distance
FROM business
INNER JOIN businesscat ON businesscat.bizID=business.id
INNER JOIN category ON category.id=businesscat.catID
ORDER BY distance LIMIT 100
任何想法让它更快?