summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume (ioguix) de Rorthais2010-04-11 21:56:58 +0000
committerGuillaume (ioguix) de Rorthais2010-04-11 21:56:58 +0000
commit12d0b94703b1284bc14b19c21c30ac2bace6b8c8 (patch)
treef5877cd35351e9f0cdbfeaf33acc2549f5ff8a0f
parent674b6ec6df7f6e5e1fa1fcd10a36f8f2f1d4c2e4 (diff)
Fix cluster action on the admin page
-rw-r--r--admin.php109
-rwxr-xr-xclasses/database/Postgres.php50
-rw-r--r--classes/database/Postgres82.php23
-rw-r--r--indexes.php2
-rw-r--r--lang/english.php13
-rw-r--r--lang/recoded/english.php13
-rw-r--r--tables.php1
7 files changed, 179 insertions, 32 deletions
diff --git a/admin.php b/admin.php
index 60f546f5..dcd94954 100644
--- a/admin.php
+++ b/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 @@
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 @@
}
switch ($action) {
- //case 'confirm_recluster':
+ case 'confirm_cluster':
+ doCluster($type, true);
+ break;
case 'confirm_reindex':
doReindex($type, true);
break;
@@ -591,7 +683,12 @@
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
diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php
index 817bc511..72ac39bf 100755
--- a/classes/database/Postgres.php
+++ b/classes/database/Postgres.php
@@ -3253,6 +3253,34 @@ class Postgres extends ADODB_base {
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 @@ class Postgres extends ADODB_base {
* @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);
}
diff --git a/classes/database/Postgres82.php b/classes/database/Postgres82.php
index 346eace6..a014f8be 100644
--- a/classes/database/Postgres82.php
+++ b/classes/database/Postgres82.php
@@ -256,15 +256,26 @@ class Postgres82 extends Postgres83 {
* @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);
}
diff --git a/indexes.php b/indexes.php
index 0d57d39e..23682a21 100644
--- a/indexes.php
+++ b/indexes.php
@@ -39,7 +39,7 @@
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']);
diff --git a/lang/english.php b/lang/english.php
index 76b268ad..2683e48c 100644
--- a/lang/english.php
+++ b/lang/english.php
@@ -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';
diff --git a/lang/recoded/english.php b/lang/recoded/english.php
index b8f66915..173fb1e1 100644
--- a/lang/recoded/english.php
+++ b/lang/recoded/english.php
@@ -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';
diff --git a/tables.php b/tables.php
index ff6493ec..48b38dad 100644
--- a/tables.php
+++ b/tables.php
@@ -886,6 +886,7 @@
'vars' => array('table' => 'relname'),
'multiaction' => 'confirm_reindex',
),
+ //'cluster' TODO ?
);
if (!$data->hasTablespaces()) unset($columns['tablespace']);