このクエリを使用しましたが、mysqlが結果を出すのに時間がかかりすぎました。行数は160万行です。
SELECT DISTINCT TB.ID, Latitude, Longitude,
111151.29341326*SQRT(pow(-6-`Latitude`,2)
+pow(106-`Longitude`,2)*cos(-6*0.017453292519943)
*cos(`Latitude`*0.017453292519943)) as Distance
FROM `tablebusiness` AS TB, `tablecity` AS TC, `businessestag` AS BC,
`businessesdistricts` AS BD, `tabledistrict` AS TD,
(SELECT ID,
(SELECT Title
FROM `tablebusiness` As TBuild
WHERE TBuild.ID = TBB.Building) As BuildingTitle
FROM `tablebusiness` As TBB) AS TBuilding
WHERE TB.City = TC.City AND BC.BusinessID = TB.ID AND BD.BusinessID = TB.ID
AND TD.ID = BD.District AND TBuilding.ID = TB.ID
AND (`Title` LIKE '%%' OR `Street` LIKE '%%' OR TB.City LIKE '%%'
OR Country LIKE '%%' OR Tag LIKE '%%' OR TD.District LIKE '%%'
OR TBuilding.BuildingTitle LIKE '%%')
AND (-6.0917668133836 < `Latitude` AND `Latitude` < -5.9082331866164
AND 105.90823318662 < `Longitude` AND `Longitude` < 106.09176681338)
ORDER BY Distance LIMIT 0, 100
行数はクエリの160万部分ですが、
AND (-6.0917668133836 < `Latitude` AND `Latitude` < -5.9082331866164 AND 105.90823318662 < `Longitude` AND `Longitude` < 106.09176681338)
行数を大幅に制限します。mysqlが検索してクエリを最適化することを気にしないようです
AND (-6.0917668133836 < `Latitude` AND `Latitude` < -5.9082331866164 AND 105.90823318662 < `Longitude` AND `Longitude` < 106.09176681338) first.
前面の緯度経度アスペクトを移動してクエリを変更しました
SELECT DISTINCT TB.ID, Latitude, Longitude,
111151.29341326*SQRT(pow(-6-`Latitude`,2)
+pow(106-`Longitude`,2)*cos(-6*0.017453292519943)
*cos(`Latitude`*0.017453292519943)) as Distance
FROM `tablebusiness` AS TB, `tablecity` AS TC, `businessestag` AS BC,
`businessesdistricts` AS BD, `tabledistrict` AS TD,
(SELECT ID,
(SELECT Title
FROM `tablebusiness` As TBuild
WHERE TBuild.ID = TBB.Building) As BuildingTitle
FROM `tablebusiness` As TBB) AS TBuilding
WHERE (-6.0917668133836 < `Latitude` AND `Latitude` < -5.9082331866164
AND 105.90823318662 < `Longitude` AND `Longitude` < 106.09176681338)
AND TB.City = TC.City AND BC.BusinessID = TB.ID AND BD.BusinessID = TB.ID
AND TD.ID = BD.District AND TBuilding.ID = TB.ID
AND (`Title` LIKE '%%' OR `Street` LIKE '%%' OR TB.City LIKE '%%'
OR Country LIKE '%%' OR Tag LIKE '%%' OR TD.District LIKE '%%'
OR TBuilding.BuildingTitle LIKE '%%')
ORDER BY Distance LIMIT 0 ,100
それでも同じくらい遅いです。
それならどうすればいいですか?