Build Status Coverage Status

NAME

MySQL::Explain::Parser - Parser for result of EXPLAIN of MySQL

SYNOPSIS

use utf8;
use MySQL::Explain::Parser qw/parse/;

my $explain = <<'...';
+----+-------------+-------+-------+---------------+---------+---------+------+------+----------+-------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | filtered | Extra       |
+----+-------------+-------+-------+---------------+---------+---------+------+------+----------+-------------+
|  1 | PRIMARY     | t1    | index | NULL          | PRIMARY | 4       | NULL | 4    | 100.00   |             |
|  2 | SUBQUERY    | t2    | index | a             | a       | 5       | NULL | 3    | 100.00   | Using index |
+----+-------------+-------+-------+---------------+---------+---------+------+------+----------+-------------+
...

my $parsed = parse($explain);
# =>
#    [
#        {
#            'id'            => '1',
#            'select_type'   => 'PRIMARY',
#            'table'         => 't1',
#            'type'          => 'index',
#            'possible_keys' => undef,
#            'key'           => 'PRIMARY',
#            'key_len'       => '4',
#            'ref'           => undef
#            'rows'          => '4',
#            'filtered'      => '100.00',
#            'Extra'         => '',
#        },
#        {
#            'id'            => '2',
#            'select_type'   => 'SUBQUERY',
#            'table'         => 't2',
#            'type'          => 'index',
#            'possible_keys' => 'a',
#            'key'           => 'a',
#            'key_len'       => '5',
#            'ref'           => undef
#            'rows'          => '3',
#            'filtered'      => '100.00',
#            'Extra'         => 'Using index',
#        }
#    ]

DESCRIPTION

MySQL::Explain::Parser is the parser for result of EXPLAIN of MySQL.

This module provides parse() and parse_vertical() function. These function receive the result of EXPLAIN or EXPLAIN EXTENDED, and return the parsed result as array reference that contains hash reference.

This module treat SQL's NULL as Perl's undef.

Please refer to the following pages to get information about format of EXPLAIN;

FUNCTIONS

LICENSE

Copyright (C) moznion.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

moznion moznion@gmail.com