From: Alexander Ebert Date: Sun, 2 Jun 2013 22:22:33 +0000 (+0200) Subject: Improved logging for SQLParser X-Git-Tag: 2.0.0_Beta_3~23^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b2f79fc585d32f39aba7075e30cbe41d0f1f5b6b;p=GitHub%2FWoltLab%2FWCF.git Improved logging for SQLParser --- diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 7d889ea878..4c0627e1a8 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -728,13 +728,17 @@ class WCFSetup extends WCF { $sql = StringUtil::replace('wcf1_', 'wcf'.WCF_N.'_', $sql); $GLOBALS['__db'] = array( + '__construct' => 0, 'parse' => 0, 'modify' => 0, 'insert' => 0, 'tableCount' => 0, 'table' => 0, + 'tableGlobal' => 0, 'default' => 0, - 'defaultCount' => 0 + 'defaultCount' => 0, + 'key' => 0, + 'keyCount' => 0 ); // execute sql queries diff --git a/wcfsetup/install/files/lib/system/database/util/SQLParser.class.php b/wcfsetup/install/files/lib/system/database/util/SQLParser.class.php index 0a7cd7e246..2b794cdf25 100644 --- a/wcfsetup/install/files/lib/system/database/util/SQLParser.class.php +++ b/wcfsetup/install/files/lib/system/database/util/SQLParser.class.php @@ -30,12 +30,14 @@ class SQLParser { */ public function __construct($queries) { // delete comments + $start = microtime(true); $queries = preg_replace("~('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|(?:(?:--|#)[^\n]*|/\*.*?\*/)~s", '$1', $queries); // split queries by semicolon if (preg_match_all("~(?:[^;']+(?:'[^'\\\\]*(?:\\\\.[^'\\\\]*)*')*)*(?=;|\$)~s", $queries, $matches)) { $this->queryArray = ArrayUtil::trim($matches[0]); } + $GLOBALS['__db']['__construct'] = round(microtime(true) - $start, 3); } /** @@ -66,6 +68,7 @@ class SQLParser { case 'CREATE TABLE': // get table name if (preg_match('~^CREATE\s+TABLE\s+(\w+)\s*\(~i', $query, $match)) { + $startG = microtime(true); $tableName = $match[1]; $columns = $indices = array(); @@ -118,6 +121,7 @@ class SQLParser { $this->executeCreateTableStatement($tableName, $columns, $indices); $GLOBALS['__db']['tableCount']++; $GLOBALS['__db']['table'] += round(microtime(true) - $s, 3); + $GLOBALS['__db']['tableGlobal'] += round(microtime(true) - $startG, 3); } break; @@ -128,7 +132,10 @@ class SQLParser { } // add foreign key else if (preg_match('~^ALTER\s+TABLE\s+(\w+)\s+ADD\s+FOREIGN KEY\s+(?:(\w+)\s*)?\((\s*\w+\s*(?:,\s*\w+\s*)*)\)\s+REFERENCES\s+(\w+)\s+\((\s*\w+\s*(?:,\s*\w+\s*)*)\)(?:\s+ON\s+(UPDATE|DELETE)\s+(CASCADE|SET NULL|NO ACTION))?~is', $query, $match)) { + $s = microtime(true); $this->executeAddForeignKeyStatement($match[1], ($match[2] ?: self::getGenericIndexName($match[1], $match[3], 'fk')), array('columns' => $match[3], 'referencedTable' => $match[4], 'referencedColumns' => $match[5], 'operation' => $match[6], 'action' => $match[7])); + $GLOBALS['__db']['keyCount']++; + $GLOBALS['__db']['key'] += round(microtime(true) - $s, 3); } // add/change column else if (preg_match("~^ALTER\s+TABLE\s+(\w+)\s+(?:(ADD)\s+(?:COLUMN\s+)?|(CHANGE)\s+(?:COLUMN\s+)?(\w+)\s+)(\w+)\s+(\w+)(?:\s*\((\s*(?:\d+(?:\s*,\s*\d+)?|'[^']*'(?:\s*,\s*'[^']*')*))\))?(?:\s+UNSIGNED)?(?:\s+(NOT NULL|NULL))?(?:\s+DEFAULT\s+(-?\d+.\d+|-?\d+|NULL|'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'))?(?:\s+(AUTO_INCREMENT))?(?:\s+(UNIQUE|PRIMARY)(?: KEY)?)?~is", $query, $match)) {