Permalink
Browse files

Fix cluster action on the admin page

  • Loading branch information...
1 parent 674b6ec commit 12d0b94703b1284bc14b19c21c30ac2bace6b8c8 @ioguix ioguix committed Apr 11, 2010
Showing with 179 additions and 32 deletions.
  1. +103 −6 admin.php
  2. +43 −7 classes/database/Postgres.php
  3. +17 −6 classes/database/Postgres82.php
  4. +1 −1 indexes.php
  5. +7 −6 lang/english.php
  6. +7 −6 lang/recoded/english.php
  7. +1 −0 tables.php
View
109 admin.php
@@ -3,6 +3,89 @@
$script = ''; // init global value script
/**
+ * Show confirmation of cluster and perform cluster
+ */
+ function doCluster($type, $confirm=false) {
+ global $script, $data, $misc, $lang;
+
+ if (($type == 'table') && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) {
+ doDefault($lang['strspecifytabletocluster']);
+ return;
+ }
+
+ if ($confirm) {
+ if (isset($_REQUEST['ma'])) {
+ $misc->printTrail('schema');
+ $misc->printTitle($lang['strclusterindex'], 'pg.cluster');
+
+ echo "<form action=\"{$script}\" method=\"post\">\n";
+ foreach($_REQUEST['ma'] as $v) {
+ $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
+ echo "<p>", sprintf($lang['strconfclustertable'], $misc->printVal($a['table'])), "</p>\n";
+ echo "<input type=\"hidden\" name=\"table[]\" value=\"", htmlspecialchars($a['table']), "\" />\n";
+ }
+ } // END if multi cluster
+ else {
+ $misc->printTrail($type);
+ $misc->printTitle($lang['strclusterindex'], 'pg.cluster');
+
+ echo "<form action=\"{$script}\" method=\"post\">\n";
+
+ if ($type == 'table') {
+ echo "<p>", sprintf($lang['strconfclustertable'], $misc->printVal($_REQUEST['object'])), "</p>\n";
+ echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['object']), "\" />\n";
+ }
+ else {
+ echo "<p>", sprintf($lang['strconfclusterdatabase'], $misc->printVal($_REQUEST['object'])), "</p>\n";
+ echo "<input type=\"hidden\" name=\"table\" value=\"\" />\n";
+ }
+ }
+ echo "<input type=\"hidden\" name=\"action\" value=\"cluster\" />\n";
+
+ echo $misc->form;
+
+ echo "<input type=\"submit\" name=\"cluster\" value=\"{$lang['strcluster']}\" />\n"; //TODO
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
+ echo "</form>\n";
+ } // END single cluster
+ else {
+ //If multi table cluster
+ if ($type == 'table') { // cluster one or more table
+ if (is_array($_REQUEST['table'])) {
+ $msg='';
+ foreach($_REQUEST['table'] as $o) {
+ $status = $data->clusterIndex($o);
+ if ($status == 0)
+ $msg.= sprintf('%s: %s<br />', htmlentities($o), $lang['strclusteredgood']);
+ else {
+ doDefault($type, sprintf('%s%s: %s<br />', $msg, htmlentities($o), $lang['strclusteredbad']));
+ return;
+ }
+ }
+ // Everything went fine, back to the Default page....
+ doDefault($msg);
+ }
+ else {
+ $status = $data->clusterIndex($_REQUEST['object']);
+ if ($status == 0) {
+ doAdmin($type, $lang['strclusteredgood']);
+ }
+ else
+ doAdmin($type, $lang['strclusteredbad']);
+ }
+ }
+ else { // Cluster all tables in database
+ $status = $data->clusterIndex();
+ if ($status == 0) {
+ doAdmin($type, $lang['strclusteredgood']);
+ }
+ else
+ doAdmin($type, $lang['strclusteredbad']);
+ }
+ }
+ }
+
+ /**
* Show confirmation of reindex and perform reindex
*/
function doReindex($type, $confirm=false) {
@@ -437,17 +520,24 @@ function doAdmin($type, $msg = '') {
echo "</form>\n";
echo "</td>\n";
- // Recluster
+ // Cluster
if ($data->hasRecluster()){
echo "<td class=\"data1\" style=\"text-align: center; vertical-align: bottom\">\n";
echo "<form action=\"{$script}\" method=\"post\">\n";
- echo "<p><input type=\"hidden\" name=\"action\" value=\"recluster\" />\n";
echo $misc->form;
if ($type == 'table') {
- echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($table), "\" />\n";
+ echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['object']), "\" />\n";
echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n";
+ if ($data->alreadyClustered($_REQUEST['object'])) {
+ $disabled = '';
+ }
+ else {
+ $disabled = 'disabled="disabled" ';
+ echo "{$lang['strnoclusteravailable']}<br />";
+ }
}
- echo "<input type=\"submit\" value=\"{$lang['strclusterindex']}\" /></p>\n";
+ echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_cluster\" />\n";
+ echo "<input type=\"submit\" value=\"{$lang['strclusterindex']}\" $disabled/></p>\n";
echo "</form>\n";
echo "</td>\n";
}
@@ -581,7 +671,9 @@ function adminActions($action, $type) {
}
switch ($action) {
- //case 'confirm_recluster':
+ case 'confirm_cluster':
+ doCluster($type, true);
+ break;
case 'confirm_reindex':
doReindex($type, true);
break;
@@ -591,7 +683,12 @@ function adminActions($action, $type) {
case 'confirm_vacuum':
doVacuum($type, true);
break;
- //case 'recluster':
+ case 'cluster':
+ if (isset($_POST['cluster'])) doCluster($type);
+ // if multi-action from table canceled: back to the schema default page
+ else if (($type == 'table') && is_array($_REQUEST['object']) ) doDefault();
+ else doAdmin($type);
+ break;
case 'reindex':
if (isset($_POST['reindex'])) doReindex($type);
// if multi-action from table canceled: back to the schema default page
@@ -3253,6 +3253,34 @@ function getIndexes($table = '', $unique = false) {
return $this->selectSet($sql);
}
+ /**
+ * test if a table has been clustered on an index
+ * @param $table The table to test
+ *
+ * @return true if the table has been already clustered
+ */
+ function alreadyClustered($table) {
+
+ $c_schema = $this->_schema;
+ $this->clean($c_schema);
+ $this->clean($table);
+
+ $sql = "SELECT i.indisclustered
+ FROM pg_catalog.pg_class c, pg_catalog.pg_index i
+ WHERE c.relname = '{$table}'
+ AND c.oid = i.indrelid AND i.indisclustered
+ AND c.relnamespace = (SELECT oid FROM pg_catalog.pg_namespace
+ WHERE nspname='{$c_schema}')
+ ";
+
+ $v = $this->selectSet($sql);
+
+ if ($v->recordCount() == 0)
+ return false;
+
+ return true;
+ }
+
/**
* Creates an index
* @param $name The index name
@@ -3348,16 +3376,24 @@ function reindex($type, $name, $force = false) {
* @param $table The table the index is on
* @return 0 success
*/
- function clusterIndex($index, $table) {
-
- $f_schema = $this->_schema;
- $this->fieldClean($f_schema);
- $this->fieldClean($index);
- $this->fieldClean($table);
+ function clusterIndex($table='', $index='') {
+
+ $sql = 'CLUSTER';
// 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 \"{$f_schema}\".\"{$table}\" USING \"{$index}\"";
+
+ if (!empty($table)) {
+ $f_schema = $this->_schema;
+ $this->fieldClean($f_schema);
+ $this->fieldClean($table);
+ $sql .= " \"{$f_schema}\".\"{$table}\"";
+
+ if (!empty($index)) {
+ $this->fieldClean($index);
+ $sql .= " USING \"{$index}\"";
+ }
+ }
return $this->execute($sql);
}
@@ -256,15 +256,26 @@ function createFunction($funcname, $args, $returns, $definition, $language, $fla
* @param $table The table the index is on
* @return 0 success
*/
- function clusterIndex($index, $table) {
- $f_schema = $this->_schema;
- $this->fieldClean($f_schema);
- $this->fieldClean($index);
- $this->fieldClean($table);
+ function clusterIndex($table='', $index='') {
+ $sql = 'CLUSTER';
+
// 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 \"{$f_schema}\".\"{$table}\"";
+
+ if (!empty($table)) {
+ $f_schema = $this->_schema;
+ $this->fieldClean($f_schema);
+ $this->fieldClean($table);
+
+ if (!empty($index)) {
+ $this->fieldClean($index);
+ $sql .= " \"{$index}\" ON \"{$f_schema}\".\"{$table}\"";
+ }
+ else {
+ $sql .= " \"{$f_schema}\".\"{$table}\"";
+ }
+ }
return $this->execute($sql);
}
View
@@ -39,7 +39,7 @@ function doClusterIndex($confirm) {
echo "</form>\n";
}
else {
- $status = $data->clusterIndex($_POST['index'], $_POST['table']);
+ $status = $data->clusterIndex($_POST['table'], $_POST['index']);
if ($status == 0)
if (isset($_POST['analyze'])){
$status = $data->analyzeDB($_POST['table']);
View
@@ -158,11 +158,6 @@
$lang['strconfdelhistory'] = 'Really remove this request from history?';
$lang['strconfclearhistory'] = 'Really clear history?';
$lang['strnodatabaseselected'] = 'Please, select a database.';
-
- // Database
- $lang['strconfanalyzedatabase'] = 'Are you sure you want to analyze all tables in database "%s"?';
- $lang['strconfvacuumdatabase'] = 'Are you sure you want to vacuum all tables in database "%s"?';
- $lang['strconfreindexdatabase'] = 'Are you sure you want to reindex all tables in database "%s"?';
// Database sizes
$lang['strnoaccess'] = 'No Access';
@@ -262,12 +257,14 @@
$lang['strconfvacuumtable'] = 'Are you sure you want to vacuum "%s"?';
$lang['strconfanalyzetable'] = 'Are you sure you want to analyze "%s"?';
$lang['strconfreindextable'] = 'Are you sure you want to reindex "%s"?';
+ $lang['strconfclustertable'] = 'Are you sure you want to cluster "%s"?';
$lang['strestimatedrowcount'] = 'Estimated row count';
$lang['strspecifytabletoanalyze'] = 'You must specify at least one table to analyze.';
$lang['strspecifytabletoempty'] = 'You must specify at least one table to empty.';
$lang['strspecifytabletodrop'] = 'You must specify at least one table to drop.';
$lang['strspecifytabletovacuum'] = 'You must specify at least one table to vacuum.';
$lang['strspecifytabletoreindex'] = 'You must specify at least one table to reindex.';
+ $lang['strspecifytabletocluster'] = 'You must specify at least one table to cluster.';
$lang['strnofieldsforinsert'] = 'You cannot insert a row into a table with no column.';
// Columns
@@ -390,6 +387,10 @@
$lang['strdatabasealteredbad'] = 'Database alter failed.';
$lang['strspecifydatabasetodrop'] = 'You must specify at least one database to drop.';
$lang['strtemplatedb'] = 'Template';
+ $lang['strconfanalyzedatabase'] = 'Are you sure you want to analyze all tables in database "%s"?';
+ $lang['strconfvacuumdatabase'] = 'Are you sure you want to vacuum all tables in database "%s"?';
+ $lang['strconfreindexdatabase'] = 'Are you sure you want to reindex all tables in database "%s"?';
+ $lang['strconfclusterdatabase'] = 'Are you sure you want to cluster all tables in database "%s"?';
// Views
$lang['strview'] = 'View';
@@ -476,10 +477,10 @@
$lang['strindextype'] = 'Type of index';
$lang['strtablecolumnlist'] = 'Columns in table';
$lang['strindexcolumnlist'] = 'Columns in index';
- $lang['strconfcluster'] = 'Are you sure you want to cluster "%s"?';
$lang['strclusteredgood'] = 'Cluster complete.';
$lang['strclusteredbad'] = 'Cluster failed.';
$lang['strconcurrently'] = 'Concurrently';
+ $lang['strnoclusteravailable'] = 'Table not clustered on an index.';
// Rules
$lang['strrules'] = 'Rules';
View
@@ -158,11 +158,6 @@
$lang['strconfdelhistory'] = 'Really remove this request from history?';
$lang['strconfclearhistory'] = 'Really clear history?';
$lang['strnodatabaseselected'] = 'Please, select a database.';
-
- // Database
- $lang['strconfanalyzedatabase'] = 'Are you sure you want to analyze all tables in database &quot;%s&quot;?';
- $lang['strconfvacuumdatabase'] = 'Are you sure you want to vacuum all tables in database &quot;%s&quot;?';
- $lang['strconfreindexdatabase'] = 'Are you sure you want to reindex all tables in database &quot;%s&quot;?';
// Database sizes
$lang['strnoaccess'] = 'No Access';
@@ -262,12 +257,14 @@
$lang['strconfvacuumtable'] = 'Are you sure you want to vacuum &quot;%s&quot;?';
$lang['strconfanalyzetable'] = 'Are you sure you want to analyze &quot;%s&quot;?';
$lang['strconfreindextable'] = 'Are you sure you want to reindex &quot;%s&quot;?';
+ $lang['strconfclustertable'] = 'Are you sure you want to cluster &quot;%s&quot;?';
$lang['strestimatedrowcount'] = 'Estimated row count';
$lang['strspecifytabletoanalyze'] = 'You must specify at least one table to analyze.';
$lang['strspecifytabletoempty'] = 'You must specify at least one table to empty.';
$lang['strspecifytabletodrop'] = 'You must specify at least one table to drop.';
$lang['strspecifytabletovacuum'] = 'You must specify at least one table to vacuum.';
$lang['strspecifytabletoreindex'] = 'You must specify at least one table to reindex.';
+ $lang['strspecifytabletocluster'] = 'You must specify at least one table to cluster.';
$lang['strnofieldsforinsert'] = 'You cannot insert a row into a table with no column.';
// Columns
@@ -390,6 +387,10 @@
$lang['strdatabasealteredbad'] = 'Database alter failed.';
$lang['strspecifydatabasetodrop'] = 'You must specify at least one database to drop.';
$lang['strtemplatedb'] = 'Template';
+ $lang['strconfanalyzedatabase'] = 'Are you sure you want to analyze all tables in database &quot;%s&quot;?';
+ $lang['strconfvacuumdatabase'] = 'Are you sure you want to vacuum all tables in database &quot;%s&quot;?';
+ $lang['strconfreindexdatabase'] = 'Are you sure you want to reindex all tables in database &quot;%s&quot;?';
+ $lang['strconfclusterdatabase'] = 'Are you sure you want to cluster all tables in database &quot;%s&quot;?';
// Views
$lang['strview'] = 'View';
@@ -476,10 +477,10 @@
$lang['strindextype'] = 'Type of index';
$lang['strtablecolumnlist'] = 'Columns in table';
$lang['strindexcolumnlist'] = 'Columns in index';
- $lang['strconfcluster'] = 'Are you sure you want to cluster &quot;%s&quot;?';
$lang['strclusteredgood'] = 'Cluster complete.';
$lang['strclusteredbad'] = 'Cluster failed.';
$lang['strconcurrently'] = 'Concurrently';
+ $lang['strnoclusteravailable'] = 'Table not clustered on an index.';
// Rules
$lang['strrules'] = 'Rules';
View
@@ -886,6 +886,7 @@ function doDefault($msg = '') {
'vars' => array('table' => 'relname'),
'multiaction' => 'confirm_reindex',
),
+ //'cluster' TODO ?
);
if (!$data->hasTablespaces()) unset($columns['tablespace']);

0 comments on commit 12d0b94

Please sign in to comment.