title: mysql query inner join slowing
body: <p>I have the following database structure:</p>
  
  <pre><code>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 ;
  </code></pre>
  
  <p>This table (business) has 507,736 records</p>
  
  <pre><code>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 ;
  </code></pre>
  
  <p>This table (businesscat) has 519,825 records</p>
  
  <pre><code>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 ;
  </code></pre>
  
  <p>This table (category) has only 5 records</p>
  
  <p>So, my problem is I'm trying to get 100 records with calculation of nearest business using the ff:</p>
  
  <pre><code>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 
  </code></pre>
  
  <p>Any idea to make it faster? </p>