16 if (!defined(
'ADODB_DIR'))
die();
23 created datetime NOT NULL, 24 sql0 varchar(250) NOT NULL, 28 timer decimal(16,6) NOT NULL 33 'MyISAM cache hit ratio' => array(
'RATIO',
36 'InnoDB cache hit ratio' => array(
'RATIO',
39 'data cache hit ratio' => array(
'HIDE', # only
if called
42 'sql cache hit ratio' => array(
'RATIO',
46 'data reads' => array(
'IO',
48 'Number of selects (Key_reads is not accurate)'),
49 'data writes' => array(
'IO',
51 'Number of inserts/updates/deletes * coef (Key_writes is not accurate)'),
54 'MyISAM data cache size' => array(
'DATAC',
55 array(
"show variables",
'key_buffer_size'),
57 'BDB data cache size' => array(
'DATAC',
58 array(
"show variables",
'bdb_cache_size'),
60 'InnoDB data cache size' => array(
'DATAC',
61 array(
"show variables",
'innodb_buffer_pool_size'),
64 'read buffer size' => array(
'CACHE',
65 array(
"show variables",
'read_buffer_size'),
67 'sort buffer size' => array(
'CACHE',
68 array(
"show variables",
'sort_buffer_size'),
69 'Size of sort buffer (per session)' ),
70 'table cache' => array(
'CACHE',
71 array(
"show variables",
'table_cache'),
72 'Number of tables to keep open'),
74 'current connections' => array(
'SESS',
75 array(
'show status',
'Threads_connected'),
77 'max connections' => array(
'SESS',
78 array(
"show variables",
'max_connections'),
92 if (strtoupper(substr(trim(
$sql),0,6)) !==
'SELECT')
return '<p>Unable to EXPLAIN non-select statement</p>';
93 $save = $this->conn->LogSQL(
false);
95 $sqlq = $this->conn->qstr(
$sql.
'%');
96 $arr = $this->conn->GetArray(
"select distinct sql1 from adodb_logsql where sql1 like $sqlq");
98 foreach($arr as $row) {
100 if (crc32(
$sql) == $partial)
break;
107 $sqlq = $this->conn->qstr(
$sql.
'%');
108 $sql = $this->conn->GetOne(
"select sql1 from adodb_logsql where sql1 like $sqlq");
111 $s =
'<p><b>Explain</b>: '.htmlspecialchars(
$sql).
'</p>';
112 $rs = $this->conn->Execute(
'EXPLAIN '.
$sql);
114 $this->conn->LogSQL($save);
121 if (!$this->tablesSQL)
return false;
123 $rs = $this->conn->Execute($this->tablesSQL);
124 if (!
$rs)
return false;
132 global $ADODB_FETCH_MODE;
133 $save = $ADODB_FETCH_MODE;
134 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
135 if ($this->conn->fetchMode !==
false) $savem = $this->conn->SetFetchMode(
false);
137 $rs = $this->conn->Execute(
'show status');
139 if (isset($savem)) $this->conn->SetFetchMode($savem);
140 $ADODB_FETCH_MODE = $save;
145 switch(
$rs->fields[0]) {
147 $val =
$rs->fields[1];
161 global $ADODB_FETCH_MODE;
162 $save = $ADODB_FETCH_MODE;
163 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
164 if ($this->conn->fetchMode !==
false) $savem = $this->conn->SetFetchMode(
false);
166 $rs = $this->conn->Execute(
'show status');
168 if (isset($savem)) $this->conn->SetFetchMode($savem);
169 $ADODB_FETCH_MODE = $save;
174 switch(
$rs->fields[0]) {
176 $val +=
$rs->fields[1];
break;
178 $val +=
$rs->fields[1];
break;
180 $val +=
$rs->fields[1]/2;
197 global $ADODB_FETCH_MODE;
198 $save = $ADODB_FETCH_MODE;
199 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
200 if ($this->conn->fetchMode !==
false) $savem = $this->conn->SetFetchMode(
false);
202 $rs = $this->conn->Execute(
'show table status');
204 if (isset($savem)) $this->conn->SetFetchMode($savem);
205 $ADODB_FETCH_MODE = $save;
208 $type = strtoupper(
$rs->fields[1]);
213 return $this->
DBParameter(
'MyISAM cache hit ratio').
' (MyISAM)';
215 return $this->
DBParameter(
'InnoDB cache hit ratio').
' (InnoDB)';
217 return $type.
' not supported';
225 $hits = $this->
_DBParameter(array(
"show status",
"Qcache_hits"));
226 $total = $this->
_DBParameter(array(
"show status",
"Qcache_inserts"));
227 $total += $this->
_DBParameter(array(
"show status",
"Qcache_not_cached"));
230 if ($total)
return round(($hits*100)/$total,2);
248 global $ADODB_FETCH_MODE;
250 $save = $ADODB_FETCH_MODE;
251 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
252 if ($this->conn->fetchMode !==
false) $savem = $this->conn->SetFetchMode(
false);
254 $rs = $this->conn->Execute(
'show engine innodb status');
256 if (isset($savem)) $this->conn->SetFetchMode($savem);
257 $ADODB_FETCH_MODE = $save;
259 if (!
$rs ||
$rs->EOF)
return 0;
260 $stat =
$rs->fields[0];
262 $at = strpos($stat,
'Buffer pool hit rate');
263 $stat = substr($stat,$at,200);
264 if (preg_match(
'!Buffer pool hit rate\s*([0-9]*) / ([0-9]*)!',$stat,$arr)) {
265 $val = 100*$arr[1]/$arr[2];
266 $_SESSION[
'INNODB_HIT_PCT'] = $val;
267 return round($val,2);
269 if (isset($_SESSION[
'INNODB_HIT_PCT']))
return $_SESSION[
'INNODB_HIT_PCT'];
277 $hits = $this->
_DBParameter(array(
"show status",
"Key_read_requests"));
278 $reqs = $this->
_DBParameter(array(
"show status",
"Key_reads"));
279 if ($reqs == 0)
return 0;
281 return round(($hits/($reqs+$hits))*100,2);
293 if ( !is_string(
$table))
return false;
296 if ( !
$conn)
return false;
305 ADOConnection::outp( sprintf(
"<p>%s: '%s' using of undefined mode '%s'</p>", __CLASS__, __FUNCTION__, $mode));
if(isset($_REQUEST['nrows'])) else $rs
Explain($sql, $partial=false)
optimizeTable( $table, $mode=ADODB_OPT_LOW)
rs2html(&$rs, $ztabhtml=false, $zheaderarray=false, $htmlspecialchars=true, $echo=true)