Welcome to mirror list, hosted at ThFree Co, Russian Federation.

InfoController.php « controllers « src - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8a66ae30ebb33f4ef230efce80d5360998854342 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<?php

/**
 * PHPPgAdmin v6.0.0-beta.50
 */

namespace PHPPgAdmin\Controller;

use PHPPgAdmin\Decorators\Decorator;

/**
 * Base controller class.
 *
 * @package PHPPgAdmin
 */
class InfoController extends BaseController
{
    public $controller_title = 'strtables';

    /**
     * Default method to render the controller according to the action parameter.
     */
    public function render()
    {
        $this->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
        $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']);
        } else {
            // Referring foreign tables
            if ($referrers !== -99 && $referrers->recordCount() > 0) {
                echo "<h3>{$this->lang['strreferringtables']}</h3>".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']);
            }

            // Parent tables
            if ($parents->recordCount() > 0) {
                echo "<h3>{$this->lang['strparenttables']}</h3>".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']);
            }

            // Child tables
            if ($children->recordCount() > 0) {
                echo "<h3>{$this->lang['strchildtables']}</h3>".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']);
            }

            // Row performance
            if ($tablestatstups->recordCount() > 0) {
                echo "<h3>{$this->lang['strrowperf']}</h3>".PHP_EOL;

                echo '<table>'.PHP_EOL;
                echo "\t<tr>".PHP_EOL;
                echo "\t\t<th class=\"data\" colspan=\"2\">{$this->lang['strsequential']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\" colspan=\"2\">{$this->lang['strindex']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\" colspan=\"3\">{$this->lang['strrows2']}</th>".PHP_EOL;
                echo "\t</tr>".PHP_EOL;
                echo "\t<tr>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strscan']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strread']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strscan']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strfetch']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strinsert']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strupdate']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strdelete']}</th>".PHP_EOL;
                echo "\t</tr>".PHP_EOL;
                $i = 0;

                while (!$tablestatstups->EOF) {
                    $id = (0 == ($i % 2) ? '1' : '2');
                    echo "\t<tr class=\"data{$id}\">".PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['seq_scan'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['seq_tup_read'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['idx_scan'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['idx_tup_fetch'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['n_tup_ins'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['n_tup_upd'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatstups->fields['n_tup_del'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t</tr>".PHP_EOL;
                    $tablestatstups->movenext();
                    ++$i;
                }

                echo '</table>'.PHP_EOL;
            }

            // I/O performance
            if ($tablestatsio->recordCount() > 0) {
                echo "<h3>{$this->lang['strioperf']}</h3>".PHP_EOL;

                echo '<table>'.PHP_EOL;
                echo "\t<tr>".PHP_EOL;
                echo "\t\t<th class=\"data\" colspan=\"3\">{$this->lang['strheap']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\" colspan=\"3\">{$this->lang['strindex']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\" colspan=\"3\">{$this->lang['strtoast']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\" colspan=\"3\">{$this->lang['strtoastindex']}</th>".PHP_EOL;
                echo "\t</tr>".PHP_EOL;
                echo "\t<tr>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strdisk']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strcache']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strpercent']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strdisk']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strcache']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strpercent']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strdisk']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strcache']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strpercent']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strdisk']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strcache']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strpercent']}</th>".PHP_EOL;
                echo "\t</tr>".PHP_EOL;
                $i = 0;

                while (!$tablestatsio->EOF) {
                    $id = (0 == ($i % 2) ? '1' : '2');
                    echo "\t<tr class=\"data{$id}\">".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<td>", $this->misc->printVal($tablestatsio->fields['heap_blks_read'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['heap_blks_hit'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>({$percentage}{$this->lang['strpercent']})</td>".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<td>", $this->misc->printVal($tablestatsio->fields['idx_blks_read'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['idx_blks_hit'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>({$percentage}{$this->lang['strpercent']})</td>".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<td>", $this->misc->printVal($tablestatsio->fields['toast_blks_read'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['toast_blks_hit'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>({$percentage}{$this->lang['strpercent']})</td>".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<td>", $this->misc->printVal($tablestatsio->fields['tidx_blks_read'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($tablestatsio->fields['tidx_blks_hit'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>({$percentage}{$this->lang['strpercent']})</td>".PHP_EOL;
                    echo "\t</tr>".PHP_EOL;
                    $tablestatsio->movenext();
                    ++$i;
                }

                echo '</table>'.PHP_EOL;
            }

            // Index row performance
            if ($indexstatstups->recordCount() > 0) {
                echo "<h3>{$this->lang['stridxrowperf']}</h3>".PHP_EOL;

                echo '<table>'.PHP_EOL;
                echo "\t<tr>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strindex']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strscan']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strread']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strfetch']}</th>".PHP_EOL;
                echo "\t</tr>".PHP_EOL;
                $i = 0;

                while (!$indexstatstups->EOF) {
                    $id = (0 == ($i % 2) ? '1' : '2');
                    echo "\t<tr class=\"data{$id}\">".PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['indexrelname']), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['idx_scan'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['idx_tup_read'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($indexstatstups->fields['idx_tup_fetch'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t</tr>".PHP_EOL;
                    $indexstatstups->movenext();
                    ++$i;
                }

                echo '</table>'.PHP_EOL;
            }

            // Index I/0 performance
            if ($indexstatsio->recordCount() > 0) {
                echo "<h3>{$this->lang['stridxioperf']}</h3>".PHP_EOL;

                echo '<table>'.PHP_EOL;
                echo "\t<tr>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strindex']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strdisk']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strcache']}</th>".PHP_EOL;
                echo "\t\t<th class=\"data\">{$this->lang['strpercent']}</th>".PHP_EOL;
                echo "\t</tr>".PHP_EOL;
                $i = 0;

                while (!$indexstatsio->EOF) {
                    $id = (0 == ($i % 2) ? '1' : '2');
                    echo "\t<tr class=\"data{$id}\">".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<td>", $this->misc->printVal($indexstatsio->fields['indexrelname']), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($indexstatsio->fields['idx_blks_read'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>", $this->misc->printVal($indexstatsio->fields['idx_blks_hit'], 'int4', $shownull), '</td>'.PHP_EOL;
                    echo "\t\t<td>({$percentage}{$this->lang['strpercent']})</td>".PHP_EOL;
                    echo "\t</tr>".PHP_EOL;
                    $indexstatsio->movenext();
                    ++$i;
                }

                echo '</table>'.PHP_EOL;
            }
        }
    }
}