mysql_casual_explain 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.rubocop.yml +68 -0
- data/.travis.yml +6 -0
- data/Appraisals +9 -0
- data/Dockerfile +14 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +13 -0
- data/docker-compose.yml +15 -0
- data/gemfiles/ar52.gemfile +9 -0
- data/gemfiles/ar52.gemfile.lock +85 -0
- data/gemfiles/ar60.gemfile +9 -0
- data/gemfiles/ar60.gemfile.lock +85 -0
- data/lib/mysql_casual_explain.rb +12 -0
- data/lib/mysql_casual_explain/config.rb +41 -0
- data/lib/mysql_casual_explain/pretty_printer.rb +53 -0
- data/lib/mysql_casual_explain/version.rb +5 -0
- data/mysql_casual_explain.gemspec +33 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bfa3ca12a315eb43f64ad0250f20ae3e2a10c02f1b7ed3092ed43f4a5a58099f
|
4
|
+
data.tar.gz: ccbaa468d6f453eb069cef156ae4c12e1d874bd780fcfb19503ff3f561086882
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36a83aee0a65940ee65e0ee7fe238a6cbde339e58cef3f043664deadb28ef4fc3aecd3d6e17e7b30d94a585c8b279f3d919f31d8c06eda124d3027607c2f632d
|
7
|
+
data.tar.gz: e47caa8e550e91fd9bc233669e0ea197ff5839367fbca90a9a9a711a8e9597be9f95b5c3f5425e6d6fc007f7721bf8bf81e9c7ab29295392a12f67dae9d10683
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "gemfiles/**/*"
|
4
|
+
- "test.rb"
|
5
|
+
TargetRubyVersion: 2.5
|
6
|
+
Style/Documentation:
|
7
|
+
Enabled: false
|
8
|
+
Style/TrailingCommaInArrayLiteral:
|
9
|
+
EnforcedStyleForMultiline: consistent_comma
|
10
|
+
Style/TrailingCommaInHashLiteral:
|
11
|
+
EnforcedStyleForMultiline: consistent_comma
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Enabled: false
|
14
|
+
Metrics/CyclomaticComplexity:
|
15
|
+
Enabled: false
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Enabled: false
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Enabled: false
|
20
|
+
Layout/LineLength:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
24
|
+
Enabled: true
|
25
|
+
Layout/SpaceAroundMethodCallOperator:
|
26
|
+
Enabled: true
|
27
|
+
Lint/DeprecatedOpenSSLConstant:
|
28
|
+
Enabled: true
|
29
|
+
Lint/DuplicateElsifCondition:
|
30
|
+
Enabled: true
|
31
|
+
Lint/MixedRegexpCaptureTypes:
|
32
|
+
Enabled: true
|
33
|
+
Lint/RaiseException:
|
34
|
+
Enabled: true
|
35
|
+
Lint/StructNewOverride:
|
36
|
+
Enabled: true
|
37
|
+
Style/AccessorGrouping:
|
38
|
+
Enabled: true
|
39
|
+
Style/ArrayCoercion:
|
40
|
+
Enabled: true
|
41
|
+
Style/BisectedAttrAccessor:
|
42
|
+
Enabled: true
|
43
|
+
Style/CaseLikeIf:
|
44
|
+
Enabled: true
|
45
|
+
Style/ExponentialNotation:
|
46
|
+
Enabled: true
|
47
|
+
Style/HashAsLastArrayItem:
|
48
|
+
Enabled: true
|
49
|
+
Style/HashEachMethods:
|
50
|
+
Enabled: true
|
51
|
+
Style/HashLikeCase:
|
52
|
+
Enabled: true
|
53
|
+
Style/HashTransformKeys:
|
54
|
+
Enabled: true
|
55
|
+
Style/HashTransformValues:
|
56
|
+
Enabled: true
|
57
|
+
Style/RedundantAssignment:
|
58
|
+
Enabled: true
|
59
|
+
Style/RedundantFetchBlock:
|
60
|
+
Enabled: true
|
61
|
+
Style/RedundantFileExtensionInRequire:
|
62
|
+
Enabled: true
|
63
|
+
Style/RedundantRegexpCharacterClass:
|
64
|
+
Enabled: true
|
65
|
+
Style/RedundantRegexpEscape:
|
66
|
+
Enabled: true
|
67
|
+
Style/SlicingWithRange:
|
68
|
+
Enabled: true
|
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/Dockerfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
FROM rubylang/ruby:2.5-bionic
|
2
|
+
|
3
|
+
RUN apt-get update && \
|
4
|
+
apt-get install -y \
|
5
|
+
mysql-client \
|
6
|
+
libmysqlclient-dev \
|
7
|
+
rubygems \
|
8
|
+
curl
|
9
|
+
|
10
|
+
COPY ./ /mnt/
|
11
|
+
WORKDIR /mnt
|
12
|
+
RUN gem update bundler -f && \
|
13
|
+
bundle install && \
|
14
|
+
bundle exec appraisal install
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mysql_casual_explain (0.1.0)
|
5
|
+
activerecord
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (6.0.3.2)
|
11
|
+
activesupport (= 6.0.3.2)
|
12
|
+
activerecord (6.0.3.2)
|
13
|
+
activemodel (= 6.0.3.2)
|
14
|
+
activesupport (= 6.0.3.2)
|
15
|
+
activesupport (6.0.3.2)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
21
|
+
appraisal (2.3.0)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
thor (>= 0.14.0)
|
25
|
+
ast (2.4.1)
|
26
|
+
concurrent-ruby (1.1.6)
|
27
|
+
diff-lcs (1.4.4)
|
28
|
+
i18n (1.8.4)
|
29
|
+
concurrent-ruby (~> 1.0)
|
30
|
+
minitest (5.14.1)
|
31
|
+
mysql2 (0.5.3)
|
32
|
+
parallel (1.19.2)
|
33
|
+
parser (2.7.1.4)
|
34
|
+
ast (~> 2.4.1)
|
35
|
+
rainbow (3.0.0)
|
36
|
+
rake (12.3.3)
|
37
|
+
regexp_parser (1.7.1)
|
38
|
+
rexml (3.2.4)
|
39
|
+
rspec (3.9.0)
|
40
|
+
rspec-core (~> 3.9.0)
|
41
|
+
rspec-expectations (~> 3.9.0)
|
42
|
+
rspec-mocks (~> 3.9.0)
|
43
|
+
rspec-core (3.9.2)
|
44
|
+
rspec-support (~> 3.9.3)
|
45
|
+
rspec-expectations (3.9.2)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.9.0)
|
48
|
+
rspec-mocks (3.9.1)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.9.0)
|
51
|
+
rspec-support (3.9.3)
|
52
|
+
rubocop (0.88.0)
|
53
|
+
parallel (~> 1.10)
|
54
|
+
parser (>= 2.7.1.1)
|
55
|
+
rainbow (>= 2.2.2, < 4.0)
|
56
|
+
regexp_parser (>= 1.7)
|
57
|
+
rexml
|
58
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
59
|
+
ruby-progressbar (~> 1.7)
|
60
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
61
|
+
rubocop-ast (0.1.0)
|
62
|
+
parser (>= 2.7.0.1)
|
63
|
+
ruby-progressbar (1.10.1)
|
64
|
+
thor (1.0.1)
|
65
|
+
thread_safe (0.3.6)
|
66
|
+
tzinfo (1.2.7)
|
67
|
+
thread_safe (~> 0.1)
|
68
|
+
unicode-display_width (1.7.0)
|
69
|
+
zeitwerk (2.4.0)
|
70
|
+
|
71
|
+
PLATFORMS
|
72
|
+
ruby
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
appraisal
|
76
|
+
bundler
|
77
|
+
mysql2
|
78
|
+
mysql_casual_explain!
|
79
|
+
rake (~> 12.0)
|
80
|
+
rspec (~> 3.0)
|
81
|
+
rubocop
|
82
|
+
|
83
|
+
BUNDLED WITH
|
84
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 winebarrel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# MysqlCasualExplain
|
2
|
+
|
3
|
+
Highlight problematic MySQL explain results.
|
4
|
+
|
5
|
+
Inspired by [MySQLCasualLog.pm](https://gist.github.com/kamipo/839e8a5b6d12bddba539).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'mysql_casual_explain'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install mysql_casual_explain
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
#!/usr/bin/env ruby
|
27
|
+
require 'active_record'
|
28
|
+
require 'mysql_casual_explain'
|
29
|
+
|
30
|
+
ActiveRecord::Base.establish_connection(
|
31
|
+
adapter: 'mysql2',
|
32
|
+
username: 'root',
|
33
|
+
database: 'employees'
|
34
|
+
)
|
35
|
+
|
36
|
+
|
37
|
+
class Employee < ActiveRecord::Base; end
|
38
|
+
|
39
|
+
puts Employee.all.explain
|
40
|
+
```
|
41
|
+
|
42
|
+

|
43
|
+
|
44
|
+
## Test
|
45
|
+
|
46
|
+
```sh
|
47
|
+
docker-compose build
|
48
|
+
docker-compose run client bundle exec appraisal ar60 rake
|
49
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
RuboCop::RakeTask.new do |task|
|
10
|
+
task.options = %w[-c .rubocop.yml]
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: %i[rubocop spec]
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
version: "3.8"
|
2
|
+
services:
|
3
|
+
client:
|
4
|
+
build: .
|
5
|
+
environment:
|
6
|
+
MYSQL_PING_ATTEMPTS: "10"
|
7
|
+
DATABASE_URL: mysql2://root@db/sakila
|
8
|
+
volumes:
|
9
|
+
- ./:/mnt
|
10
|
+
depends_on:
|
11
|
+
- db
|
12
|
+
db:
|
13
|
+
image: budougumi0617/mysql-sakila:5.7
|
14
|
+
environment:
|
15
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: "1"
|
@@ -0,0 +1,85 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
mysql_casual_explain (0.1.0)
|
5
|
+
activerecord
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (5.2.4.3)
|
11
|
+
activesupport (= 5.2.4.3)
|
12
|
+
activerecord (5.2.4.3)
|
13
|
+
activemodel (= 5.2.4.3)
|
14
|
+
activesupport (= 5.2.4.3)
|
15
|
+
arel (>= 9.0)
|
16
|
+
activesupport (5.2.4.3)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 0.7, < 2)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
appraisal (2.3.0)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
thor (>= 0.14.0)
|
25
|
+
arel (9.0.0)
|
26
|
+
ast (2.4.1)
|
27
|
+
concurrent-ruby (1.1.6)
|
28
|
+
diff-lcs (1.4.4)
|
29
|
+
i18n (1.8.4)
|
30
|
+
concurrent-ruby (~> 1.0)
|
31
|
+
minitest (5.14.1)
|
32
|
+
mysql2 (0.5.3)
|
33
|
+
parallel (1.19.2)
|
34
|
+
parser (2.7.1.4)
|
35
|
+
ast (~> 2.4.1)
|
36
|
+
rainbow (3.0.0)
|
37
|
+
rake (12.3.3)
|
38
|
+
regexp_parser (1.7.1)
|
39
|
+
rexml (3.2.4)
|
40
|
+
rspec (3.9.0)
|
41
|
+
rspec-core (~> 3.9.0)
|
42
|
+
rspec-expectations (~> 3.9.0)
|
43
|
+
rspec-mocks (~> 3.9.0)
|
44
|
+
rspec-core (3.9.2)
|
45
|
+
rspec-support (~> 3.9.3)
|
46
|
+
rspec-expectations (3.9.2)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.9.0)
|
49
|
+
rspec-mocks (3.9.1)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.9.0)
|
52
|
+
rspec-support (3.9.3)
|
53
|
+
rubocop (0.88.0)
|
54
|
+
parallel (~> 1.10)
|
55
|
+
parser (>= 2.7.1.1)
|
56
|
+
rainbow (>= 2.2.2, < 4.0)
|
57
|
+
regexp_parser (>= 1.7)
|
58
|
+
rexml
|
59
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
60
|
+
ruby-progressbar (~> 1.7)
|
61
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
62
|
+
rubocop-ast (0.1.0)
|
63
|
+
parser (>= 2.7.0.1)
|
64
|
+
ruby-progressbar (1.10.1)
|
65
|
+
thor (1.0.1)
|
66
|
+
thread_safe (0.3.6)
|
67
|
+
tzinfo (1.2.7)
|
68
|
+
thread_safe (~> 0.1)
|
69
|
+
unicode-display_width (1.7.0)
|
70
|
+
|
71
|
+
PLATFORMS
|
72
|
+
ruby
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
activerecord (~> 5.2.1)
|
76
|
+
appraisal
|
77
|
+
bundler
|
78
|
+
mysql2
|
79
|
+
mysql_casual_explain!
|
80
|
+
rake (~> 12.0)
|
81
|
+
rspec (~> 3.0)
|
82
|
+
rubocop
|
83
|
+
|
84
|
+
BUNDLED WITH
|
85
|
+
2.1.4
|
@@ -0,0 +1,85 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
mysql_casual_explain (0.1.0)
|
5
|
+
activerecord
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (6.0.3.2)
|
11
|
+
activesupport (= 6.0.3.2)
|
12
|
+
activerecord (6.0.3.2)
|
13
|
+
activemodel (= 6.0.3.2)
|
14
|
+
activesupport (= 6.0.3.2)
|
15
|
+
activesupport (6.0.3.2)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
21
|
+
appraisal (2.3.0)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
thor (>= 0.14.0)
|
25
|
+
ast (2.4.1)
|
26
|
+
concurrent-ruby (1.1.6)
|
27
|
+
diff-lcs (1.4.4)
|
28
|
+
i18n (1.8.4)
|
29
|
+
concurrent-ruby (~> 1.0)
|
30
|
+
minitest (5.14.1)
|
31
|
+
mysql2 (0.5.3)
|
32
|
+
parallel (1.19.2)
|
33
|
+
parser (2.7.1.4)
|
34
|
+
ast (~> 2.4.1)
|
35
|
+
rainbow (3.0.0)
|
36
|
+
rake (12.3.3)
|
37
|
+
regexp_parser (1.7.1)
|
38
|
+
rexml (3.2.4)
|
39
|
+
rspec (3.9.0)
|
40
|
+
rspec-core (~> 3.9.0)
|
41
|
+
rspec-expectations (~> 3.9.0)
|
42
|
+
rspec-mocks (~> 3.9.0)
|
43
|
+
rspec-core (3.9.2)
|
44
|
+
rspec-support (~> 3.9.3)
|
45
|
+
rspec-expectations (3.9.2)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.9.0)
|
48
|
+
rspec-mocks (3.9.1)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.9.0)
|
51
|
+
rspec-support (3.9.3)
|
52
|
+
rubocop (0.88.0)
|
53
|
+
parallel (~> 1.10)
|
54
|
+
parser (>= 2.7.1.1)
|
55
|
+
rainbow (>= 2.2.2, < 4.0)
|
56
|
+
regexp_parser (>= 1.7)
|
57
|
+
rexml
|
58
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
59
|
+
ruby-progressbar (~> 1.7)
|
60
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
61
|
+
rubocop-ast (0.1.0)
|
62
|
+
parser (>= 2.7.0.1)
|
63
|
+
ruby-progressbar (1.10.1)
|
64
|
+
thor (1.0.1)
|
65
|
+
thread_safe (0.3.6)
|
66
|
+
tzinfo (1.2.7)
|
67
|
+
thread_safe (~> 0.1)
|
68
|
+
unicode-display_width (1.7.0)
|
69
|
+
zeitwerk (2.4.0)
|
70
|
+
|
71
|
+
PLATFORMS
|
72
|
+
ruby
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
activerecord (~> 6.0.3)
|
76
|
+
appraisal
|
77
|
+
bundler
|
78
|
+
mysql2
|
79
|
+
mysql_casual_explain!
|
80
|
+
rake (~> 12.0)
|
81
|
+
rspec (~> 3.0)
|
82
|
+
rubocop
|
83
|
+
|
84
|
+
BUNDLED WITH
|
85
|
+
2.1.4
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
|
5
|
+
require 'mysql_casual_explain/config'
|
6
|
+
require 'mysql_casual_explain/pretty_printer'
|
7
|
+
require 'mysql_casual_explain/version'
|
8
|
+
|
9
|
+
ActiveSupport.on_load :active_record do
|
10
|
+
require 'active_record/connection_adapters/mysql/explain_pretty_printer'
|
11
|
+
ActiveRecord::ConnectionAdapters::MySQL::ExplainPrettyPrinter.prepend MysqlCasualExplain::PrettyPrinter
|
12
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MysqlCasualExplain
|
4
|
+
SLOW_SELECT_TYPE_RE = Regexp.union(
|
5
|
+
'DEPENDENT UNION',
|
6
|
+
'DEPENDENT SUBQUERY',
|
7
|
+
'UNCACHEABLE UNION',
|
8
|
+
'UNCACHEABLE SUBQUERY'
|
9
|
+
)
|
10
|
+
|
11
|
+
SLOW_TYPE_RE = Regexp.union('index', 'ALL')
|
12
|
+
SLOW_POSSIBLE_KEYS_RE = Regexp.union('NULL')
|
13
|
+
SLOW_KEY_RE = Regexp.union('NULL')
|
14
|
+
|
15
|
+
SLOW_EXTRA_RE = Regexp.union(
|
16
|
+
'Using filesort',
|
17
|
+
'Using temporary'
|
18
|
+
)
|
19
|
+
|
20
|
+
@warnings_by_column = {
|
21
|
+
select_type: [
|
22
|
+
->(value) { SLOW_SELECT_TYPE_RE =~ value },
|
23
|
+
],
|
24
|
+
type: [
|
25
|
+
->(value) { SLOW_TYPE_RE =~ value },
|
26
|
+
],
|
27
|
+
possible_keys: [
|
28
|
+
->(value) { SLOW_POSSIBLE_KEYS_RE =~ value },
|
29
|
+
],
|
30
|
+
key: [
|
31
|
+
->(value) { SLOW_KEY_RE =~ value },
|
32
|
+
],
|
33
|
+
extra: [
|
34
|
+
->(value) { SLOW_EXTRA_RE =~ value },
|
35
|
+
],
|
36
|
+
}
|
37
|
+
|
38
|
+
class << self
|
39
|
+
attr_accessor :warnings_by_column
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MysqlCasualExplain
|
4
|
+
module PrettyPrinter
|
5
|
+
COLUMNS = %i[
|
6
|
+
id
|
7
|
+
select_type
|
8
|
+
table
|
9
|
+
type
|
10
|
+
possible_keys
|
11
|
+
key
|
12
|
+
key_len
|
13
|
+
ref
|
14
|
+
rows
|
15
|
+
extra
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
BOLD = ActiveSupport::LogSubscriber::BOLD
|
19
|
+
RED = ActiveSupport::LogSubscriber::RED
|
20
|
+
CLEAR = ActiveSupport::LogSubscriber::CLEAR
|
21
|
+
|
22
|
+
def build_cells(items, widths)
|
23
|
+
items, widths = _colorize_items(items, widths) if items.first != 'id'
|
24
|
+
super(items, widths)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def _colorize_items(items, widths)
|
30
|
+
item_by_column = COLUMNS.zip(items).to_h
|
31
|
+
warnings_by_column = MysqlCasualExplain.warnings_by_column
|
32
|
+
|
33
|
+
new_items = []
|
34
|
+
new_widths = []
|
35
|
+
extra_len = "#{BOLD}#{RED}#{CLEAR}".length
|
36
|
+
|
37
|
+
item_by_column.each_with_index do |(column, item), i|
|
38
|
+
item = 'NULL' if item.nil?
|
39
|
+
warnings = warnings_by_column.fetch(column, [])
|
40
|
+
|
41
|
+
if warnings.any? { |w| w.call(item) }
|
42
|
+
new_items << "#{BOLD}#{RED}#{item}#{CLEAR}"
|
43
|
+
new_widths << widths[i] + extra_len
|
44
|
+
else
|
45
|
+
new_items << item
|
46
|
+
new_widths << widths[i]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
[new_items, new_widths]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/mysql_casual_explain/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'mysql_casual_explain'
|
7
|
+
spec.version = MysqlCasualExplain::VERSION
|
8
|
+
spec.authors = ['winebarrel']
|
9
|
+
spec.email = ['sugawara@winebarrel.jp']
|
10
|
+
|
11
|
+
spec.summary = 'Highlight problematic MySQL explain results.'
|
12
|
+
spec.description = 'Highlight problematic MySQL explain results.'
|
13
|
+
spec.homepage = 'https://github.com/winebarrel/mysql_casual_explain'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_dependency 'activerecord'
|
27
|
+
spec.add_development_dependency 'appraisal'
|
28
|
+
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'mysql2'
|
30
|
+
spec.add_development_dependency 'rake'
|
31
|
+
spec.add_development_dependency 'rspec'
|
32
|
+
spec.add_development_dependency 'rubocop'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mysql_casual_explain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- winebarrel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mysql2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Highlight problematic MySQL explain results.
|
112
|
+
email:
|
113
|
+
- sugawara@winebarrel.jp
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Appraisals
|
123
|
+
- Dockerfile
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- docker-compose.yml
|
130
|
+
- gemfiles/ar52.gemfile
|
131
|
+
- gemfiles/ar52.gemfile.lock
|
132
|
+
- gemfiles/ar60.gemfile
|
133
|
+
- gemfiles/ar60.gemfile.lock
|
134
|
+
- lib/mysql_casual_explain.rb
|
135
|
+
- lib/mysql_casual_explain/config.rb
|
136
|
+
- lib/mysql_casual_explain/pretty_printer.rb
|
137
|
+
- lib/mysql_casual_explain/version.rb
|
138
|
+
- mysql_casual_explain.gemspec
|
139
|
+
homepage: https://github.com/winebarrel/mysql_casual_explain
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 2.3.0
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubygems_version: 3.0.3
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: Highlight problematic MySQL explain results.
|
162
|
+
test_files: []
|