* Fixed bug #7545: Explain queries does not work when selecting multiple tables ...
authorMichael Stucki <michael.stucki@typo3.org>
Fri, 29 Feb 2008 11:46:01 +0000 (11:46 +0000)
committerMichael Stucki <michael.stucki@typo3.org>
Fri, 29 Feb 2008 11:46:01 +0000 (11:46 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@3326 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_db.php

index 91f7c7d..e953d04 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-02-29  Michael Stucki  <michael@typo3.org>
+
+       * Fixed bug #7545: Explain queries does not work when selecting multiple tables (patch by Ingo Schmitt)
+
 2008-02-29  Ingmar Schlecht  <ingmar@typo3.org>
 
        * Fixed bug #1358: Installer didn't honour fourceCharset (patch by Masi)
index 66f90db..2eb8992 100755 (executable)
@@ -1164,25 +1164,29 @@ class t3lib_DB {
                $error = $GLOBALS['TYPO3_DB']->sql_error();
                $trail = t3lib_div::debug_trail();
 
+               $explain_tables = array();
                $explain_output = array();
                $res = $this->sql_query('EXPLAIN '.$query, $this->link);
                if (is_resource($res)) {
                        while ($tempRow = $this->sql_fetch_assoc($res)) {
                                $explain_output[] = $tempRow;
+                               $explain_tables[] = $tempRow['table'];
                        }
                        $this->sql_free_result($res);
                }
 
                $indices_output = array();
-               if ($explain_output[0]['rows']>1 || t3lib_div::inList('ALL',$explain_output[0]['type'])) {
+               if ($explain_output[0]['rows']>1 || t3lib_div::inList('ALL',$explain_output[0]['type'])) {      // Notice: Rows are skipped if there is only one result, or if no conditions are set
                        $debug = true;  // only enable output if it's really useful
 
-                       $res = $this->sql_query('SHOW INDEX FROM '.$from_table, $this->link);
-                       if (is_resource($res)) {
-                               while ($tempRow = $this->sql_fetch_assoc($res)) {
-                                       $indices_output[] = $tempRow;
+                       foreach ($explain_tables as $table) {
+                               $res = $this->sql_query('SHOW INDEX FROM '.$table, $this->link);
+                               if (is_resource($res)) {
+                                       while ($tempRow = $this->sql_fetch_assoc($res)) {
+                                               $indices_output[] = $tempRow;
+                                       }
+                                       $this->sql_free_result($res);
                                }
-                               $this->sql_free_result($res);
                        }
                } else {
                        $debug = false;