mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-02 05:02:48 +08:00
添加SQL性能分析(开启数据库调试模式)
This commit is contained in:
@@ -1170,7 +1170,17 @@ abstract class Driver
|
||||
$this->modelSql[$this->model] = $this->queryStr;
|
||||
// 记录操作结束时间
|
||||
Debug::remark('queryEndTime', 'time');
|
||||
Log::record($this->queryStr . ' [ RunTime:' . Debug::getRangeTime('queryStartTime', 'queryEndTime') . 's ]', 'sql');
|
||||
$log = $this->queryStr . ' [ RunTime:' . Debug::getRangeTime('queryStartTime', 'queryEndTime') . 's ]';
|
||||
// SQL性能分析
|
||||
if (0 === stripos(trim($this->queryStr), 'select')) {
|
||||
$pdo = $this->linkID->query("EXPLAIN " . $this->queryStr);
|
||||
$result = $pdo->fetch(PDO::FETCH_ASSOC);
|
||||
if (strpos($result['extra'], 'filesort') || strpos($result['extra'], 'temporary')) {
|
||||
Log::record('SQL:' . $this->queryStr . '[' . $result['extra'] . ']', 'warn');
|
||||
}
|
||||
$log .= '[ EXPLAIN : ' . var_export($result, true) . ' ]';
|
||||
}
|
||||
Log::record($log, 'sql');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user