Class: Maatkit::IndexUsage
- Inherits:
-
Object
- Object
- Maatkit::IndexUsage
- Defined in:
- lib/maatkit-ruby/mk-index-usage.rb
Overview
Read queries from a log and analyze how they use indexes.
Maatkit::IndexUsage.new( array, str, array)
Instance Attribute Summary collapse
-
#ask_pass ⇒ Object
Prompt for a password when connecting to MySQL.
-
#charset ⇒ Object
short form: -A; type: string Default character set.
-
#config ⇒ Object
type: Array Read this comma-separated list of config files; if specified, this must be the first option on the command line.
-
#defaults_file ⇒ Object
short form: -F; type: string Only read mysql options from the given file.
-
#drop ⇒ Object
type: Hash; default: non-unique Suggest dropping only these types of unusued indexes.
-
#help ⇒ Object
Show help and exit.
-
#host ⇒ Object
short form: -h; type: string Connect to host.
-
#password ⇒ Object
short form: -p; type: string Password to use when connecting.
-
#path_to_mk_index_usage ⇒ Object
Sets the executable path, otherwise the environment path will be used.
-
#port ⇒ Object
short form: -P; type: int Port number to use for connection.
-
#progress ⇒ Object
type: array; default: time,30 Print progress reports to STDERR.
-
#quiet ⇒ Object
short form: -q Do not print any warnings.
-
#set_vars ⇒ Object
type: string; default: wait_timeout=10000 Set these MySQL variables.
-
#socket ⇒ Object
short form: -S; type: string Socket file to use for connection.
-
#user ⇒ Object
short form: -u; type: string User for login if not current user.
-
#version ⇒ Object
Show version and exit.
Instance Method Summary collapse
-
#initialize ⇒ IndexUsage
constructor
Returns a new IndexUsage Object.
-
#start(options = nil) ⇒ Object
Execute the command.
Constructor Details
#initialize ⇒ IndexUsage
Returns a new IndexUsage Object
107 108 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 107 def initialize() end |
Instance Attribute Details
#ask_pass ⇒ Object
Prompt for a password when connecting to MySQL.
17 18 19 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 17 def ask_pass @ask_pass end |
#charset ⇒ Object
short form: -A; type: string Default character set. If the value is utf8, sets Perl’s binmode on STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.
24 25 26 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 24 def charset @charset end |
#config ⇒ Object
type: Array Read this comma-separated list of config files; if specified, this must be the first option on the command line.
30 31 32 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 30 def config @config end |
#defaults_file ⇒ Object
short form: -F; type: string Only read mysql options from the given file. You must give an absolute pathname.
35 36 37 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 35 def defaults_file @defaults_file end |
#drop ⇒ Object
type: Hash; default: non-unique Suggest dropping only these types of unusued indexes. By default mk-index-usage will only suggest to drop unused secondary indexes, not primary or unique indexes. You can specify which types of unused indexes the tool suggests to drop: primary, unique, non-unique, all. A separate “ALTER TABLE” statement for each type is printed. So if you specify “–drop all” and there is a primary key and a non-unique index, the “ALTER TABLE … DROP” for each will be printed on separate lines.
46 47 48 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 46 def drop @drop end |
#help ⇒ Object
Show help and exit.
50 51 52 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 50 def help @help end |
#host ⇒ Object
short form: -h; type: string Connect to host.
55 56 57 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 55 def host @host end |
#password ⇒ Object
short form: -p; type: string Password to use when connecting.
60 61 62 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 60 def password @password end |
#path_to_mk_index_usage ⇒ Object
Sets the executable path, otherwise the environment path will be used.
102 103 104 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 102 def path_to_mk_index_usage @path_to_mk_index_usage end |
#port ⇒ Object
short form: -P; type: int Port number to use for connection.
65 66 67 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 65 def port @port end |
#progress ⇒ Object
type: array; default: time,30 Print progress reports to STDERR. The value is a comma-separated list with two parts. The first part can be percentage, time, or iterations; the second part specifies how often an update should be printed, in percentage, seconds, or number of iterations.
72 73 74 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 72 def progress @progress end |
#quiet ⇒ Object
short form: -q Do not print any warnings. Also disables “–progress”.
77 78 79 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 77 def quiet @quiet end |
#set_vars ⇒ Object
type: string; default: wait_timeout=10000 Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET and executed.
83 84 85 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 83 def set_vars @set_vars end |
#socket ⇒ Object
short form: -S; type: string Socket file to use for connection.
88 89 90 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 88 def socket @socket end |
#user ⇒ Object
short form: -u; type: string User for login if not current user.
93 94 95 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 93 def user @user end |
#version ⇒ Object
Show version and exit.
97 98 99 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 97 def version @version end |
Instance Method Details
#start(options = nil) ⇒ Object
Execute the command
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/maatkit-ruby/mk-index-usage.rb', line 113 def start( = nil) tmp = Tempfile.new('tmp') command = option_string() + .to_s + " 2> " + tmp.path success = system(command) if success begin while (line = tmp.readline) line.chomp selected_string = line end rescue EOFError tmp.close end return selected_string else tmp.close! return success end end |