1

我的 queryScenario.php 文件加载速度太慢,平均 28 秒。我该怎么做才能通过查询和循环来减少这种情况?我不知道如何处理它,因为我对优化 PHP 几乎一无所知。

谢谢。

这是我的 queryScenario.php 文件:

<?php
        include("database.php");
        include("dataModel.php");

        if(!isset($_SESSION))
            session_start();

        //$userId = 1; // This variable will be obtained from the session
        $userId = $_SESSION['userIdNumber'];
        //$selectedUserLandId = $_GET['id']; // This variable may be defined as a session variable
        $selectedUserLandId = $_SESSION['selectedUserLandId'];

        // load the related user based model tables (dynamic data)
        $landLiteral = dbGetUserLandByLandId($userId, $selectedUserLandId); 
        if (count($landLiteral)< 1){
            // TODO: Throw an exception here          
        }
        $landLiteralSelected = $landLiteral[0];
        $userLand = new Land();
        $userLand->id = $landLiteralSelected["id"];
        $userLand->name = $landLiteralSelected["name"];
        $userLand->desc = $landLiteralSelected["description"];
        $landmap = dbGetLandmapById($landLiteralSelected["id"]);
        $userLand->mapimage = $landmap[0]["mapimage"];
        $geopos = dbGetGeoposById($landLiteralSelected["geopos_id"]);
        $userLand->lat = $geopos[0]["lat"];
        $userLand->lng = $geopos[0]["lng"] ;
        $userLand->type = $landLiteralSelected["landenum_id"];
        $sectorsLiteral = dbGetSectorsByLandId($userLand->id);
        foreach ($sectorsLiteral as $sectorLiteral){
           $sector = new Sector();
            $sector->id = $sectorLiteral["id"];
            $sector->name = $sectorLiteral["name"];
            $sector->desc = $sectorLiteral["description"];
            $geoposSector = dbGetGeoposById($sectorLiteral["geopos_id"]);
            $sector->lat = $geoposSector[0]["lat"];
            $sector->lng = $geoposSector[0]["lng"] ;
            $userLand->sectionList[] = $sector;

            $devicesLiteral = dbGetDevicesBySectorId($sector->id);
            foreach ($devicesLiteral as $deviceLiteral){
                $device = new Device();
                $device->id = $deviceLiteral["id"];
                $device->sceneName = $deviceLiteral["scenename"];
                $device->sceneDesc = $deviceLiteral["scenedescription"];
                $mapinfoDevice = dbGetMapInfoById($deviceLiteral["mapitem_id"]);
                $device->mapInfo[] = $mapinfoDevice[0];
                $geoposDevice = dbGetGeoposById($deviceLiteral["geopos_id"]);
                $device->lat = $geoposDevice[0]["lat"];
                $device->lng = $geoposDevice[0]["lng"];
                $device->type = $deviceLiteral["deviceenum_id"];
                $device->serialNo = $deviceLiteral["serialNo"];
                $sector->deviceList[] = $device;

                // NOW THE MODULES
                $modulesLiteral = dbGetDeviceModulesByDeviceType($device->type);

                foreach($modulesLiteral as $moduleLiteralList){
                    foreach ($moduleLiteralList as $moduleLiteral){
                        $module = new Module();
                        $module->id = $moduleLiteral["id"];
                        $module->type = $moduleLiteral["moduleenum_id"];
                        $module->unit = $moduleLiteral["unit"];
                        $module->subid = dbGetSubIdOfModule($module->id);
                        $deviceStateLiteral=dbGetDeviceStates($device->id);

                        if (count($deviceStateLiteral) > 0){
                            $moduleState=new ModuleState();
                            $moduleState->pendingState=$deviceStateLiteral[0]["pending_state"];
                            $moduleState->desiredState=$deviceStateLiteral[0]["desired_state"];
                            $moduleState->currentState=$deviceStateLiteral[0]["current_state"];
                            $module->moduleState=$moduleState;
                        }
                        $moduleDataLiteral=dbGetLastDeviceModuleData($device->id,$module->id);
                        $moduleData=new ModuleData();
                        if (count($moduleDataLiteral) > 0){
                            $moduleData->data=$moduleDataLiteral[0]["value"]." ".$module->unit;
                            $moduleData->timeStamp=$moduleDataLiteral[0]["timestamp"];
                        }else{
                               $moduleData->data="Veri Yok";
                               $moduleData->timeStamp="Veri Yok";
                        }
                              $module->moduleData=$moduleData;

                        $device->moduleList[] = $module;

                        // NOW THE MODULE SPECS
                        // First, get the default specs
                        $specsLiteral = dbGetDefaultSpecsByModuleId($module->id);

                        foreach($specsLiteral as $specLiteral){
                            $spec = new Spec();
                            $spec->type = $specLiteral["specenum_id"];
                            $spec->editable = $specLiteral["editable"];
                            $spec->value = $specLiteral["default"];

                            // NOW LOOK FOR UPDATED SPEC FOR THIS DEVICE MODULE AND SPEC
                            $updatedSpecLiteral = dbGetUpdatedDeviceSpec($device->id, $module->id, $spec->type);

                            if ($updatedSpecLiteral){
                               $spec->value = $updatedSpecLiteral[0]["specvalue"];
                            }

                            $module->specList[] = $spec;
                        }
                    }           
                }
            }
        }
        if(!(isset($_GET["nonEcho"]) && $_GET["nonEcho"]=="yes"))
            echo json_encode($userLand);

?>

这些是数据模型:

<?php
class Node {
    public $id;
}

class SpatialNode extends Node {
    public $lat = 0;
    public $lng = 0;
}

class Land extends SpatialNode{
    public $name;
    public $desc = "";
    public $type;
    public $sectionList = array();
    public $mapimage;
}

class Sector extends SpatialNode{
    public $name;
    public $desc = "";
    public $deviceList = array();
}

class Device extends SpatialNode{
    public $sceneName;
    public $sceneDesc;
    public $type;
    public $desc = "";
    public $serialNo;
    public $installationDate = "";
    public $moduleList = array();
    public $mapInfo = array();
}

class Module extends Node{
    public $type;
    public $unit = "";
    public $subid;
    public $specList = array();
    public $moduleData;
    public $moduleState;
}

class ModuleData{
    public $data;
    public $timeStamp;
}
class ModuleState{
    public $pendingState;
    public $desiredState;
    public $currentState;
}
class Spec{
    public $type;
    public $value;
    public $editable;
}


class DeviceStatus{
    public $name;
    public $address;
    public $pendingState;
    public $desiredState;
}

?>

这些是查询:

<?php
//include("dataModel.php");

function dbConnect() {
    $dbhost = 'XXXXXXXX';
    $dbuser = 'XXXXX';
    $dbpass = 'XXXXXXXXX';

    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if (!$conn) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db('XXXXXXXXX', $conn);
    mysql_query("SET NAMES UTF8");
    return $conn;
}

function executeSQL($sql) {
    $conn = dbConnect();

    $values = array();
    $retval = mysql_query($sql, $conn);

    if (!$retval) {
        die('Could not get data: ' . mysql_error());
    }

    while ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
        array_push($values, $row);
    }

    return $values;
}

function executeSQLForPersist($sql){
    $conn = dbConnect();


    $retval = mysql_query($sql, $conn);

    return $retval;
}

function dbGetLandsByUserId($userId){
    $sql  = "SELECT * FROM land WHERE user_id=$userId or user_id=1 ";
    return executeSQL($sql);
}

function dbGetUserLandByLandId($userId, $landId){
    $sql = "SELECT * FROM land WHERE user_id=$userId AND id=$landId UNION SELECT * FROM land WHERE user_id=1 AND id=1";
    return executeSQL($sql);
}

function dbGetGeoposById($geoId){
    $sql  = "SELECT * FROM geoposition WHERE id=$geoId";
    return executeSQL($sql);
}
function dbGetLandmapById($id){
    $sql  = "SELECT * FROM landimages WHERE land_id=$id";
    return executeSQL($sql);
}
function dbGetMapInfoById($id) {
    $sql  = "SELECT * FROM mapitems WHERE id=$id";
    return executeSQL($sql);
}

function dbGetEnums(){
    $sql = "SELECT * FROM enums";
    return executeSQL($sql);
}

function dbGetSceneDevices(){
    $sql = "SELECT * FROM scenedevices";
    return executeSQL($sql);
}


function dbGetSectorsByLandId($landId){
    $sql = "SELECT * FROM sector WHERE land_id=$landId";
    return executeSQL($sql);
}

function dbGetDevicesBySectorId($sectorId){
    $sql = "SELECT * FROM scenedevices WHERE sector_id=$sectorId";
    return executeSQL($sql);
}

function dbGetDeviceModulesByDeviceType($deviceTypeId){
     $sql = "SELECT module_id FROM devicedef WHERE deviceenum_id=$deviceTypeId";
     $moduleIdsLiteral = executeSQL($sql);

     $modulesLiteralList = array();
     foreach ($moduleIdsLiteral as $moduleIdLiteral){
         $moduleId = $moduleIdLiteral["module_id"];
         $sqlModuleQuery = "SELECT * FROM module WHERE id=$moduleId";
         $modulesLiteralList[] = executeSQL($sqlModuleQuery);

     }
     return $modulesLiteralList;
}

function dbGetDefaultSpecsByModuleId($moduleId){
    $sql = "SELECT * FROM module_specs WHERE module_id=$moduleId";
    return executeSQL($sql);
}

function dbGetUpdatedDeviceSpec($deviceId, $moduleId, $specId){
    $sql = "SELECT * FROM deviceprefs WHERE scenedevice_id=$deviceId AND module_id=$moduleId AND specenum_id=$specId";
    return executeSQL($sql);
}

function dbGetProfileLandImageByLandId($landId){
    $sql = "SELECT * FROM landimages WHERE land_id=$landId AND profile=1";
    return executeSQL($sql);
}


function dbGetSubIdOfModule($moduleId){
    $sql = "SELECT * FROM devicedef WHERE module_id='$moduleId'";
    $idLiteral = executeSQL($sql);
    if(count($idLiteral) != 0) {
        return $idLiteral[0]["subid"];
    }
    else {
        return -1;
    }
}

function dbGetModuleIdByModuleEnumId($moduleEnumId){
    $sql = "SELECT * FROM module WHERE moduleenum_id=$moduleEnumId";
    $idLiteral = executeSQL($sql);
    if (count($idLiteral) == 1){
        return $idLiteral[0]['id'];
    }else{
        return -1;
    }
}

function dbGetAllDeviceModuleData($devId, $modId){
    $sql = "SELECT * FROM realtimedevicedata WHERE scenedevice_id=$devId AND module_id=$modId ORDER BY timestamp LIMIT 0, 500"; //TODO.
    return executeSQL($sql);
}
function dbGetLastDeviceModuleData($devId, $modId){
    $sql = "SELECT * FROM realtimedevicedata WHERE scenedevice_id=$devId AND module_id=$modId ORDER BY timestamp desc limit 1";
    return executeSQL($sql);   
}

function dbGetLastDayDeviceModuleData($devId, $modId){
    $sql = "SELECT * FROM realtimedevicedata WHERE scenedevice_id=$devId AND module_id=$modId AND timestamp>=SYSDATE()-INTERVAL 1 DAY ORDER BY timestamp";
    return executeSQL($sql);   
}

function dbGetIntervalDeviceModuleData($devId, $modId, $startDate, $endDate){
    $sql = "SELECT * FROM realtimedevicedata WHERE scenedevice_id=$devId AND module_id=$modId AND timestamp>='$startDate' AND timestamp<='$endDate' ORDER BY timestamp";
    return executeSQL($sql);   
}

function dbGetDeviceStates($devId) {
    $sql = "SELECT * FROM deviceprefs WHERE scenedevice_id=$devId";
    return executeSQL($sql);   
}

function dbGetAllDeviceStates($imei) {
    $sql  = "SELECT  scenedevices.scenename, scenedevices.serialNo, deviceprefs.pending_state, ".
            "deviceprefs.desired_state FROM  scenedevices, deviceprefs ". 
        "WHERE  scenedevices.parentId = '".$imei."' AND scenedevices.id = deviceprefs.scenedevice_id ";
    return executeSQL($sql);
}


?>
4

2 回答 2

2

我对这个主题的一般想法是,您应该将代码分成两个主要部分:

  1. 数据提取
  2. 数据准备

在您当前的实现中,每个foreach()循环都有一个针对 DB 的查询。尝试这样做:

$sectorsLiteral = dbGetSectorsByLandId($userLand->id);
$sectorsLiteralIds = array();
foreach ($sectorsLiteral as $sectorLiteral) {
    $sectorsLiteralIds[] = $sectorLiteral["id"]
}

$devicesLiteral = dbGetDevicesBySectorId($sectorsLiteralIds);

等等。

当然,您必须调整您的数据库“类”以接受参数数组。

然后,当您将在 3-5 个查询中获取所有数据时,您应该使用数组 - 在 foreaches 中再次使用 foreaches,但它们会运行得很快,因为您不必在每个循环周期内提取数据。

处理所有进一步准备的抽象方法如下所示

$response = array();
foreach($sectorsLiteral as $sectorLiteral) {
    foreach($devicesLiteral as $deviceLiteral) {
        if ($deviceLiteral['sectorId'] == $sectorLiteral['id']) {
            ...do what you need
        }
    }
}

是的,代码变得更加复杂,但它的工作速度要快得多。

编辑

您的代码的一项重要改进 - 您应该将您$connection的全局变量放在全局变量中,以避免每次发送查询时都打开新变量。

$conn = false;

function dbConnect() {
    ...
    global $conn;

    if (!$conn) {
        $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    }
    ...

}

唯一的事情-您将不得不找到另一种检查连接状态的方法:)

干杯;)

于 2012-07-27T12:06:39.490 回答
0

我意识到我的代码运行缓慢的原因是 realtimedevicedata 表太大(大约 120MB 并且有 50K 记录),我尝试在选择没有记录之前订购此表。为避免这种情况,我将代码更改为从该表中获取前 500 条记录,然后对该表进行排序。这打破了链条。

感谢所有愿意提供帮助的人,并为时间松散感到抱歉。祝你有美好的一天。

SQL 更改:

老一:

$sql = "SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=$devId AND module_id=$modId ORDER BY timestamp desc limit 0,1";

新的一个:

$sql = "SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=$devId AND K.module_id=$modId LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1";

realtimedevicedata 的证明是一个坏女孩:

0.02 secs : SELECT * FROM land WHERE user_id=2 AND id=1 UNION SELECT * FROM land WHERE user_id=1 AND id=1
0.11 secs : SELECT mapimage FROM landimages WHERE land_id=1 LIMIT 0,1
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=1 LIMIT 0,1
0.06 secs : SELECT id, name, description, geopos_id FROM sector WHERE land_id=1
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=2 LIMIT 0,1
0.03 secs : SELECT id,scenename,scenedescription,mapitem_id,geopos_id,deviceenum_id,serialNo FROM scenedevices WHERE sector_id=1
0.00 secs : SELECT * FROM mapitems WHERE id=1
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=47 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=6
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=11
0.00 secs : SELECT subid FROM devicedef WHERE module_id='11'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=1
0.15 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=1 AND module_id=11 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=11
0.00 secs : SELECT * FROM mapitems WHERE id=3
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=2 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=4
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=1
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=2
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=3
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=10
0.00 secs : SELECT subid FROM devicedef WHERE module_id='1'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=2
9.41 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=2 AND module_id=1 ORDER BY timestamp desc limit 0,1
0.01 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=1
0.02 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=1 AND specenum_id=14
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=1 AND specenum_id=15
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=1 AND specenum_id=18
0.00 secs : SELECT subid FROM devicedef WHERE module_id='2'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=2
6.84 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=2 AND module_id=2 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=2
0.01 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=2 AND specenum_id=14
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=2 AND specenum_id=15
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=2 AND specenum_id=18
0.02 secs : SELECT subid FROM devicedef WHERE module_id='3'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=2
4.44 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=2 AND module_id=3 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=3
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=3 AND specenum_id=14
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=3 AND specenum_id=15
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=3 AND specenum_id=18
0.00 secs : SELECT subid FROM devicedef WHERE module_id='10'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=2
9.27 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=2 AND module_id=10 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=10
0.01 secs : SELECT * FROM mapitems WHERE id=5
0.01 secs : SELECT lat,lng FROM geoposition WHERE id=44 LIMIT 0,1
0.02 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=5
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=4
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=10
0.00 secs : SELECT subid FROM devicedef WHERE module_id='4'
0.02 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=4
0.01 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=4 AND module_id=4 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=4
0.00 secs : SELECT subid FROM devicedef WHERE module_id='10'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=4
0.00 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=4 AND module_id=10 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=10
0.00 secs : SELECT * FROM mapitems WHERE id=6
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=45 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=31
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=4
0.00 secs : SELECT subid FROM devicedef WHERE module_id='4'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=5
0.00 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=5 AND module_id=4 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=4
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=3 LIMIT 0,1
0.00 secs : SELECT id,scenename,scenedescription,mapitem_id,geopos_id,deviceenum_id,serialNo FROM scenedevices WHERE sector_id=2
0.00 secs : SELECT * FROM mapitems WHERE id=4
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=3 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=29
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=1
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=2
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=9
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=10
0.00 secs : SELECT subid FROM devicedef WHERE module_id='1'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=3
4.34 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=3 AND module_id=1 ORDER BY timestamp desc limit 0,1
0.01 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=1
0.03 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=1 AND specenum_id=14
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=1 AND specenum_id=15
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=1 AND specenum_id=18
0.00 secs : SELECT subid FROM devicedef WHERE module_id='2'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=3
11.86 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=3 AND module_id=2 ORDER BY timestamp desc limit 0,1
0.02 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=2
0.05 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=2 AND specenum_id=14
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=2 AND specenum_id=15
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=2 AND specenum_id=18
0.04 secs : SELECT subid FROM devicedef WHERE module_id='9'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=3
4.25 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=3 AND module_id=9 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=9
0.00 secs : SELECT subid FROM devicedef WHERE module_id='10'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=3
2.71 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=3 AND module_id=10 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=10
0.00 secs : SELECT * FROM mapitems WHERE id=7
0.05 secs : SELECT lat,lng FROM geoposition WHERE id=46 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=5
0.01 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=4
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=10
0.00 secs : SELECT subid FROM devicedef WHERE module_id='4'
0.01 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=6
0.00 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=6 AND module_id=4 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=4
0.00 secs : SELECT subid FROM devicedef WHERE module_id='10'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=6
0.00 secs : SELECT value, timestamp FROM realtimedevicedata WHERE scenedevice_id=6 AND module_id=10 ORDER BY timestamp desc limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=10

现在,她答应我做个好女孩:)

0.00 secs : SELECT * FROM land WHERE user_id=2 AND id=1 UNION SELECT * FROM land WHERE user_id=1 AND id=1
0.00 secs : SELECT mapimage FROM landimages WHERE land_id=1 LIMIT 0,1
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=1 LIMIT 0,1
0.00 secs : SELECT id, name, description, geopos_id FROM sector WHERE land_id=1
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=2 LIMIT 0,1
0.00 secs : SELECT id,scenename,scenedescription,mapitem_id,geopos_id,deviceenum_id,serialNo FROM scenedevices WHERE sector_id=1
0.00 secs : SELECT * FROM mapitems WHERE id=1
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=47 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=6
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=11
0.00 secs : SELECT subid FROM devicedef WHERE module_id='11'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=1
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=1 AND K.module_id=11 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=11
0.00 secs : SELECT * FROM mapitems WHERE id=3
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=2 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=4
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=1
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=2
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=3
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=10
0.00 secs : SELECT subid FROM devicedef WHERE module_id='1'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=2
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=2 AND K.module_id=1 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=1
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=1 AND specenum_id=14
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=1 AND specenum_id=15
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=1 AND specenum_id=18
0.00 secs : SELECT subid FROM devicedef WHERE module_id='2'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=2
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=2 AND K.module_id=2 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=2
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=2 AND specenum_id=14
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=2 AND specenum_id=15
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=2 AND specenum_id=18
0.00 secs : SELECT subid FROM devicedef WHERE module_id='3'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=2
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=2 AND K.module_id=3 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=3
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=3 AND specenum_id=14
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=3 AND specenum_id=15
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=2 AND module_id=3 AND specenum_id=18
0.00 secs : SELECT subid FROM devicedef WHERE module_id='10'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=2
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=2 AND K.module_id=10 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=10
0.00 secs : SELECT * FROM mapitems WHERE id=5
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=44 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=5
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=4
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=10
0.00 secs : SELECT subid FROM devicedef WHERE module_id='4'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=4
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=4 AND K.module_id=4 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=4
0.00 secs : SELECT subid FROM devicedef WHERE module_id='10'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=4
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=4 AND K.module_id=10 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=10
0.00 secs : SELECT * FROM mapitems WHERE id=6
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=45 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=31
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=4
0.00 secs : SELECT subid FROM devicedef WHERE module_id='4'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=5
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=5 AND K.module_id=4 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=4
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=3 LIMIT 0,1
0.00 secs : SELECT id,scenename,scenedescription,mapitem_id,geopos_id,deviceenum_id,serialNo FROM scenedevices WHERE sector_id=2
0.00 secs : SELECT * FROM mapitems WHERE id=4
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=3 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=29
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=1
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=2
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=9
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=10
0.00 secs : SELECT subid FROM devicedef WHERE module_id='1'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=3
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=3 AND K.module_id=1 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=1
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=1 AND specenum_id=14
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=1 AND specenum_id=15
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=1 AND specenum_id=18
0.00 secs : SELECT subid FROM devicedef WHERE module_id='2'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=3
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=3 AND K.module_id=2 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=2
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=2 AND specenum_id=14
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=2 AND specenum_id=15
0.00 secs : SELECT specvalue FROM deviceprefs WHERE scenedevice_id=3 AND module_id=2 AND specenum_id=18
0.00 secs : SELECT subid FROM devicedef WHERE module_id='9'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=3
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=3 AND K.module_id=9 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=9
0.00 secs : SELECT subid FROM devicedef WHERE module_id='10'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=3
0.20 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=3 AND K.module_id=10 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=10
0.00 secs : SELECT * FROM mapitems WHERE id=7
0.00 secs : SELECT lat,lng FROM geoposition WHERE id=46 LIMIT 0,1
0.00 secs : SELECT module_id FROM devicedef WHERE deviceenum_id=5
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=4
0.00 secs : SELECT id, moduleenum_id, unit FROM module WHERE id=10
0.00 secs : SELECT subid FROM devicedef WHERE module_id='4'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=6
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=6 AND K.module_id=4 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=4
0.00 secs : SELECT subid FROM devicedef WHERE module_id='10'
0.00 secs : SELECT pending_state, desired_state, current_state FROM deviceprefs WHERE scenedevice_id=6
0.00 secs : SELECT value, timestamp FROM (SELECT DISTINCT scenedevice_id, value, timestamp FROM realtimedevicedata AS K WHERE K.scenedevice_id=6 AND K.module_id=10 LIMIT 0,100) AS M ORDER BY M.timestamp desc Limit 0,1
0.00 secs : SELECT `specenum_id`, `editable`, `default` FROM module_specs WHERE module_id=10
于 2012-07-27T12:21:12.280 回答