~longbow/percona-xtrabackup/fix664986

« back to all changes in this revision

Viewing changes to doc/source/xtrabackup_bin/analyzing_table_statistics.rst

  • Committer: Alexey Kopytov
  • Date: 2011-07-19 07:15:08 UTC
  • mfrom: (290.2.1 staging)
  • Revision ID: akopytov@gmail.com-20110719071508-lxkx7tgghohnevkn
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
============================
 
2
 Analyzing Table Statistics
 
3
============================
 
4
 
 
5
The |xtrabackup| binary can analyze InnoDB data files in read-only mode to give statistics about them. To do this, you should use the :option:`--stats` option. You can combine this with the :option:`--tables` option to limit the files to examine. It also uses the :option:`--use-memory` option.
 
6
 
 
7
You can perform the analysis on a running server, with some chance of errors due to the data being changed during analysis. Or, you can analyze a backup copy of the database. Either way, to use the statistics feature, you need a clean copy of the database including correctly sized log files, so you need to execute with :option:`--prepare` twice to use this functionality on a backup.
 
8
 
 
9
The result of running on a backup might look like the following: ::
 
10
 
 
11
  <INDEX STATISTICS>
 
12
    table: test/table1, index: PRIMARY, space id: 12, root page 3
 
13
    estimated statistics in dictionary:
 
14
      key vals: 25265338, leaf pages 497839, size pages 498304
 
15
    real statistics:
 
16
       level 2 pages: pages=1, data=5395 bytes, data/pages=32%
 
17
       level 1 pages: pages=415, data=6471907 bytes, data/pages=95%
 
18
          leaf pages: recs=25958413, pages=497839, data=7492026403 bytes, data/pages=91%
 
19
 
 
20
This can be interpreted as follows:
 
21
 
 
22
* The first line simply shows the table and index name and its internal identifiers. If you see an index named ``GEN_CLUST_INDEX``, that is the table's clustered index, automatically created because you did not explicitly create a ``PRIMARY KEY``.
 
23
 
 
24
* The estimated statistics in dictionary information is similar to the data that's gathered through ``ANALYZE TABLE`` inside of |InnoDB| to be stored as estimated cardinality statistics and passed to the query optimizer.
 
25
 
 
26
* The real statistics information is the result of scanning the data pages and computing exact information about the index.
 
27
 
 
28
* ``The level <X> pages``: output means that the line shows information about pages at that level in the index tree. The larger ``<X>`` is, the farther it is from the leaf pages, which are level 0. The first line is the root page.
 
29
 
 
30
* The ``leaf pages`` output shows the leaf pages, of course. This is where the table's data is stored.
 
31
 
 
32
* The ``external pages``: output (not shown) shows large external pages that hold values too long to fit in the row itself, such as long ``BLOB`` and ``TEXT`` values.
 
33
 
 
34
* The ``recs`` is the real number of records (rows) in leaf pages.
 
35
 
 
36
* The ``pages`` is the page count.
 
37
 
 
38
* The ``data`` is the total size of the data in the pages, in bytes.
 
39
 
 
40
* The ``data/pages`` is calculated as (``data`` / (``pages`` * ``PAGE_SIZE``)) * 100%. It will never reach 100% because of space reserved for page headers and footers.
 
41
 
 
42
A more detailed example is posted as a MySQL Performance Blog post.
 
43
 
 
44
Script to Format Output
 
45
=======================
 
46
 
 
47
The following script can be used to summarize and tabulate the output of the statistics information: ::
 
48
 
 
49
    tabulate-xtrabackup-stats.pl
 
50
 
 
51
    #!/usr/bin/env perl
 
52
    use strict;
 
53
    use warnings FATAL => 'all';
 
54
    my $script_version = "0.1";
 
55
     
 
56
    my $PG_SIZE = 16_384; # InnoDB defaults to 16k pages, change if needed.
 
57
    my ($cur_idx, $cur_tbl);
 
58
    my (%idx_stats, %tbl_stats);
 
59
    my ($max_tbl_len, $max_idx_len) = (0, 0);
 
60
    while ( my $line = <> ) {
 
61
       if ( my ($t, $i) = $line =~ m/table: (.*), index: (.*), space id:/ ) {
 
62
          $t =~ s!/!.!;
 
63
          $cur_tbl = $t;
 
64
          $cur_idx = $i;
 
65
          if ( length($i) > $max_idx_len ) {
 
66
             $max_idx_len = length($i);
 
67
          }
 
68
          if ( length($t) > $max_tbl_len ) {
 
69
             $max_tbl_len = length($t);
 
70
          }
 
71
       }
 
72
       elsif ( my ($kv, $lp, $sp) = $line =~ m/key vals: (\d+), \D*(\d+), \D*(\d+)/ ) {
 
73
          @{$idx_stats{$cur_tbl}->{$cur_idx}}{qw(est_kv est_lp est_sp)} = ($kv, $lp, $sp);
 
74
          $tbl_stats{$cur_tbl}->{est_kv} += $kv;
 
75
          $tbl_stats{$cur_tbl}->{est_lp} += $lp;
 
76
          $tbl_stats{$cur_tbl}->{est_sp} += $sp;
 
77
       }
 
78
       elsif ( my ($l, $pages, $bytes) = $line =~ m/(?:level (\d+)|leaf) pages:.*pages=(\d+), data=(\d+) bytes/ ) {
 
79
          $l ||= 0;
 
80
          $idx_stats{$cur_tbl}->{$cur_idx}->{real_pages} += $pages;
 
81
          $idx_stats{$cur_tbl}->{$cur_idx}->{real_bytes} += $bytes;
 
82
          $tbl_stats{$cur_tbl}->{real_pages} += $pages;
 
83
          $tbl_stats{$cur_tbl}->{real_bytes} += $bytes;
 
84
       }
 
85
    }
 
86
     
 
87
    my $hdr_fmt = "%${max_tbl_len}s %${max_idx_len}s %9s %10s %10s\n";
 
88
    my @headers = qw(TABLE INDEX TOT_PAGES FREE_PAGES PCT_FULL);
 
89
    printf $hdr_fmt, @headers;
 
90
     
 
91
    my $row_fmt = "%${max_tbl_len}s %${max_idx_len}s %9d %10d %9.1f%%\n";
 
92
    foreach my $t ( sort keys %tbl_stats ) {
 
93
       my $tbl = $tbl_stats{$t};
 
94
       printf $row_fmt, $t, "", $tbl->{est_sp}, $tbl->{est_sp} - $tbl->{real_pages},
 
95
          $tbl->{real_bytes} / ($tbl->{real_pages} * $PG_SIZE) * 100;
 
96
       foreach my $i ( sort keys %{$idx_stats{$t}} ) {
 
97
          my $idx = $idx_stats{$t}->{$i};
 
98
          printf $row_fmt, $t, $i, $idx->{est_sp}, $idx->{est_sp} - $idx->{real_pages},
 
99
             $idx->{real_bytes} / ($idx->{real_pages} * $PG_SIZE) * 100;
 
100
       }
 
101
    }
 
102
 
 
103
Sample Script Output
 
104
--------------------
 
105
 
 
106
The output of the above Perl script, when run against the sample shown in the previously mentioned blog post, will appear as follows: ::
 
107
 
 
108
            TABLE           INDEX TOT_PAGES FREE_PAGES   PCT_FULL
 
109
  art.link_out104                    832383      38561      86.8%
 
110
  art.link_out104         PRIMARY    498304         49      91.9%
 
111
  art.link_out104       domain_id     49600       6230      76.9%
 
112
  art.link_out104     domain_id_2     26495       3339      89.1%
 
113
  art.link_out104 from_message_id     28160        142      96.3%
 
114
  art.link_out104    from_site_id     38848       4874      79.4%
 
115
  art.link_out104   revert_domain    153984      19276      71.4%
 
116
  art.link_out104    site_message     36992       4651      83.4%
 
117
 
 
118
The columns are the table and index, followed by the total number of pages in that index, the number of pages not actually occupied by data, and the number of bytes of real data as a percentage of the total size of the pages of real data. The first line in the above output, in which the ``INDEX`` column is empty, is a summary of the entire table.