Permalink
Browse files

add a page that displays all queries that reference a particular table

  • Loading branch information...
1 parent ff5a5b1 commit 784893932b18ee7bc17ec066767fa127e7f8348b @timdenike timdenike committed Jun 21, 2011
Showing with 57 additions and 0 deletions.
  1. +1 −0 explain.php
  2. +3 −0 explain.tpl
  3. +34 −0 table.php
  4. +19 −0 table.tpl
View
1 explain.php
@@ -6,6 +6,7 @@
require_once('init.php');
$checksum = $_GET['checksum'];
+ $hours = $_GET['hours'];
$q = "SELECT * FROM {$host_conf['db_query_review_history_table']} WHERE checksum = '{$checksum}'";
$result = mysql_query($q);
View
3 explain.tpl
@@ -13,7 +13,10 @@
<? foreach ($rows as $row): ?>
<tr <? if ($counter++ % 2): ?>class="alt"<? endif ?>>
<? 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>
+ <? endif ?>
<? endforeach; ?>
</tr>
<? endforeach; ?>
View
34 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");
+
View
19 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.