arel-mysql-index-hint 0.1.0 → 0.1.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 758e3e6dbf40d9363f4663cf9924b01ce6cdabf5
|
4
|
+
data.tar.gz: 0b39b9b861187a818a2b072397cef9fbd0a2fa8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cccbf44e580a68b70b041764f5526552f32133e091f67159e6b976239fb4d964c2e0e66ad31f0bffa009e4e78f23af2ec73dfa6d64f2e76348815a3a79f7cbee
|
7
|
+
data.tar.gz: 61d096700cc04ea3fb8d78e403d64e6751094a12156af6d6f4ffab3ee1e1aa3f42a7fbb5c0eb234ecba527d6445e2b4f970f1878ef432122c4bd827f015550a9
|
data/README.md
CHANGED
@@ -25,6 +25,9 @@ Or install it yourself as:
|
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
```ruby
|
28
|
+
Article.hint(idx_article: :force)
|
29
|
+
# => "SELECT `articles`.* FROM `articles` force INDEX (idx_article)"
|
30
|
+
|
28
31
|
Article.joins(:comments).hint(articles: {idx_article: :use})
|
29
32
|
# => "SELECT `articles`.* FROM `articles` use INDEX (idx_article) INNER JOIN `comments` ON `comments`
|
30
33
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = "arel-mysql-index-hint"
|
4
|
-
spec.version = "0.1.
|
4
|
+
spec.version = "0.1.1"
|
5
5
|
spec.authors = ["Genki Sugawara"]
|
6
6
|
spec.email = ["sgwr_dts@yahoo.co.jp"]
|
7
7
|
spec.summary = %q{Add index hint to MySQL query in Arel.}
|
@@ -26,7 +26,16 @@ class Arel::Visitors::MySQL
|
|
26
26
|
|
27
27
|
def get_index_hint(table)
|
28
28
|
index_hint_by_table = Thread.current[INDEX_HINT_BY_TABLE_THREAD_KEY]
|
29
|
-
|
29
|
+
|
30
|
+
if index_hint_by_table.nil? or index_hint_by_table.empty?
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
|
34
|
+
if index_hint_by_table.values.any? {|i| i.is_a?(Hash) }
|
35
|
+
index_hint_by_table[table]
|
36
|
+
else
|
37
|
+
index_hint_by_table
|
38
|
+
end
|
30
39
|
end
|
31
40
|
|
32
41
|
def clear_index_hint_by_table
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe "arel-mysql-index-hint" do
|
2
|
+
context "unnested hint" do
|
3
|
+
subject do
|
4
|
+
User.
|
5
|
+
hint(index_users_on_email: hint_type).
|
6
|
+
to_sql
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:sql) do
|
10
|
+
"SELECT `users`.* " +
|
11
|
+
"FROM `users` " +
|
12
|
+
"#{hint_type} INDEX (index_users_on_email)"
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:hint_type) { :force }
|
16
|
+
|
17
|
+
it { is_expected.to eq sql }
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel-mysql-index-hint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- spec/arel-mysql-index-hint/includes_spec.rb
|
147
147
|
- spec/arel-mysql-index-hint/joins_spec.rb
|
148
148
|
- spec/arel-mysql-index-hint/preload_spec.rb
|
149
|
+
- spec/arel-mysql-index-hint/unnested_hint_spec.rb
|
149
150
|
- spec/arel-mysql-index-hint/without_join_spec.rb
|
150
151
|
- spec/init.sql
|
151
152
|
- spec/models.rb
|
@@ -179,6 +180,7 @@ test_files:
|
|
179
180
|
- spec/arel-mysql-index-hint/includes_spec.rb
|
180
181
|
- spec/arel-mysql-index-hint/joins_spec.rb
|
181
182
|
- spec/arel-mysql-index-hint/preload_spec.rb
|
183
|
+
- spec/arel-mysql-index-hint/unnested_hint_spec.rb
|
182
184
|
- spec/arel-mysql-index-hint/without_join_spec.rb
|
183
185
|
- spec/init.sql
|
184
186
|
- spec/models.rb
|