[Phpmyadmin-devel] [PATCH] Better InnoDB info.

Joshua Nye josh at boxcarmedia.com
Thu Feb 21 09:08:21 CET 2002


This patch rewrites the handling of row count and table size in db_details to more accurately deal with different table types such as InnoDB. It also re-enables the valid fields of size usage and row stats in tbl_properties for InnoDB tables.

-Josh

diff -r -u phpMyAdmin-2.2.4/db_details.php phpMyAdmin-devel/db_details.php
--- phpMyAdmin-2.2.4/db_details.php Tue Feb 19 18:35:40 2002
+++ phpMyAdmin-devel/db_details.php Thu Feb 21 12:00:00 2002
@@ -237,51 +237,43 @@
     </td>
         <?php
         echo "\n";
-        $mergetable         = FALSE;
-        $nonisam            = FALSE;
-        if (isset($sts_data['Type'])) {
-            if ($sts_data['Type'] == 'MRG_MyISAM') {
-                $mergetable = TRUE;
-            } else if (!eregi('ISAM|HEAP', $sts_data['Type'])) {
-                $nonisam    = TRUE;
+
+        if(isset($sts_data['Rows'])) {
+            # MyISAM, ISAM or Heap table: Row count, data size and index size is accurate.
+            if(isset($sts_data['Type']) && ereg('^(MyISAM|ISAM|HEAP)$', $sts_data['Type'])) {
+                $tblsize = $sts_data['Data_length'] + $sts_data['Index_length'];
+                $sum_size += $tblsize;
+                list($formated_size, $unit) =  PMA_formatByteDown($tblsize, 3, $tblsize > 0 ? 1 : 0);
+                $sum_entries += $sts_data['Rows'];
+                $display_rows = number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator);
             }
-        }
 
-        if (isset($sts_data['Rows'])) {
-            if ($mergetable == FALSE) {
-                if ($cfgShowStats && $nonisam == FALSE) {
-                    $tblsize                        =  $sts_data['Data_length'] + $sts_data['Index_length'];
-                    $sum_size                       += $tblsize;
-                    if ($tblsize > 0) {
-                        list($formated_size, $unit) =  PMA_formatByteDown($tblsize, 3, 1);
-                    } else {
-                        list($formated_size, $unit) =  PMA_formatByteDown($tblsize, 3, 0);
-                    }
-                } else if ($cfgShowStats) {
-                    $formated_size                  = ' - ';
-                    $unit                           = '';
-                }
-                $sum_entries                        += $sts_data['Rows'];
+            # InnoDB table: Row count is not accurate but data and index sizes are.
+            elseif(isset($sts_data['Type']) && $sts_data['Type'] == "InnoDB") {
+                $tblsize = $sts_data['Data_length'] + $sts_data['Index_length'];
+                $sum_size += $tblsize;
+                list($formated_size, $unit) =  PMA_formatByteDown($tblsize, 3, $tblsize > 0 ? 1 : 0);
+                $display_rows = ' - ';
             }
-            // MyISAM MERGE Table
-            else if ($cfgShowStats && $mergetable == TRUE) {
+
+            # Merge or BerkleyDB table: Only row count is accurate.
+            elseif(isset($sts_data['Type']) && ereg('^(MRG_MyISAM|BerkeleyDB)$', $sts_data['Type'])) {
                 $formated_size = ' - ';
-                $unit          = '';
+                $unit = '';
+                $sum_entries += $sts_data['Rows'];
+                $display_rows = number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator);
             }
-            else if ($cfgShowStats) {
+
+            # Unknown table type.
+            else {
                 $formated_size = 'unknown';
-                $unit          = '';
+                $unit = '';
+                $display_rows = 'unknown';
             }
+
             ?>
     <td align="right" bgcolor="<?php echo $bgcolor; ?>">
-            <?php
-            echo "\n" . '        ';
-            if ($mergetable == TRUE) {
-                echo '<i>' . number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . '</i>' . "\n";
-            } else {
-                echo number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n";
-            }
-            ?>
+        <?php echo $display_rows . "\n"; ?>
     </td>
     <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
          <?php echo (isset($sts_data['Type']) ? $sts_data['Type'] : ' '); ?> 
@@ -291,24 +283,21 @@
                 echo "\n";
                 ?>
     <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
-          
-        <a href="tbl_properties.php?<?php echo $url_query; ?>#showusage"><?php echo $formated_size . ' ' . $unit; ?></a>
+          <a href="tbl_properties.php?<?php echo $url_query; ?>#showusage"><?php echo $formated_size . ' ' . $unit; ?></a>
     </td>
                 <?php
-                echo "\n";
-            } // end if
-        } else {
+            }
+        }
+        else {
             ?>
-    <td colspan="3" align="center" bgcolor="<?php echo $bgcolor; ?>">
-        <?php echo $strInUse . "\n"; ?>
-    </td>
+<td colspan="3" align="center" bgcolor="<?php echo $bgcolor; ?>"><?php echo $strInUse . "\n"; ?></td>
             <?php
         }
         echo "\n";
         ?>
 </tr>
         <?php
-    }
+    } 
     // Show Summary
     if ($cfgShowStats) {
         list($sum_formated, $unit) = PMA_formatByteDown($sum_size, 3, 1);
diff -r -u phpMyAdmin-2.2.4/tbl_properties.php phpMyAdmin-devel/tbl_properties.php
--- phpMyAdmin-2.2.4/tbl_properties.php Tue Feb 19 18:35:42 2002
+++ phpMyAdmin-devel/tbl_properties.php Thu Feb 21 11:58:15 2002
@@ -484,10 +484,11 @@
 // BEGIN - Calc Table Space - staybyte - 9 June 2001
 if ($cfgShowStats) {
     $nonisam     = FALSE;
+    $innodb = $showtable['Type'] == "InnoDB";
     if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
         $nonisam = TRUE;
     }
-    if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE) {
+    if (PMA_MYSQL_INT_VERSION >= 32303 && ($nonisam == FALSE || $innodb)) {
         // Gets some sizes
         $mergetable     = FALSE;
         if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
@@ -613,7 +614,7 @@
         </tr>
             <?php
         }
-        if (isset($showtable['Rows'])) {
+        if (!$innodb && isset($showtable['Rows'])) {
             $bgcolor = ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne);
             echo "\n";
             ?>
@@ -625,7 +626,7 @@
         </tr>
             <?php
         }
-        if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
+        if (!$innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
             $bgcolor = ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne);
             echo "\n";
             ?>
@@ -637,7 +638,7 @@
         </tr>
             <?php
         }
-        if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
+        if (!$innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
             $bgcolor = ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne);
             echo "\n";
             ?>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.phpmyadmin.net/pipermail/developers/attachments/20020221/7d35f243/attachment.html>


More information about the Developers mailing list