shiba 0.9.3 → 0.9.4
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 +5 -5
- data/.travis.yml +5 -0
- data/Gemfile.lock +1 -1
- data/lib/shiba/explain.rb +8 -0
- data/lib/shiba/index_stats.rb +12 -3
- data/lib/shiba/parsers/mysql_select_fields.rb +13 -0
- data/lib/shiba/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b605c4306ab0ccc32f881973a7cea994b50db84a
|
4
|
+
data.tar.gz: c19790bf5c25d35b80973395e13cee7b644fdba3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abad67fe6c72f8dbce81a10ccacdcd024ec6d9c3d1a9c55f463ecf6825b7a48ad77578a12ced06df67770675ff785f9b861d8444880c67789a980fa49e102393
|
7
|
+
data.tar.gz: fb92c8fbb81b39a925bcdc5a85f37a974fd938c000956d1c02a44bfd4c7730b306a32d57e12b1d95f1717e70095a3d1a14339938c919d1b698221370b2ebe5f3
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/shiba/explain.rb
CHANGED
@@ -33,6 +33,14 @@ module Shiba
|
|
33
33
|
|
34
34
|
if Shiba.connection.mysql?
|
35
35
|
@rows = Shiba::Explain::MysqlExplain.new.transform_json(@explain_json['query_block'])
|
36
|
+
|
37
|
+
# For simple queries, use original table name rather than the alias
|
38
|
+
if @select_fields.keys.size == 1
|
39
|
+
table = @select_fields.keys.first
|
40
|
+
if @rows.first['table'] != table
|
41
|
+
@rows.first['table'] = table
|
42
|
+
end
|
43
|
+
end
|
36
44
|
else
|
37
45
|
@rows = Shiba::Explain::PostgresExplain.new(@explain_json).transform
|
38
46
|
end
|
data/lib/shiba/index_stats.rb
CHANGED
@@ -13,6 +13,15 @@ module Shiba
|
|
13
13
|
@tables.any?
|
14
14
|
end
|
15
15
|
|
16
|
+
# case insenstive table match
|
17
|
+
def find_table(name)
|
18
|
+
table = @tables[name]
|
19
|
+
return table if table
|
20
|
+
|
21
|
+
_, table = @tables.detect { |k,_| k.casecmp(name).zero? }
|
22
|
+
return table
|
23
|
+
end
|
24
|
+
|
16
25
|
Table = Struct.new(:name, :count, :indexes) do
|
17
26
|
def encode_with(coder)
|
18
27
|
if self.count.nil?
|
@@ -138,11 +147,11 @@ module Shiba
|
|
138
147
|
attr_reader :tables
|
139
148
|
|
140
149
|
def table_count(table)
|
141
|
-
return
|
150
|
+
return find_table(table).count if find_table(table)
|
142
151
|
end
|
143
152
|
|
144
153
|
def fetch_index(table, name)
|
145
|
-
tbl =
|
154
|
+
tbl = find_table(table)
|
146
155
|
return nil unless tbl
|
147
156
|
|
148
157
|
tbl.indexes[name]
|
@@ -158,7 +167,7 @@ module Shiba
|
|
158
167
|
end
|
159
168
|
|
160
169
|
def get_column_size(table_name, column)
|
161
|
-
table =
|
170
|
+
table = find_table(table_name)
|
162
171
|
return nil unless table
|
163
172
|
|
164
173
|
table.column_sizes[column]
|
@@ -2,6 +2,7 @@ require 'shiba/parsers/shiba_string_scanner'
|
|
2
2
|
|
3
3
|
module Shiba
|
4
4
|
module Parsers
|
5
|
+
# Extracts table name and columns from queries formatted by 'show warnings'.
|
5
6
|
class MysqlSelectFields
|
6
7
|
def initialize(sql)
|
7
8
|
@sql = sql
|
@@ -66,6 +67,18 @@ module Shiba
|
|
66
67
|
|
67
68
|
sc.scan(/,/)
|
68
69
|
end
|
70
|
+
|
71
|
+
# resolve table aliases
|
72
|
+
if sc.scan(/ `.*?`\.`(.*?)` `(.*?)`/)
|
73
|
+
table = sc[1]
|
74
|
+
table_alias = sc[2]
|
75
|
+
|
76
|
+
if tables[table_alias]
|
77
|
+
tables[table] = tables[table_alias]
|
78
|
+
tables.delete(table_alias)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
69
82
|
tables
|
70
83
|
end
|
71
84
|
end
|
data/lib/shiba/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shiba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Osheroff
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -160,10 +160,9 @@ files:
|
|
160
160
|
- shiba.gemspec
|
161
161
|
- shiba.yml.example
|
162
162
|
- web/babel.config.js
|
163
|
-
- web/dist/example_data.json
|
164
163
|
- web/dist/index.html
|
165
|
-
- web/dist/js/app.
|
166
|
-
- web/dist/js/app.
|
164
|
+
- web/dist/js/app.bca3a322.js
|
165
|
+
- web/dist/js/app.bca3a322.js.map
|
167
166
|
- web/package-lock.json
|
168
167
|
- web/package.json
|
169
168
|
- web/public/index.html
|
@@ -198,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
197
|
version: '0'
|
199
198
|
requirements: []
|
200
199
|
rubyforge_project:
|
201
|
-
rubygems_version: 2.
|
200
|
+
rubygems_version: 2.6.14.1
|
202
201
|
signing_key:
|
203
202
|
specification_version: 4
|
204
203
|
summary: Catch bad SQL queries before they cause problems in production
|