printHeader($this->headerTitle('', '', $_REQUEST['table'].' - '.$this->lang['strinfo'])); $this->printBody(); switch ($this->action) { default: $this->doDefault(); break; } $this->printFooter(); } /** * List all the information on the table. * * @param string $msg * * @return string|void */ public function doDefault($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('table'); $this->printTabs('table', 'info'); $this->printMsg($msg); // common params for printVal $this->shownull = ['null' => true]; // Fetch info $referrers = $data->getReferrers($_REQUEST['table']); $parents = $data->getTableParents($_REQUEST['table']); $children = $data->getTableChildren($_REQUEST['table']); $tablestatstups = $data->getStatsTableTuples($_REQUEST['table']); $tablestatsio = $data->getStatsTableIO($_REQUEST['table']); $indexstatstups = $data->getStatsIndexTuples($_REQUEST['table']); $indexstatsio = $data->getStatsIndexIO($_REQUEST['table']); // Check that there is some info if (($referrers === -99 || ($referrers !== -99 && 0 == $referrers->recordCount())) && 0 == $parents->recordCount() && 0 == $children->recordCount() && (0 == $tablestatstups->recordCount() && 0 == $tablestatsio->recordCount() && 0 == $indexstatstups->recordCount() && 0 == $indexstatsio->recordCount())) { $this->printMsg($this->lang['strnoinfo']); return; } // Referring foreign tables if ($referrers !== -99 && $referrers->recordCount() > 0) { $this->_printReferring($referrers); } // Parent tables if ($parents->recordCount() > 0) { $this->_printParents($parents); } // Child tables if ($children->recordCount() > 0) { $this->_printChildren($children); } // Row performance if ($tablestatstups->recordCount() > 0) { $this->_printTablestatstups($tablestatstups); } // I/O performance if ($tablestatsio->recordCount() > 0) { $this->_printTablestatsio($tablestatsio); } // Index row performance if ($indexstatstups->recordCount() > 0) { $this->_printIndexstatstups($indexstatstups); } // Index I/0 performance if ($indexstatsio->recordCount() > 0) { $this->_printIndexstatsio($indexstatsio); } } private function _printChildren($children) { echo "

{$this->lang['strchildtables']}

".PHP_EOL; $columns = [ 'schema' => [ 'title' => $this->lang['strschema'], 'field' => Decorator::field('nspname'), ], 'table' => [ 'title' => $this->lang['strtable'], 'field' => Decorator::field('relname'), ], 'actions' => [ 'title' => $this->lang['stractions'], ], ]; $actions = [ 'properties' => [ 'content' => $this->lang['strproperties'], 'attr' => [ 'href' => [ 'url' => 'tblproperties', 'urlvars' => [ 'schema' => Decorator::field('nspname'), 'table' => Decorator::field('relname'), ], ], ], ], ]; echo $this->printTable($children, $columns, $actions, 'info-children', $this->lang['strnodata']); } private function _printTablestatstups($tablestatstups) { echo "

{$this->lang['strrowperf']}

".PHP_EOL; echo ''.PHP_EOL; echo "\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t".PHP_EOL; echo "\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t".PHP_EOL; $i = 0; while (!$tablestatstups->EOF) { $id = (0 == ($i % 2) ? '1' : '2'); echo "\t".PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t".PHP_EOL; $tablestatstups->movenext(); ++$i; } echo '
{$this->lang['strsequential']}{$this->lang['strindex']}{$this->lang['strrows2']}
{$this->lang['strscan']}{$this->lang['strread']}{$this->lang['strscan']}{$this->lang['strfetch']}{$this->lang['strinsert']}{$this->lang['strupdate']}{$this->lang['strdelete']}
", $this->misc->printVal($tablestatstups->fields['seq_scan'], 'int4', $this->shownull), '", $this->misc->printVal($tablestatstups->fields['seq_tup_read'], 'int4', $this->shownull), '", $this->misc->printVal($tablestatstups->fields['idx_scan'], 'int4', $this->shownull), '", $this->misc->printVal($tablestatstups->fields['idx_tup_fetch'], 'int4', $this->shownull), '", $this->misc->printVal($tablestatstups->fields['n_tup_ins'], 'int4', $this->shownull), '", $this->misc->printVal($tablestatstups->fields['n_tup_upd'], 'int4', $this->shownull), '", $this->misc->printVal($tablestatstups->fields['n_tup_del'], 'int4', $this->shownull), '
'.PHP_EOL; } private function _printTablestatsio($tablestatsio) { echo "

{$this->lang['strioperf']}

".PHP_EOL; echo ''.PHP_EOL; echo "\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t".PHP_EOL; echo "\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t".PHP_EOL; $i = 0; while (!$tablestatsio->EOF) { $id = (0 == ($i % 2) ? '1' : '2'); echo "\t".PHP_EOL; $total = $tablestatsio->fields['heap_blks_hit'] + $tablestatsio->fields['heap_blks_read']; if ($total > 0) { $percentage = round(($tablestatsio->fields['heap_blks_hit'] / $total) * 100); } else { $percentage = 0; } echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t".PHP_EOL; $total = $tablestatsio->fields['idx_blks_hit'] + $tablestatsio->fields['idx_blks_read']; if ($total > 0) { $percentage = round(($tablestatsio->fields['idx_blks_hit'] / $total) * 100); } else { $percentage = 0; } echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t".PHP_EOL; $total = $tablestatsio->fields['toast_blks_hit'] + $tablestatsio->fields['toast_blks_read']; if ($total > 0) { $percentage = round(($tablestatsio->fields['toast_blks_hit'] / $total) * 100); } else { $percentage = 0; } echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t".PHP_EOL; $total = $tablestatsio->fields['tidx_blks_hit'] + $tablestatsio->fields['tidx_blks_read']; if ($total > 0) { $percentage = round(($tablestatsio->fields['tidx_blks_hit'] / $total) * 100); } else { $percentage = 0; } echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t".PHP_EOL; echo "\t".PHP_EOL; $tablestatsio->movenext(); ++$i; } echo '
{$this->lang['strheap']}{$this->lang['strindex']}{$this->lang['strtoast']}{$this->lang['strtoastindex']}
{$this->lang['strdisk']}{$this->lang['strcache']}{$this->lang['strpercent']}{$this->lang['strdisk']}{$this->lang['strcache']}{$this->lang['strpercent']}{$this->lang['strdisk']}{$this->lang['strcache']}{$this->lang['strpercent']}{$this->lang['strdisk']}{$this->lang['strcache']}{$this->lang['strpercent']}
", $this->misc->printVal($tablestatsio->fields['heap_blks_read'], 'int4', $this->shownull), '", $this->misc->printVal($tablestatsio->fields['heap_blks_hit'], 'int4', $this->shownull), '({$percentage}{$this->lang['strpercent']})", $this->misc->printVal($tablestatsio->fields['idx_blks_read'], 'int4', $this->shownull), '", $this->misc->printVal($tablestatsio->fields['idx_blks_hit'], 'int4', $this->shownull), '({$percentage}{$this->lang['strpercent']})", $this->misc->printVal($tablestatsio->fields['toast_blks_read'], 'int4', $this->shownull), '", $this->misc->printVal($tablestatsio->fields['toast_blks_hit'], 'int4', $this->shownull), '({$percentage}{$this->lang['strpercent']})", $this->misc->printVal($tablestatsio->fields['tidx_blks_read'], 'int4', $this->shownull), '", $this->misc->printVal($tablestatsio->fields['tidx_blks_hit'], 'int4', $this->shownull), '({$percentage}{$this->lang['strpercent']})
'.PHP_EOL; } private function _printIndexstatstups($indexstatstups) { echo "

{$this->lang['stridxrowperf']}

".PHP_EOL; echo ''.PHP_EOL; echo "\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t".PHP_EOL; $i = 0; while (!$indexstatstups->EOF) { $id = (0 == ($i % 2) ? '1' : '2'); echo "\t".PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t".PHP_EOL; $indexstatstups->movenext(); ++$i; } echo '
{$this->lang['strindex']}{$this->lang['strscan']}{$this->lang['strread']}{$this->lang['strfetch']}
", $this->misc->printVal($indexstatstups->fields['indexrelname']), '", $this->misc->printVal($indexstatstups->fields['idx_scan'], 'int4', $this->shownull), '", $this->misc->printVal($indexstatstups->fields['idx_tup_read'], 'int4', $this->shownull), '", $this->misc->printVal($indexstatstups->fields['idx_tup_fetch'], 'int4', $this->shownull), '
'.PHP_EOL; } private function _printIndexstatsio($indexstatsio) { echo "

{$this->lang['stridxioperf']}

".PHP_EOL; echo ''.PHP_EOL; echo "\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t\t".PHP_EOL; echo "\t".PHP_EOL; $i = 0; while (!$indexstatsio->EOF) { $id = (0 == ($i % 2) ? '1' : '2'); echo "\t".PHP_EOL; $total = $indexstatsio->fields['idx_blks_hit'] + $indexstatsio->fields['idx_blks_read']; if ($total > 0) { $percentage = round(($indexstatsio->fields['idx_blks_hit'] / $total) * 100); } else { $percentage = 0; } echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t".PHP_EOL; echo "\t".PHP_EOL; $indexstatsio->movenext(); ++$i; } echo '
{$this->lang['strindex']}{$this->lang['strdisk']}{$this->lang['strcache']}{$this->lang['strpercent']}
", $this->misc->printVal($indexstatsio->fields['indexrelname']), '", $this->misc->printVal($indexstatsio->fields['idx_blks_read'], 'int4', $this->shownull), '", $this->misc->printVal($indexstatsio->fields['idx_blks_hit'], 'int4', $this->shownull), '({$percentage}{$this->lang['strpercent']})
'.PHP_EOL; } private function _printParents($parents) { echo "

{$this->lang['strparenttables']}

".PHP_EOL; $columns = [ 'schema' => [ 'title' => $this->lang['strschema'], 'field' => Decorator::field('nspname'), ], 'table' => [ 'title' => $this->lang['strtable'], 'field' => Decorator::field('relname'), ], 'actions' => [ 'title' => $this->lang['stractions'], ], ]; $actions = [ 'properties' => [ 'content' => $this->lang['strproperties'], 'attr' => [ 'href' => [ 'url' => 'tblproperties', 'urlvars' => [ 'schema' => Decorator::field('nspname'), 'table' => Decorator::field('relname'), ], ], ], ], ]; echo $this->printTable($parents, $columns, $actions, 'info-parents', $this->lang['strnodata']); } private function _printReferring($referrers) { echo "

{$this->lang['strreferringtables']}

".PHP_EOL; $columns = [ 'schema' => [ 'title' => $this->lang['strschema'], 'field' => Decorator::field('nspname'), ], 'table' => [ 'title' => $this->lang['strtable'], 'field' => Decorator::field('relname'), ], 'name' => [ 'title' => $this->lang['strname'], 'field' => Decorator::field('conname'), ], 'definition' => [ 'title' => $this->lang['strdefinition'], 'field' => Decorator::field('consrc'), ], 'actions' => [ 'title' => $this->lang['stractions'], ], ]; $actions = [ 'properties' => [ 'content' => $this->lang['strproperties'], 'attr' => [ 'href' => [ 'url' => 'constraints', 'urlvars' => [ 'schema' => Decorator::field('nspname'), 'table' => Decorator::field('relname'), ], ], ], ], ]; echo $this->printTable($referrers, $columns, $actions, 'info-referrers', $this->lang['strnodata']); } }