MySQLでpqaを使ってみるテスト

Linuxでやる夫のアクセス数が多いようで悔しいのでタマには技術的な話でも。

slowクエリをサマリにするツールでPostgreSQLではpqaを使っているのだけど、pqa=「PostgreSQL query analysis」の略だと勝手に思っていたのだが、「Practical query analysis」の略であることを知る。つまりMySQLのログにも対応しているようだ。MySQLだと標準付属の「mysqldumpslow」を使うのが常套っぽいのだけど、一応結果ファイルを全部眺めないとどれが一番多い回数(Queries that took up the most time)とかがわからないで困っていたのでこれは期待できそう。※そんなに多種のslowクエリを吐いていることが問題かもしれないけど…

# pqa(Practical query analysis) Project
http://pgfoundry.org/projects/pqa/

Note: に「MySQL users, please stick with 1.4 for now, thanks!」とあったからpqa-1.4という古いバージョン(現行最新1.6)だとMySQLのログも食わせることができることを確認。

ただ、残念ながらいわゆる「general.log」形式のログしか食わせられないようで、slowクエリログを集計対象にしようとして試したのだがpqa側では認識できずslowクエリログのみしか取得していない際は活用できないっぽい。今のシステムにgeneral.logを吐かせようとすると涙目になる可能性が高いのでできないや。残念。

あと、pqa-1.6とPostgreSQLのログの組み合わせだと下記のようなサマリが出力されるのだが、それよりも簡素の模様。

######## Overall statistics
######## Queries by type
######## Queries that took up the most time
######## Slowest queries
######## Most frequent queries

=========================
サンプルログを食わせた出力結果
=========================

PB:~ yokoyama$ ruby /Library/Ruby/Gems/1.8/gems/pqa-1.4/lib/pqa.rb -logtype mysql -file /Library/Ruby/Gems/1.8/gems/pqa-1.4/sample/mysql_sample.log
######## Overall statistics
241 queries (96 unique) parsed in 0.29746 seconds
######## Queries by type
SELECTs: 239 (99%)
UPDATEs: 2 (1%)
######## Most frequent queries
23 times: SELECT name, query, linkinfooter FROM namedqueries WHERE userid = 165
23 times: SELECT mybugslink, realname, groupset, blessgroupset FROM profiles WHERE userid = 165
23 times: select name, (bit & 9223372036854775807) != 0 from groups
23 times: SELECT profiles.userid, profiles.groupset, profiles.login_name, profiles.login_name = ‘tom@infoether.com’ AND logincookies.ipaddr = ‘192.168.10.222′, profiles.disabledtext FROM profiles, logincookies WHERE logincookies.cookie = ‘141′ AND profiles.userid = logincookies.userid
18 times: select (bit & 9223372036854775807) != 0 from groups where name = ‘editbugs’
6 times: select (bit & 9223372036854775807) != 0 from groups where name = ‘canconfirm’
6 times: SELECT bit, name, description, (bit & 0 != 0), (bit & 9223372036854775807 != 0) FROM groups WHERE isbuggroup != 0 AND *1 OR (bit & 0 != 0))
5 times: SELECT name FROM fielddefs
4 times: SELECT bugs.bug_id FROM bugs LEFT JOIN cc selectVisible_cc ON bugs.bug_id = selectVisible_cc.bug_id AND selectVisible_cc.who = 165 WHERE *2 OR (bugs.assigned_to = 165)) AND bugs.bug_id = 13121
4 times: SELECT login_name,realname FROM profiles WHERE userid = 165

*1:isactive = 1 AND (bit & 9223372036854775807 != 0

*2:bugs.groupset & 9223372036854775807) = bugs.groupset OR (bugs.reporter_accessible = 1 AND bugs.reporter = 165) OR (bugs.cclist_accessible = 1 AND selectVisible_cc.who = 165 AND not isnull(selectVisible_cc.who