Improved logging for SQLParser
authorAlexander Ebert <ebert@woltlab.com>
Sun, 2 Jun 2013 22:22:33 +0000 (00:22 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 2 Jun 2013 22:22:33 +0000 (00:22 +0200)
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/system/database/util/SQLParser.class.php

index 7d889ea878814e6b803be92d3e9ea81028c6c23b..4c0627e1a82d3922e84c0ed7ae41f4b2fa49c2b5 100644 (file)
@@ -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
index 0a7cd7e2465024f59a9e683de90df907617ba725..2b794cdf25a0d9a2bccbafe4ebd5651d99fb2d82 100644 (file)
@@ -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)) {