Skip to content

Commit

Permalink
add a page that displays all queries that reference a particular table
Browse files Browse the repository at this point in the history
  • Loading branch information
timdenike committed Jun 21, 2011
1 parent ff5a5b1 commit 7848939
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions explain.php
Expand Up @@ -6,6 +6,7 @@
require_once('init.php'); require_once('init.php');


$checksum = $_GET['checksum']; $checksum = $_GET['checksum'];
$hours = $_GET['hours'];


$q = "SELECT * FROM {$host_conf['db_query_review_history_table']} WHERE checksum = '{$checksum}'"; $q = "SELECT * FROM {$host_conf['db_query_review_history_table']} WHERE checksum = '{$checksum}'";
$result = mysql_query($q); $result = mysql_query($q);
Expand Down
3 changes: 3 additions & 0 deletions explain.tpl
Expand Up @@ -13,7 +13,10 @@
<? foreach ($rows as $row): ?> <? foreach ($rows as $row): ?>
<tr <? if ($counter++ % 2): ?>class="alt"<? endif ?>> <tr <? if ($counter++ % 2): ?>class="alt"<? endif ?>>
<? foreach ($row as $key => $value): ?> <? foreach ($row as $key => $value): ?>
<? if ($key == "table"): ?><td><a href="table.php?hours=<?= $hours ?>&table=<?= $value ?>&host=<?= $host ?>"><?= $value ?></a></td>
<? else: ?>
<td><?= $value ?></td> <td><?= $value ?></td>
<? endif ?>
<? endforeach; ?> <? endforeach; ?>
</tr> </tr>
<? endforeach; ?> <? endforeach; ?>
Expand Down
34 changes: 34 additions & 0 deletions table.php
@@ -0,0 +1,34 @@
<?php
#
# 'table' UI - search for queries on a given table
#

require_once('init.php');

$table = $_GET['table'];
$hours = $_GET['hours'];

$q = "SELECT
t.sample as query, sum(h.ts_cnt) as count, t.checksum as checksum
from
{$host_conf['db_query_review_table']} as t
join
{$host_conf['db_query_review_history_table']} as h
on
t.checksum=h.checksum
where
t.sample like '% {$table} %'
AND
h.ts_max > date_sub(now(),interval {$hours} hour)
group by t.checksum order by count desc";

$result=mysql_query($q);

$rows = array();
while ($row = mysql_fetch_assoc($result)) {
$row['explain_url'] = "explain.php?" . ish_build_query(array('checksum'=>$row['checksum']));
$rows[] = $row;
}

require("table.tpl");

19 changes: 19 additions & 0 deletions table.tpl
@@ -0,0 +1,19 @@
<?php include("top.tpl"); ?>
<p>
</p>
<h3>More queries on table <?= $_GET['table'] ?></h3>
<table>
<tr>
<th>Count</th>
<th>Query</th>
<th>Explain</th>
</tr>
<? foreach ($rows as $row): ?>
<tr <? if ($counter++ % 2): ?>class="alt"<? endif ?>>
<td><?= $row['count']?></td>
<td><?=format_query($row['query']) ?></td>
<td><a href="<?= $row['explain_url'] ?>">explain</a></td>
</tr>
<? endforeach?>
</table>
<?php include("bottom.tpl"); ?>

0 comments on commit 7848939

Please sign in to comment.