Move clusterIndex() to Postgres.php and drop Analyze from it. Add doReindex() + let...
authorsoranzo <soranzo>
Wed, 19 May 2004 01:28:34 +0000 (01:28 +0000)
committersoranzo <soranzo>
Wed, 19 May 2004 01:28:34 +0000 (01:28 +0000)
classes/database/BaseDB.php
classes/database/Postgres.php
classes/database/Postgres72.php
classes/database/Postgres73.php
classes/database/Postgres74.php
constraints.php
database.php
indexes.php

index 6d2b595e6577fd171d9f9ceff847e9391140056c..16804dddc3f6cedf342f034a0ce6e0c9de9fc8f1 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: BaseDB.php,v 1.45 2004/05/14 07:56:37 chriskl Exp $
+ * $Id: BaseDB.php,v 1.46 2004/05/19 01:28:34 soranzo Exp $
  */
 
 include_once('./classes/database/ADODB_base.php');
@@ -255,8 +255,9 @@ class BaseDB extends ADODB_base {
        function hasSchemas() { return false; }
        function hasConversions() { return false; }     
        function hasGrantOption() { return false; }
-       function hasCluster() { return false; }
+       function hasIsClustered() { return false; }
        function hasDropBehavior() { return false; }
+       function hasDropColumn() { return false; }
        function hasSRFs() { return false; }
        function hasDomains() { return false; }
        function hasDomainConstraints() { return false; }
@@ -275,6 +276,10 @@ class BaseDB extends ADODB_base {
        function hasSchemaDump() { return false; }
        function hasFunctionRename() { return false; }
        function hasAlterColumnType() { return false; }
+       function hasUserSessionDefaults() { return false; }
+       function hasUserRename() { return false; }
+       function hasRecluster() { return false; }
+       function hasFullVacuum() { return false; }
 
 }
 
index ef6c509b607caa0541fb6b1b5da5572de6a10aa2..da4ac0717b2ab0baa031b30db423b988826e5873 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.208 2004/05/16 15:46:24 chriskl Exp $
+ * $Id: Postgres.php,v 1.209 2004/05/19 01:28:34 soranzo Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -886,7 +886,7 @@ class Postgres extends BaseDB {
        /**
         * Formats a value or expression for sql purposes
         * @param $type The type of the field
-        * @param $mode VALUE or EXPRESSION
+        * @param $format VALUE or EXPRESSION
         * @param $value The actual value entered in the field.  Can be NULL
         * @return The suitably quoted and escaped value.
         */
@@ -2018,6 +2018,8 @@ class Postgres extends BaseDB {
 
        }
 
+       // Index functions
+
        /**
         * Grabs a list of indexes for a table
         * @param $table The name of a table whose indexes to retrieve
@@ -2076,6 +2078,23 @@ class Postgres extends BaseDB {
                return $this->execute($sql);
        }
 
+       /**
+        * Clusters an index
+        * @param $index The name of the index
+        * @param $table The table the index is on
+        * @return 0 success
+        */
+       function clusterIndex($index, $table) {
+               $this->fieldClean($index);
+               $this->fieldClean($table);
+
+               // We don't bother with a transaction here, as there's no point rolling
+               // back an expensive cluster if a cheap analyze fails for whatever reason
+               $sql = "CLUSTER \"{$index}\" ON \"{$table}\"";
+
+               return $this->execute($sql);
+       }
+
        // Rule functions
        
        /**
@@ -3255,15 +3274,18 @@ class Postgres extends BaseDB {
 
        /**
         * Vacuums a database
-        * @param $table (optional) The table to vacuum
-        */
-       function vacuumDB($table = '') {
+        * @param $table The table to vacuum
+        * @param $analyze If true, also does analyze
+        * @param $full If true, selects "full" vacuum (PostgreSQL >= 7.2)
+        * @param $freeze If true, selects aggressive "freezing" of tuples (PostgreSQL >= 7.2)
+        */
+       function vacuumDB($table = '', $analyze = false, $full = false, $freeze = false) {
+               $sql = "VACUUM";
+               if ($analyze) $sql .= " ANALYZE";
                if ($table != '') {
                        $this->fieldClean($table);
-                       $sql = "VACUUM \"{$table}\"";
+                       $sql .= " \"{$table}\"";
                }
-               else
-                       $sql = "VACUUM";
 
                return $this->execute($sql);
        }
@@ -3283,6 +3305,27 @@ class Postgres extends BaseDB {
                return $this->execute($sql);
        }
 
+       /**
+        * Rebuild indexes
+        * @param $type 'DATABASE' or 'TABLE' or 'INDEX'
+        * @param $name The name of the specific database, table, or index to be reindexed
+        * @param $force If true, recreates indexes forcedly in PostgreSQL 7.0-7.1, forces rebuild of system indexes in 7.2-7.3, ignored in >=7.4
+        */
+       function reindex($type, $name, $force=false) {
+               $this->fieldClean($name);
+               switch($type) {
+                       case 'DATABASE':
+                       case 'TABLE':
+                       case 'INDEX':
+                               $sql = "REINDEX {$type} {$name}";
+                               if ($force) $sql .= ' FORCE';
+                               break;
+                       default:
+                               return -1;
+               }
+               return $this->execute($sql);
+       }
+
        // Constraint functions
 
        /**
@@ -3775,11 +3818,8 @@ class Postgres extends BaseDB {
        function hasIndicies() { return true; }
        function hasRules() { return true; }
        function hasLanguages() { return true; }
-       function hasDropColumn() { return false; }
        function hasSRFs() { return true; }
        function hasOpClasses() { return true; }
-       function hasUserSessionDefaults() { return false; }
-       function hasUserRename() { return false; }
        function hasFunctionRename() { return true; }
 
 }
index a6fe50b9024083dfc0b9735b441fbd5856ec07e9..7ffca5cde4fe197ec9c2fa05f87128cfdc8cff63 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres72.php,v 1.64 2004/05/14 07:56:38 chriskl Exp $
+ * $Id: Postgres72.php,v 1.65 2004/05/19 01:28:34 soranzo Exp $
  */
 
 
@@ -378,6 +378,26 @@ class Postgres72 extends Postgres71 {
 
        // Administration functions
 
+       /**
+        * Vacuums a database
+        * @param $table The table to vacuum
+        * @param $analyze If true, also does analyze
+        * @param $full If true, selects "full" vacuum (PostgreSQL >= 7.2)
+        * @param $freeze If true, selects aggressive "freezing" of tuples (PostgreSQL >= 7.2)
+        */
+       function vacuumDB($table = '', $analyze = false, $full = false, $freeze = false) {
+               $sql = "VACUUM";
+               if ($full) $sql .= " FULL";
+               if ($freeze) $sql .= " FREEZE";
+               if ($analyze) $sql .= " ANALYZE";
+               if ($table != '') {
+                       $this->fieldClean($table);
+                       $sql .= " \"{$table}\"";
+               }
+
+               return $this->execute($sql);
+       }
+
        /**
         * Analyze a database
         * @note PostgreSQL 7.2 finally had an independent ANALYZE command
@@ -474,6 +494,7 @@ class Postgres72 extends Postgres71 {
        function hasPartialIndexes() { return true; }
        function hasProcesses() { return true; }
        function hasStatsCollector() { return true; }
+       function hasFullVacuum() { return true; }
 
 }
 
index e160f74948e1b1d0ecfe356e9c1c81d6cfd00ff3..5db25d42445064f468b4d8a35c1710af09d4ccae 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres73.php,v 1.107 2004/05/16 15:42:30 chriskl Exp $
+ * $Id: Postgres73.php,v 1.108 2004/05/19 01:28:34 soranzo Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -596,31 +596,6 @@ class Postgres73 extends Postgres72 {
 
                return $this->selectSet($sql);
        }
-       
-       /**
-        * Clusters an index
-        * @param $index The name of the index
-        * @param $table The table the index is on
-        * @param $analyze True to run analyze afterward, false otherwise
-        * @return 0 success
-        */
-       function clusterIndex($index, $table, $analyze) {
-               $this->fieldClean($index);
-               $this->fieldClean($table);
-
-               // We don't bother with a transaction here, as there's no point rolling
-               // back an expensive cluster if a cheap analyze fails for whatever reason
-               $sql = "CLUSTER \"{$index}\" ON \"{$table}\"";
-               $status = $this->execute($sql);
-               if ($status != 0) return $status;
-               
-               if ($analyze) {
-                       $sql = "ANALYZE \"{$table}\"";
-                       return $this->execute($sql);
-               }
-               else
-                       return $status;
-       }       
 
        /**
         * Grabs a single trigger
@@ -941,30 +916,31 @@ class Postgres73 extends Postgres72 {
        }
 
        // Constraint functions
+
        /**
-        * A function for getting all linking fields on the foreign keys based on the table names        
-        * @param $table array of table names            
-        * @return an array of linked tables and fields
+        * A function for getting all columns linked by foreign keys given a group of tables
+        * @param $tables Array of table names           
+        * @return An array of linked tables and columns
+        * @return -1 $tables isn't an array\r
         */
-        function &getLinkingKeys($arrTables) {         
-               $this->arrayClean($arrTables);
+        function &getLinkingKeys($tables) {
+               if (!is_array($tables)) return -1;
+
+               $this->arrayClean($tables);
+               $tables_list = "'" . implode("', '", $tables) . "'";
                $maxDimension = 1;
-                       
-               // Properly quote the tables    
-               $tables = "'" . implode("', '", $arrTables) . "'";
-               
-               //7.3 requires some workarounds since ANY doesn't support arrays 
+
                $sql = "
                        SELECT DISTINCT
                                array_dims(pc.conkey) AS arr_dim,
-                               pgc1.relname AS p_table 
-                       FROM 
+                               pgc1.relname AS p_table
+                       FROM
                                pg_catalog.pg_constraint AS pc,
-                               pg_catalog.pg_class AS pgc1                             
-                       WHERE 
+                               pg_catalog.pg_class AS pgc1
+                       WHERE
                                pc.contype = 'f'
                                AND (pc.conrelid = pgc1.relfilenode OR pc.confrelid = pgc1.relfilenode)
-                               AND pgc1.relname IN ($tables)                                   
+                               AND pgc1.relname IN ($tables_list)
                        ";
                
                //parse our output for find the highest dimension of foreign keys since pc.conkey is stored in an array
@@ -975,20 +951,20 @@ class Postgres73 extends Postgres72 {
                        $maxDimension = $tmpDimension > $maxDimension ? $tmpDimension : $maxDimension;
                        $rs->MoveNext();
                }
-                       
-               //we know the highest index for foreign keys thaat conkey goes up to, expand for us in an IN query                              
-               $cons_str = '( (pfield.attnum = conkey[1] AND cfield.attnum = confkey[1]) ';            
+               
+               //we know the highest index for foreign keys that conkey goes up to, expand for us in an IN query
+               $cons_str = '( (pfield.attnum = conkey[1] AND cfield.attnum = confkey[1]) ';
                for ($i = 2; $i <= $maxDimension; $i++) {
-                       $cons_str .= "OR (pfield.attnum = conkey[{$i}] AND cfield.attnum = confkey[{$i}]) ";            
+                       $cons_str .= "OR (pfield.attnum = conkey[{$i}] AND cfield.attnum = confkey[{$i}]) ";
                }
                $cons_str .= ') ';
-                       
+               
                $sql = "
-                       SELECT                                                                          
-                               pgc1.relname AS p_table,        
+                       SELECT
+                               pgc1.relname AS p_table,
                                pgc2.relname AS f_table,
                                pfield.attname AS p_field,
-                               cfield.attname AS f_field       
+                               cfield.attname AS f_field
                        FROM
                                pg_catalog.pg_constraint AS pc,
                                pg_catalog.pg_class AS pgc1,
@@ -996,19 +972,19 @@ class Postgres73 extends Postgres72 {
                                pg_catalog.pg_attribute AS pfield,
                                pg_catalog.pg_attribute AS cfield
                        WHERE
-                               pc.contype = 'f'                                
+                               pc.contype = 'f'
                                AND pc.conrelid = pgc1.relfilenode
                                AND pc.confrelid = pgc2.relfilenode
                                AND pfield.attrelid = pc.conrelid
                                AND cfield.attrelid = pc.confrelid
-                               AND $cons_str                   
-                               AND pgc1.relname IN ($tables)   
-                               AND pgc2.relname IN ($tables)
+                               AND $cons_str
+                               AND pgc1.relname IN ($tables_list)
+                               AND pgc2.relname IN ($tables_list)
                                AND pgc1.relnamespace = (SELECT oid FROM pg_catalog.pg_namespace
                                        WHERE nspname='{$this->_schema}')
                ";
                
-               return $this->selectSet($sql);                  
+               return $this->selectSet($sql);
         }
 
        /**
@@ -1670,7 +1646,7 @@ class Postgres73 extends Postgres72 {
        // Capabilities
        function hasSchemas() { return true; }
        function hasConversions() { return true; }
-       function hasCluster() { return true; }
+       function hasIsClustered() { return true; }
        function hasDropBehavior() { return true; }
        function hasDropColumn() { return true; }
        function hasDomains() { return true; }
index a9e1f9eccf70110530bae4ab0a2b32a94f4ffdea..81e6ca3eea01ca66e64ac1edc7fc29909088e7b6 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres74.php,v 1.30 2004/05/14 01:16:14 soranzo Exp $
+ * $Id: Postgres74.php,v 1.31 2004/05/19 01:28:35 soranzo Exp $
  */
 
 include_once('./classes/database/Postgres73.php');
@@ -236,7 +236,24 @@ class Postgres74 extends Postgres73 {
 
                return $this->selectSet($sql);
        }
-       
+
+       // Administration functions
+
+       /**
+        * Recluster a table or all the tables in the current database
+        * @param $table (optional) The table to recluster
+        */
+       function recluster($table = '') {
+               if ($table != '') {
+                       $this->fieldClean($table);
+                       $sql = "CLUSTER \"{$table}\"";
+               }
+               else
+                       $sql = "CLUSTER";
+
+               return $this->execute($sql);
+       }
+
        // Domain functions
        
        /**
@@ -413,6 +430,7 @@ class Postgres74 extends Postgres73 {
        function hasUserRename() { return true; }
        function hasFunctionRename() { return true; }
        function hasSchemaDump() { return true; }
+       function hasRecluster() { return true; }
        
 }
 
index 683c9648b53b6f181e9442b1fed750b15188e575..bc5b77a156c36e676b5bddc5397263f0c3fca729 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List constraints on a table
         *
-        * $Id: constraints.php,v 1.27 2004/05/09 06:21:26 chriskl Exp $
+        * $Id: constraints.php,v 1.28 2004/05/19 01:28:34 soranzo Exp $
         */
 
        // Include application functions
@@ -22,7 +22,7 @@
 
                if ($confirm) {
                        // Default analyze to on
-                       if ($action == 'confirm_cluster_constraint') $_REQUEST['analyze'] = 'on';
+                       $_REQUEST['analyze'] = true;
                        
                        echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ",
                                $misc->printVal($_REQUEST['table']), ": " , $misc->printVal($_REQUEST['constraint']), ": {$lang['strcluster']}</h2>\n";
                        echo "<p>", sprintf($lang['strconfcluster'], $misc->printVal($_REQUEST['constraint'])), "</p>\n";
 
                        echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                       echo "<p><input type=\"checkbox\" name=\"analyze\"", (isset($_REQUEST['analyze']) ? ' checked="checked"' : ''), " /> {$lang['stranalyze']}</p>\n";
                        echo "<input type=\"hidden\" name=\"action\" value=\"cluster_constraint\" />\n";
                        echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
                        echo "<input type=\"hidden\" name=\"constraint\" value=\"", htmlspecialchars($_REQUEST['constraint']), "\" />\n";
                        echo $misc->form;
-                       echo "<p><input type=\"checkbox\" name=\"analyze\"", (isset($_REQUEST['analyze']) ? ' checked="checked"' : ''), " /> {$lang['stranalyze']}</p>\n";
                        echo "<input type=\"submit\" name=\"cluster\" value=\"{$lang['strcluster']}\" />\n";
                        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
                        echo "</form>\n";
                }
                else {
-                       $status = $data->clusterIndex($_POST['constraint'], $_POST['table'], isset($_POST['analyze']));
+                       $status = $data->clusterIndex($_POST['constraint'], $_POST['table']);
                        if ($status == 0)
-                               doDefault($lang['strclusteredgood'] . ((isset($_POST['analyze']) ? ' ' . $lang['stranalyzegood'] : '')));
+                               if (isset($_POST['analyze'])) {
+                                       $status = $data->analyzeDB($_POST['table']);
+                                       if ($status == 0)
+                                               doDefault($lang['strclusteredgood'] . ' ' . $lang['stranalyzegood']);
+                                       else
+                                               doDefault($lang['stranalyzebad']);
+                               } else
+                                       doDefault($lang['strclusteredgood']);
                        else
                                doDefault($lang['strclusteredbad']);
                }
        }
 
+       function doReindex() {
+               global $data, $lang;
+
+               $status = $data->reindex('INDEX', $_REQUEST['constraint']);
+               if ($status == 0)
+                       doDefault($lang['strreindexgood']);
+               else
+                       doDefault($lang['strreindexbad']);
+       }
+
        /**
         * Confirm and then actually add a FOREIGN KEY constraint
         */
                if ($constraints->recordCount() > 0) {
                        echo "<table>\n";
                        echo "<tr><th class=\"data\">{$lang['strname']}</th><th class=\"data\">{$lang['strdefinition']}</th>\n";
-                       if ($data->hasCluster()) {
+                       if ($data->hasIsClustered()) {
                                echo "<th class=\"data\">{$lang['strclustered']}</th>";
-                               echo "<th class=\"data\" colspan=\"2\">{$lang['stractions']}</th>\n";
-                       }
-                       else {
-                               echo "<th class=\"data\">{$lang['stractions']}</th>\n";
                        }
+                       echo "<th class=\"data\" colspan=\"3\">{$lang['stractions']}</th>\n";
                        echo "</tr>\n";
                        $i = 0;
                        
                                        echo ")";
                                }
                                echo "</td>";
-                               if ($data->hasCluster()) {
-                                       if ($constraints->f['indisclustered'] !== null) {
+                               if ($data->hasIsClustered()) {
+                                       if ($constraints->f['contype'] == 'u' || $constraints->f['contype'] == 'p') {
                                                $constraints->f['indisclustered'] = $data->phpBool($constraints->f['indisclustered']);
                                                echo "<td class=\"data{$id}\">", ($constraints->f['indisclustered'] ? $lang['stryes'] : $lang['strno']), "</td>";
                                        } else {
                                                echo "<td class=\"data{$id}\"></td>";
                                        }
                                }
+                               // You can only cluster primary key and unique constraints!
+                               if ($constraints->f['contype'] == 'u' || $constraints->f['contype'] == 'p') {
+                                       echo "<td class=\"opbutton{$id}\">";
+                                       echo "<a href=\"$PHP_SELF?action=confirm_cluster_constraint&{$misc->href}&constraint=",
+                                               urlencode($constraints->f[$data->cnFields['conname']]), 
+                                               "&table=", urlencode($_REQUEST['table']), "\">{$lang['strcluster']}</a></td>";
+                                       echo "<td class=\"opbutton{$id}\">";
+                                       echo "<a href=\"$PHP_SELF?action=reindex&{$misc->href}&constraint=",
+                                               urlencode($constraints->f[$data->cnFields['conname']]),
+                                               "&table=", urlencode($_REQUEST['table']), "\">{$lang['strreindex']}</a></td>";
+                               }
+                               else {
+                                       echo "<td class=\"data{$id}\"></td>";
+                                       echo "<td class=\"data{$id}\"></td>";
+                               }
                                echo "<td class=\"opbutton{$id}\">";
                                echo "<a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&constraint=", urlencode($constraints->f[$data->cnFields['conname']]),
                                        "&table=", urlencode($_REQUEST['table']), "&type=", urlencode($constraints->f['contype']), "\">{$lang['strdrop']}</td>";
-                               if ($data->hasCluster()) {
-                                       echo "<td class=\"opbutton{$id}\">";
-                                       // You can only cluster primary key and unique constraints!
-                                       if ($constraints->f['contype'] == 'u' || $constraints->f['contype'] == 'p') {
-                                               echo "<a href=\"$PHP_SELF?action=confirm_cluster_constraint&{$misc->href}&constraint=", urlencode($constraints->f[$data->cnFields['conname']]), 
-                                                       "&table=", urlencode($_REQUEST['table']), "\">{$lang['strcluster']}</a>";
-                                       }
-                                       echo "</td>\n";
-                                               
-                               }
                                echo "</tr>\n";
 
                                $constraints->moveNext();
                case 'confirm_cluster_constraint':
                        doClusterIndex(true);
                        break;
+               case 'reindex':
+                       doReindex();
+                       break;
                case 'add_foreign_key':
                        addForeignKey(1);
                        break;
index eaee6068cce1caeefa3b45189db7be29ef9877ae..37aebb9942080077580bc7b62837e579267b662a 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Manage schemas within a database
         *
-        * $Id: database.php,v 1.42 2004/05/16 15:40:20 chriskl Exp $
+        * $Id: database.php,v 1.43 2004/05/19 01:28:34 soranzo Exp $
         */
 
        // Include application functions
                                if ($status == 0) doAdmin('', $lang['stranalyzegood']);
                                else doAdmin('', $lang['stranalyzebad']);
                                break;
-                       case 'cluster':
-                               $status = $data->analyzeDB();
+                       case 'recluster':
+                               $status = $data->recluster();
                                if ($status == 0) doAdmin('', $lang['strclusteredgood']);
-                               else doAdmin('', $lang['strclusterbad']);
+                               else doAdmin('', $lang['strclusteredbad']);
                                break;                          
                        case 'reindex';
-                               $status = $data->analyzeDB();
+                               $status = $data->reindex('DATABASE', $_REQUEST['database'], isset($_REQUEST['reindex_force']));
                                if ($status == 0) doAdmin('', $lang['strreindexgood']);
                                else doAdmin('', $lang['strreindexbad']);
                                break;
                                echo "<form name=\"adminfrm\" id=\"adminfrm\" action=\"{$PHP_SELF}\" method=\"post\">\n";
                                echo "<h3>{$lang['strvacuum']}</h3>\n";
                                echo "<input type=\"checkbox\" id=\"vacuum_analyze\" name=\"vacuum_analyze\" />{$lang['stranalyze']}<br />\n";
-                               echo "<input type=\"checkbox\" id=\"vacuum_full\" name=\"vacuum_full\" />{$lang['strfull']}<br />\n";                           
-                               echo "<input type=\"checkbox\" id=\"vacuum_freeze\" name=\"vacuum_freeze\" />{$lang['strfreeze']}<br />\n";
+                               if ($data->hasFullVacuum()) {
+                                       echo "<input type=\"checkbox\" id=\"vacuum_full\" name=\"vacuum_full\" />{$lang['strfull']}<br />\n";                           
+                                       echo "<input type=\"checkbox\" id=\"vacuum_freeze\" name=\"vacuum_freeze\" />{$lang['strfreeze']}<br />\n";
+                               }
                                echo "<input type=\"submit\" value=\"{$lang['strvacuum']}\" />\n";
                                echo "<input type=\"hidden\" name=\"action\" value=\"vacuum\" />\n";
                                echo $misc->form;
                                echo $misc->form;
                                echo "</form>\n";                                                               
                                
-                               // Cluster
-                               echo "<form name=\"adminfrm\" id=\"adminfrm\" action=\"{$PHP_SELF}\" method=\"post\">\n";
-                               echo "<h3>{$lang['strcluster']}</h3>\n";                                
-                               echo "<input type=\"submit\" value=\"{$lang['strcluster']}\" />\n";
-                               echo "<input type=\"hidden\" name=\"action\" value=\"cluster\" />\n";
-                               echo $misc->form;
-                               echo "</form>\n";                                                               
+                               // Recluster
+                               if ($data->hasRecluster()){
+                                       echo "<form name=\"adminfrm\" id=\"adminfrm\" action=\"{$PHP_SELF}\" method=\"post\">\n";
+                                       echo "<h3>{$lang['strcluster']}</h3>\n";
+                                       echo "<input type=\"submit\" value=\"{$lang['strcluster']}\" />\n";
+                                       echo "<input type=\"hidden\" name=\"action\" value=\"recluster\" />\n";
+                                       echo $misc->form;
+                                       echo "</form>\n";
+                               }
                                
                                // Reindex
                                echo "<form name=\"adminfrm\" id=\"adminfrm\" action=\"{$PHP_SELF}\" method=\"post\">\n";
                        if (isset($_GET['term'])) doFind(false);
                        else doFind(true);
                        break;
-               case 'cluster':
+               case 'recluster':
                case 'reindex':
                case 'analyze':
                case 'vacuum':
index a0de32c6ca8c38173531d25f55400a3748fa430d..e3912f03829981f6d834703e580dc741ee0e2c35 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List indexes on a table
         *
-        * $Id: indexes.php,v 1.23 2004/05/11 07:12:09 chriskl Exp $
+        * $Id: indexes.php,v 1.24 2004/05/19 01:28:34 soranzo Exp $
         */
 
        // Include application functions
@@ -22,7 +22,7 @@
 
                if ($confirm) {
                        // Default analyze to on
-                       if ($action == 'confirm_cluster_index') $_REQUEST['analyze'] = 'on';
+                       $_REQUEST['analyze'] = true;
                        
                        echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ",
                                $misc->printVal($_REQUEST['table']), ": " , $misc->printVal($_REQUEST['index']), ": {$lang['strcluster']}</h2>\n";
                        echo "<p>", sprintf($lang['strconfcluster'], $misc->printVal($_REQUEST['index'])), "</p>\n";
 
                        echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                       echo "<p><input type=\"checkbox\" name=\"analyze\"", (isset($_REQUEST['analyze']) ? ' checked="checked"' : ''), " /> {$lang['stranalyze']}</p>\n";
                        echo "<input type=\"hidden\" name=\"action\" value=\"cluster_index\" />\n";
                        echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
                        echo "<input type=\"hidden\" name=\"index\" value=\"", htmlspecialchars($_REQUEST['index']), "\" />\n";
                        echo $misc->form;
-                       echo "<p><input type=\"checkbox\" name=\"analyze\"", (isset($_REQUEST['analyze']) ? ' checked="checked"' : ''), " /> {$lang['stranalyze']}</p>\n";
                        echo "<input type=\"submit\" name=\"cluster\" value=\"{$lang['strcluster']}\" />\n";
                        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
                        echo "</form>\n";
                }
                else {
-                       $status = $data->clusterIndex($_POST['index'], $_POST['table'], isset($_POST['analyze']));
+                       $status = $data->clusterIndex($_POST['index'], $_POST['table']);
                        if ($status == 0)
-                               doDefault($lang['strclusteredgood'] . ((isset($_POST['analyze']) ? ' ' . $lang['stranalyzegood'] : '')));
+                               if (isset($_POST['analyze'])){
+                                       $status = $data->analyzeDB($_POST['table']);
+                                       if ($status == 0)
+                                               doDefault($lang['strclusteredgood'] . ' ' . $lang['stranalyzegood']);
+                                       else
+                                               doDefault($lang['stranalyzebad']);
+                               } else
+                                       doDefault($lang['strclusteredgood']);
                        else
                                doDefault($lang['strclusteredbad']);
                }
 
        }
 
+       function doReindex() {
+               global $data, $lang;
+
+               $status = $data->reindex('INDEX', $_REQUEST['index']);
+               if ($status == 0)
+                       doDefault($lang['strreindexgood']);
+               else
+                       doDefault($lang['strreindexbad']);
+       }
+
        /**
         * Displays a screen where they can enter a new index
         */
                        echo "<table>\n";
                        echo "<tr>\n";
                        echo "<th class=\"data\">{$lang['strname']}</th><th class=\"data\">{$lang['strdefinition']}</th>";
-                       if ($data->hasCluster()) {
+                       if ($data->hasIsClustered()) {
                                echo "<th class=\"data\">{$lang['strclustered']}</th>";
-                               echo "<th class=\"data\" colspan=\"2\">{$lang['stractions']}</th>\n";
-                       }
-                       else {
-                               echo "<th class=\"data\">{$lang['stractions']}</th>\n";
                        }
+                       echo "<th class=\"data\" colspan=\"3\">{$lang['stractions']}</th>\n";
                        echo "</tr>\n";
                        $i = 0;
                        
                                $id = ( ($i % 2 ) == 0 ? '1' : '2' );
                                echo "<tr><td class=\"data{$id}\">", $misc->printVal( $indexes->f[$data->ixFields['idxname']]), "</td>";
                                echo "<td class=\"data{$id}\">", $misc->printVal( $indexes->f[$data->ixFields['idxdef']]), "</td>";
-                               if ($data->hasCluster()) {
+                               if ($data->hasIsClustered()) {
                                        $indexes->f['indisclustered'] = $data->phpBool($indexes->f['indisclustered']);
                                        echo "<td class=\"data{$id}\">", ($indexes->f['indisclustered'] ? $lang['stryes'] : $lang['strno']), "</td>";
                                }
                                echo "<td class=\"opbutton{$id}\">";
+                               echo "<a href=\"$PHP_SELF?action=confirm_cluster_index&{$misc->href}&index=", urlencode( $indexes->f[$data->ixFields['idxname']]), 
+                                       "&table=", urlencode($_REQUEST['table']), "\">{$lang['strcluster']}</a></td>";
+                               echo "<td class=\"opbutton{$id}\">";
+                               echo "<a href=\"$PHP_SELF?action=reindex&{$misc->href}&index=", urlencode( $indexes->f[$data->ixFields['idxname']]), 
+                                       "&table=", urlencode($_REQUEST['table']), "\">{$lang['strreindex']}</a></td>";
+                               echo "<td class=\"opbutton{$id}\">";
                                echo "<a href=\"$PHP_SELF?action=confirm_drop_index&{$misc->href}&index=", urlencode( $indexes->f[$data->ixFields['idxname']]), 
-                                       "&table=", urlencode($_REQUEST['table']), "\">{$lang['strdrop']}</td>";
-                               if ($data->hasCluster()) {
-                                       echo "<td class=\"opbutton{$id}\">";
-                                       echo "<a href=\"$PHP_SELF?action=confirm_cluster_index&{$misc->href}&index=", urlencode( $indexes->f[$data->ixFields['idxname']]), 
-                                               "&table=", urlencode($_REQUEST['table']), "\">{$lang['strcluster']}</td>";
-                               }
+                                       "&table=", urlencode($_REQUEST['table']), "\">{$lang['strdrop']}</a></td>";
                                echo "</tr>\n";
 
                                $indexes->movenext();
                case 'confirm_cluster_index':
                        doClusterIndex(true);
                        break;
+               case 'reindex':
+                       doReindex();
+                       break;
                case 'save_create_index':
                        if (isset($_POST['cancel'])) doDefault();
                        else doSaveCreateIndex();