Projekt

Obecné

Profil

Stáhnout (13.7 KB) Statistiky
| Větev: | Tag: | Revize:
1
<?php
2

    
3
	/**
4
	 * List extra information on a table
5
	 *
6
	 * $Id: info.php,v 1.11 2005/10/18 03:45:16 chriskl Exp $
7
	 */
8

    
9
	// Include application functions
10
	include_once('./libraries/lib.inc.php');
11

    
12
	$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
13
	$PHP_SELF = $_SERVER['PHP_SELF'];
14

    
15
	/**
16
	 * List all the information on the table
17
	 */
18
	function doDefault($msg = '') {
19
		global $data, $misc;
20
		global $lang;
21

    
22
		$misc->printTrail('table');
23
		$misc->printTabs('table','info');
24
		$misc->printMsg($msg);
25

    
26
		// common params for printVal
27
		$shownull = array('null' => true);
28

    
29
		// Fetch info
30
		$referrers = $data->getReferrers($_REQUEST['table']);
31
		$parents = $data->getTableParents($_REQUEST['table']);
32
		$children = $data->getTableChildren($_REQUEST['table']);
33
		if ($data->hasStatsCollector()) {
34
    		$tablestatstups = $data->getStatsTableTuples($_REQUEST['table']);
35
    		$tablestatsio = $data->getStatsTableIO($_REQUEST['table']);
36
    		$indexstatstups = $data->getStatsIndexTuples($_REQUEST['table']);
37
    		$indexstatsio = $data->getStatsIndexIO($_REQUEST['table']);
38
        }
39
        
40
		// Check that there is some info
41
		if (($referrers === -99 || ($referrers !== -99 && $referrers->recordCount() == 0)) 
42
				&& $parents->recordCount() == 0 && $children->recordCount() == 0
43
				&& (!$data->hasStatsCollector()	||
44
				($tablestatstups->recordCount() == 0 && $tablestatsio->recordCount() == 0
45
				&& $indexstatstups->recordCount() == 0 && $indexstatsio->recordCount() == 0))) {
46
			$misc->printMsg($lang['strnoinfo']);
47
		}
48
		else {
49
			// Referring foreign tables
50
			if ($referrers !== -99 && $referrers->recordCount() > 0) {
51
				echo "<h3>{$lang['strreferringtables']}</h3>\n";
52
				echo "<table>\n";
53
				echo "\t<tr>\n\t\t";
54
				if ($data->hasSchemas()) {
55
					echo "<th class=\"data\">{$lang['strschema']}</th>";
56
				}
57
				echo "<th class=\"data\">{$lang['strtable']}</th>";
58
				echo "<th class=\"data\">{$lang['strname']}</th><th class=\"data\">{$lang['strdefinition']}</th>";
59
				echo "<th class=\"data\">{$lang['stractions']}</th>\n";
60
				echo "\t</tr>\n";
61
				$i = 0;
62
				
63
				while (!$referrers->EOF) {
64
					$id = ( ($i % 2 ) == 0 ? '1' : '2' );
65
					echo "\t<tr>\n\t\t";
66
					if ($data->hasSchemas()) {
67
						echo "<td class=\"data{$id}\">", $misc->printVal($referrers->f['nspname']), "</td>";
68
					}
69
					echo "<td class=\"data{$id}\">", $misc->printVal($referrers->f['relname']), "</td>";
70
					echo "<td class=\"data{$id}\">", $misc->printVal($referrers->f['conname']), "</td>";
71
					echo "<td class=\"data{$id}\">", $misc->printVal($referrers->f['consrc']), "</td>";
72
					echo "<td class=\"opbutton{$id}\"><a href=\"constraints.php?{$misc->href}", 
73
						"&amp;schema=", urlencode($referrers->f['nspname']),
74
						"&amp;table=", urlencode($referrers->f['relname']), "\">{$lang['strproperties']}</a></td>\n";
75
					echo "\t</tr>\n";
76
					$referrers->movenext();
77
					$i++;
78
				}
79
	
80
				echo "</table>\n";
81
			}
82
			
83
			// Parent tables
84
			if ($parents->recordCount() > 0) {
85
				echo "<h3>{$lang['strparenttables']}</h3>\n";
86
				echo "<table>\n";
87
				echo "\t<tr>\n\t\t";
88
				if ($data->hasSchemas()) {			
89
					echo "<th class=\"data\">{$lang['strschema']}</th>";
90
				}
91
				echo "\t\t<th class=\"data\">{$lang['strtable']}</th>";			
92
				echo "<th class=\"data\">{$lang['stractions']}</th>\n";
93
				echo "\t</tr>\n";
94
				$i = 0;
95
				
96
				while (!$parents->EOF) {
97
					$id = ( ($i % 2 ) == 0 ? '1' : '2' );
98
					echo "\t<tr>\n";
99
					if ($data->hasSchemas()) {
100
						echo "\t\t<td class=\"data{$id}\">", $misc->printVal($parents->f['schemaname']), "</td>";
101
					}
102
					echo "<td class=\"data{$id}\">", $misc->printVal($parents->f['relname']), "</td>";
103
					echo "<td class=\"opbutton{$id}\"><a href=\"tblproperties.php?{$misc->href}",
104
						"&amp;schema=", urlencode($parents->f['schemaname']),
105
						"&amp;table=", urlencode($parents->f['relname']), "\">{$lang['strproperties']}</a></td>\n";
106
					echo "\t</tr>\n";
107
					$parents->movenext();
108
					$i++;
109
				}
110
	
111
				echo "</table>\n";
112
			}
113
	
114
			// Child tables
115
			if ($children->recordCount() > 0) {
116
				echo "<h3>{$lang['strchildtables']}</h3>\n";
117
				echo "<table>\n";
118
				echo "\t<tr>\n";
119
				if ($data->hasSchemas()) {			
120
					echo "<th class=\"data\">{$lang['strschema']}</th>";
121
				}
122
				echo "\t\t<th class=\"data\">{$lang['strtable']}</th>";			
123
				echo "<th class=\"data\">{$lang['stractions']}</th>\n";
124
				echo "\t</tr>\n";
125
				$i = 0;
126
				
127
				while (!$children->EOF) {
128
					$id = ( ($i % 2 ) == 0 ? '1' : '2' );
129
					echo "\t<tr>\n";
130
					if ($data->hasSchemas()) {
131
						echo "\t\t<td class=\"data{$id}\">", $misc->printVal($children->f['schemaname']), "</td>";
132
					}
133
					echo "<td class=\"data{$id}\">", $misc->printVal($children->f['relname']), "</td>";
134
					echo "<td class=\"opbutton{$id}\"><a href=\"tblproperties.php?{$misc->href}",
135
						"&amp;schema=", urlencode($children->f['schemaname']),
136
						"&amp;table=", urlencode($children->f['relname']), "\">{$lang['strproperties']}</a></td>\n";
137
					echo "\t</tr>\n";
138
					$children->movenext();
139
					$i++;
140
				}
141
	
142
				echo "</table>\n";
143
			}
144

    
145
            if ($data->hasStatsCollector()) {
146
    			// Row performance
147
    			if ($tablestatstups->recordCount() > 0) {
148
    				echo "<h3>{$lang['strrowperf']}</h3>\n";
149
    
150
    				echo "<table>\n";
151
    				echo "\t<tr>\n";
152
    				echo "\t\t<th class=\"data\" colspan=\"2\">{$lang['strsequential']}</th>\n";
153
    				echo "\t\t<th class=\"data\" colspan=\"2\">{$lang['strindex']}</th>\n";
154
    				echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strrows2']}</th>\n";
155
    				echo "\t</tr>\n";
156
    				echo "\t<tr>\n";
157
    				echo "\t\t<th class=\"data\">{$lang['strscan']}</th>\n";
158
    				echo "\t\t<th class=\"data\">{$lang['strread']}</th>\n";
159
    				echo "\t\t<th class=\"data\">{$lang['strscan']}</th>\n";
160
    				echo "\t\t<th class=\"data\">{$lang['strfetch']}</th>\n";
161
    				echo "\t\t<th class=\"data\">{$lang['strinsert']}</th>\n";
162
    				echo "\t\t<th class=\"data\">{$lang['strupdate']}</th>\n";
163
    				echo "\t\t<th class=\"data\">{$lang['strdelete']}</th>\n";
164
    				echo "\t</tr>\n";
165
    				$i = 0;
166
    				
167
    				while (!$tablestatstups->EOF) {
168
    					$id = ( ($i % 2 ) == 0 ? '1' : '2' );
169
    					echo "\t<tr>\n";
170
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatstups->f['seq_scan'], 'int4', $shownull), "</td>\n";
171
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatstups->f['seq_tup_read'], 'int4', $shownull), "</td>\n";
172
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatstups->f['idx_scan'], 'int4', $shownull), "</td>\n";
173
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatstups->f['idx_tup_fetch'], 'int4', $shownull), "</td>\n";
174
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatstups->f['n_tup_ins'], 'int4', $shownull), "</td>\n";
175
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatstups->f['n_tup_upd'], 'int4', $shownull), "</td>\n";
176
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatstups->f['n_tup_del'], 'int4', $shownull), "</td>\n";
177
    					echo "\t</tr>\n";
178
    					$tablestatstups->movenext();
179
    					$i++;
180
    				}
181
    	
182
    				echo "</table>\n";
183
    			}
184
    
185
    			// I/O performance
186
    			if ($tablestatsio->recordCount() > 0) {
187
    				echo "<h3>{$lang['strioperf']}</h3>\n";
188
    
189
    				echo "<table>\n";
190
    				echo "\t<tr>\n";
191
    				echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strheap']}</th>\n";
192
    				echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strindex']}</th>\n";
193
    				echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strtoast']}</th>\n";
194
    				echo "\t\t<th class=\"data\" colspan=\"3\">{$lang['strtoastindex']}</th>\n";
195
    				echo "\t</tr>\n";
196
    				echo "\t<tr>\n";
197
    				echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n";
198
    				echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n";
199
    				echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n";
200
    				echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n";
201
    				echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n";
202
    				echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n";
203
    				echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n";
204
    				echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n";
205
    				echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n";
206
    				echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n";
207
    				echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n";
208
    				echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n";
209
    				echo "\t</tr>\n";
210
    				$i = 0;
211
    				
212
    				while (!$tablestatsio->EOF) {
213
    					$id = ( ($i % 2 ) == 0 ? '1' : '2' );
214
    					echo "\t<tr>\n";
215
    
216
    					$total = $tablestatsio->f['heap_blks_hit'] + $tablestatsio->f['heap_blks_read'];
217
    					if ($total > 0)	$percentage = round(($tablestatsio->f['heap_blks_hit'] / $total) * 100);
218
    					else $percentage = 0;
219
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatsio->f['heap_blks_read'], 'int4', $shownull), "</td>\n";
220
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatsio->f['heap_blks_hit'], 'int4', $shownull), "</td>\n";
221
    					echo "\t\t<td class=\"data{$id}\">({$percentage}{$lang['strpercent']})</td>\n";
222
    
223
    					$total = $tablestatsio->f['idx_blks_hit'] + $tablestatsio->f['idx_blks_read'];
224
    					if ($total > 0)	$percentage = round(($tablestatsio->f['idx_blks_hit'] / $total) * 100);
225
    					else $percentage = 0;
226
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatsio->f['idx_blks_read'], 'int4', $shownull), "</td>\n";
227
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatsio->f['idx_blks_hit'], 'int4', $shownull), "</td>\n";
228
    					echo "\t\t<td class=\"data{$id}\">({$percentage}{$lang['strpercent']})</td>\n";
229
    
230
    					$total = $tablestatsio->f['toast_blks_hit'] + $tablestatsio->f['toast_blks_read'];
231
    					if ($total > 0)	$percentage = round(($tablestatsio->f['toast_blks_hit'] / $total) * 100);
232
    					else $percentage = 0;
233
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatsio->f['toast_blks_read'], 'int4', $shownull), "</td>\n";
234
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatsio->f['toast_blks_hit'], 'int4', $shownull), "</td>\n";
235
    					echo "\t\t<td class=\"data{$id}\">({$percentage}{$lang['strpercent']})</td>\n";
236
    
237
    					$total = $tablestatsio->f['tidx_blks_hit'] + $tablestatsio->f['tidx_blks_read'];
238
    					if ($total > 0)	$percentage = round(($tablestatsio->f['tidx_blks_hit'] / $total) * 100);
239
    					else $percentage = 0;
240
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatsio->f['tidx_blks_read'], 'int4', $shownull), "</td>\n";
241
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($tablestatsio->f['tidx_blks_hit'], 'int4', $shownull), "</td>\n";
242
    					echo "\t\t<td class=\"data{$id}\">({$percentage}{$lang['strpercent']})</td>\n";
243
    					echo "\t</tr>\n";
244
    					$tablestatsio->movenext();
245
    					$i++;
246
    				}
247
    	
248
    				echo "</table>\n";
249
    			}
250
    
251
    			// Index row performance
252
    			if ($indexstatstups->recordCount() > 0) {
253
    				echo "<h3>{$lang['stridxrowperf']}</h3>\n";
254
    
255
    				echo "<table>\n";
256
    				echo "\t<tr>\n";
257
    				echo "\t\t<th class=\"data\">{$lang['strindex']}</th>\n";
258
    				echo "\t\t<th class=\"data\">{$lang['strscan']}</th>\n";
259
    				echo "\t\t<th class=\"data\">{$lang['strread']}</th>\n";
260
    				echo "\t\t<th class=\"data\">{$lang['strfetch']}</th>\n";
261
    				echo "\t</tr>\n";
262
    				$i = 0;
263
    				
264
    				while (!$indexstatstups->EOF) {
265
    					$id = ( ($i % 2 ) == 0 ? '1' : '2' );
266
    					echo "\t<tr>\n";
267
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($indexstatstups->f['indexrelname']), "</td>\n";
268
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($indexstatstups->f['idx_scan'], 'int4', $shownull), "</td>\n";
269
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($indexstatstups->f['idx_tup_read'], 'int4', $shownull), "</td>\n";
270
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($indexstatstups->f['idx_tup_fetch'], 'int4', $shownull), "</td>\n";
271
    					echo "\t</tr>\n";
272
    					$indexstatstups->movenext();
273
    					$i++;
274
    				}
275
    	
276
    				echo "</table>\n";
277
    			}
278
    
279
    			// Index I/0 performance
280
    			if ($indexstatsio->recordCount() > 0) {
281
    				echo "<h3>{$lang['stridxioperf']}</h3>\n";
282
    
283
    				echo "<table>\n";
284
    				echo "\t<tr>\n";
285
    				echo "\t\t<th class=\"data\">{$lang['strindex']}</th>\n";
286
    				echo "\t\t<th class=\"data\">{$lang['strdisk']}</th>\n";
287
    				echo "\t\t<th class=\"data\">{$lang['strcache']}</th>\n";
288
    				echo "\t\t<th class=\"data\">{$lang['strpercent']}</th>\n";
289
    				echo "\t</tr>\n";
290
    				$i = 0;
291
    				
292
    				while (!$indexstatsio->EOF) {
293
    					$id = ( ($i % 2 ) == 0 ? '1' : '2' );
294
    					echo "\t<tr>\n";
295
    					$total = $indexstatsio->f['idx_blks_hit'] + $indexstatsio->f['idx_blks_read'];
296
    					if ($total > 0)	$percentage = round(($indexstatsio->f['idx_blks_hit'] / $total) * 100);
297
    					else $percentage = 0;
298
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($indexstatsio->f['indexrelname']), "</td>\n";
299
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($indexstatsio->f['idx_blks_read'], 'int4', $shownull), "</td>\n";
300
    					echo "\t\t<td class=\"data{$id}\">", $misc->printVal($indexstatsio->f['idx_blks_hit'], 'int4', $shownull), "</td>\n";
301
    					echo "\t\t<td class=\"data{$id}\">({$percentage}{$lang['strpercent']})</td>\n";
302
    					echo "\t</tr>\n";
303
    					$indexstatsio->movenext();
304
    					$i++;
305
    				}
306
    	
307
    				echo "</table>\n";
308
    			}
309
    		}
310
		}
311
	}
312

    
313
	$misc->printHeader($lang['strtables'] . ' - ' . $_REQUEST['table'] . ' - ' . $lang['strinfo']);
314
	$misc->printBody();
315
	
316
	switch ($action) {
317
		default:
318
			doDefault();
319
			break;
320
	}
321
	
322
	$misc->printFooter();
323

    
324
?>
(27-27/53)