优化我的项目的场景对象

时间:2012-07-27 11:16:17

标签: php mysql optimization query-optimization

我的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);
}


?>

2 个答案:

答案 0 :(得分:2)

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

  1. 数据提取
  2. 数据准备
  3. 在当前的实现中,每个foreach()循环对数据库进行一次查询。 尝试这样做:

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

    等等。

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

    然后,当您获取3-5个查询中的所有数据时,您应该使用数组 - 再次在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);
        }
        ...
    

    }

    唯一的 - 你必须找到另一种检查连接状态的方法:)

    干杯;)

答案 1 :(得分: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