我正在開發應用程序,隨着應用程序的增長,我的查詢也一樣。
問題:
它需要14秒鐘一組查詢的特定功能,可以執行
解析:如何在php中減少查詢時間
public function doQuery($venueId){
//creating an outlet object using the outlet id.
$outlet = new ParseObject("Outlets", $venueId);
//querying for total amount of beacons
$beacQuery = new ParseQuery("Beacons");
$beacQuery->equalTo("outlet", $outlet);
$beacresults = $beacQuery->count();
//querying for outlets based on id
//I can't do this by simply calling get() on the object
//I created earlier
$outletQuery = new ParseQuery("Outlets");
$outletQuery->equalTo("objectId", $venueId);
$outletQuery->includeKey("city.states");
$outletQuery->includeKey("city.states.country");
$compResults = $outletQuery->find();
$outletInfo = [];
for ($i = 0; $i < count($compResults); $i++) {
$object = $compResults[$i];
$cityCheck = $object->get("city");
$statesCheck = $cityCheck->get("states");
$countryCheck = $statesCheck->get("country");
$city = $cityCheck->get("Cities");
$state = $statesCheck->get("stateName");
$country = $countryCheck->get("countryName");
$outletInfo[] = ['venueName' => $object->get('outletName'),
'venueAddr' => $object->get('address').', '.$city.', '.$state.', '.$country,
'venueEmail' => $object->get('email'),
'venueId' => $object->getObjectId(),
'totalBeac' => $beacresults,
];
}
return $outletInfo;
}
我需要知道,如果有簡化的查詢,減少查詢時間及製法頁面加載速度更快(加載速度慢對用戶體驗不利)。
'EXPLAIN'查詢,看看它是如何執行的,然後索引適當的列。 – twentylemon
做@twentylemon說的話,然後再運行'EXPLAIN'。 –
正在索引可能的解析? @twentylemon – lawrenceagbani