arel-mysql-index-hint 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/Appraisals +7 -0
- data/arel-mysql-index-hint.gemspec +4 -3
- data/gemfiles/activerecord_4.1.gemfile +7 -0
- data/gemfiles/activerecord_4.2.gemfile +7 -0
- data/lib/arel-mysql-index-hint.rb +22 -4
- data/lib/arel-mysql-index-hint/active_record-hint_methods.rb +38 -9
- data/lib/arel-mysql-index-hint/arel-table.rb +5 -0
- data/lib/arel-mysql-index-hint/arel-visitors-mysql.rb +27 -42
- data/spec/arel-mysql-index-hint/eager_load_spec.rb +5 -5
- data/spec/arel-mysql-index-hint/includes_spec.rb +5 -5
- data/spec/arel-mysql-index-hint/joins_spec.rb +8 -8
- data/spec/arel-mysql-index-hint/preload_spec.rb +2 -2
- data/spec/arel-mysql-index-hint/unnested_hint_spec.rb +2 -2
- data/spec/arel-mysql-index-hint/without_join_spec.rb +13 -13
- data/spec/spec_helper.rb +3 -1
- metadata +23 -6
- data/lib/arel-mysql-index-hint/active_record-querying.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 243154f93cd1a66d1f97b1c1f7a4b262eeab8739
|
4
|
+
data.tar.gz: 4e85f62d35712c7c718d08aacc31206949e0ae77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89a435f9127708456efad60d6912b98b3c8598d5f51f86c64d78a010d210c94d357f70417615c4f43efdd1a847c2b75f040d060d95ce687e2dbbf34fb4f55c16
|
7
|
+
data.tar.gz: 19e57e41253edd21929317188e8e3985ee857820590e1c170ccd316956ea8af87e9c4592200803da2bec9e9fe4f20e602404a8b63c4db76ee885c2e2c0c66755
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Appraisals
ADDED
@@ -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.2"
|
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.}
|
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
|
17
|
-
spec.add_dependency "activerecord", "
|
18
|
-
spec.add_dependency "arel", "
|
17
|
+
spec.add_dependency "activerecord", ">= 4.1.0"
|
18
|
+
spec.add_dependency "arel", ">= 5.0.0"
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler"
|
21
21
|
spec.add_development_dependency "rake"
|
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rspec", ">= 3.0.0"
|
24
24
|
spec.add_development_dependency "factory_girl"
|
25
25
|
spec.add_development_dependency "coveralls"
|
26
|
+
spec.add_development_dependency "appraisal"
|
26
27
|
end
|
@@ -1,5 +1,23 @@
|
|
1
|
-
require "
|
1
|
+
require "active_support"
|
2
2
|
|
3
|
-
|
4
|
-
require "arel-mysql-index-hint/active_record-
|
5
|
-
require "arel-mysql-index-hint/arel-
|
3
|
+
ActiveSupport.on_load :active_record do
|
4
|
+
require "arel-mysql-index-hint/active_record-hint_methods"
|
5
|
+
require "arel-mysql-index-hint/arel-table"
|
6
|
+
require "arel-mysql-index-hint/arel-visitors-mysql"
|
7
|
+
|
8
|
+
ActiveRecord::Relation.class_eval do
|
9
|
+
include ArelMysqlIndexHint::ActiveRecordHintMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
ActiveRecord::Querying.class_eval do
|
13
|
+
delegate :hint, :to => :all
|
14
|
+
end
|
15
|
+
|
16
|
+
Arel::Table.class_eval do
|
17
|
+
include ArelMysqlIndexHint::ArelTable
|
18
|
+
end
|
19
|
+
|
20
|
+
Arel::Visitors::MySQL.class_eval do
|
21
|
+
include ArelMysqlIndexHint::ArelVisitorsMySQL
|
22
|
+
end
|
23
|
+
end
|
@@ -1,11 +1,40 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
1
|
+
module ArelMysqlIndexHint
|
2
|
+
module ActiveRecordHintMethods
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
alias_method_chain :build_arel, :mysql_index_hint
|
7
|
+
end
|
8
|
+
|
9
|
+
def mysql_index_hint_value=(value)
|
10
|
+
@values[:mysql_index_hint] = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def mysql_index_hint_value
|
14
|
+
@values[:mysql_index_hint] ||= {}.with_indifferent_access
|
15
|
+
end
|
8
16
|
|
9
|
-
|
10
|
-
|
17
|
+
def hint(index_hint_by_table)
|
18
|
+
mysql_index_hint_value.update(index_hint_by_table)
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_arel_with_mysql_index_hint
|
23
|
+
arel = build_arel_without_mysql_index_hint
|
24
|
+
|
25
|
+
if mysql_index_hint_value.present?
|
26
|
+
if mysql_index_hint_value.values.any? {|i| i.is_a?(Hash) }
|
27
|
+
index_hint_by_table = mysql_index_hint_value
|
28
|
+
else
|
29
|
+
index_hint_by_table = Hash.new(mysql_index_hint_value)
|
30
|
+
end
|
31
|
+
|
32
|
+
arel.ast.select {|i| i.is_a?(Arel::Table) }.each do |node|
|
33
|
+
node.index_hint = index_hint_by_table[node.name]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
arel
|
38
|
+
end
|
39
|
+
end
|
11
40
|
end
|
@@ -1,51 +1,36 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module ArelMysqlIndexHint
|
2
|
+
module ArelVisitorsMySQL
|
3
|
+
extend ActiveSupport::Concern
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
clear_index_hint_by_table
|
7
|
-
retval
|
8
|
-
end
|
9
|
-
|
10
|
-
alias_method_chain :accept, :index_hint
|
11
|
-
|
12
|
-
def visit_Arel_Table_with_index_hint(o, a)
|
13
|
-
sql = visit_Arel_Table_without_index_hint(o, a)
|
14
|
-
index_hint = get_index_hint(o.name)
|
15
|
-
|
16
|
-
if index_hint
|
17
|
-
append_index_hint(sql, index_hint)
|
18
|
-
else
|
19
|
-
sql
|
5
|
+
included do
|
6
|
+
alias_method_chain :visit_Arel_Table, :mysql_index_hint
|
20
7
|
end
|
21
|
-
end
|
22
|
-
|
23
|
-
alias_method_chain :visit_Arel_Table, :index_hint
|
24
8
|
|
25
|
-
|
9
|
+
def visit_Arel_Table_with_mysql_index_hint(o, a)
|
10
|
+
sql = visit_Arel_Table_without_mysql_index_hint(o, a)
|
26
11
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
12
|
+
if o.index_hint
|
13
|
+
append_index_hint(sql, o.index_hint)
|
14
|
+
else
|
15
|
+
sql
|
16
|
+
end
|
32
17
|
end
|
33
18
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
19
|
+
private
|
20
|
+
|
21
|
+
def append_index_hint(sql, index_hint)
|
22
|
+
index_hint_sql = index_hint.map {|index, hint_type|
|
23
|
+
index = Array(index).map {|i| quote_table_name(i) }
|
24
|
+
hint_type = hint_type.to_s.upcase
|
25
|
+
"#{hint_type} INDEX (#{index.join(', ')})"
|
26
|
+
}.join(", ")
|
27
|
+
|
28
|
+
if sql.is_a?(String)
|
29
|
+
sql + " " + index_hint_sql
|
30
|
+
else
|
31
|
+
sql << " " + index_hint_sql
|
32
|
+
sql
|
33
|
+
end
|
38
34
|
end
|
39
35
|
end
|
40
|
-
|
41
|
-
def clear_index_hint_by_table
|
42
|
-
Thread.current[INDEX_HINT_BY_TABLE_THREAD_KEY] = nil
|
43
|
-
end
|
44
|
-
|
45
|
-
def append_index_hint(sql, index_hint)
|
46
|
-
sql + " " + index_hint.map {|index, hint_type|
|
47
|
-
index = Array(index)
|
48
|
-
"#{hint_type} INDEX (#{index.join(', ')})"
|
49
|
-
}.join(", ")
|
50
|
-
end
|
51
36
|
end
|
@@ -6,14 +6,14 @@ describe "arel-mysql-index-hint" do
|
|
6
6
|
eager_load(:microposts).
|
7
7
|
where(microposts: {id: 1}).
|
8
8
|
hint(microposts: {index_microposts_on_user_id_and_created_at: hint_type}).
|
9
|
-
to_sql
|
9
|
+
to_sql.gsub(/\s+/, " ")
|
10
10
|
end
|
11
11
|
|
12
12
|
let(:sql) do
|
13
13
|
"SELECT `users`.`id` AS t0_r0, `users`.`name` AS t0_r1, `users`.`email` AS t0_r2, `users`.`created_at` AS t0_r3, `users`.`updated_at` AS t0_r4, `users`.`password_digest` AS t0_r5, `users`.`remember_token` AS t0_r6, `users`.`admin` AS t0_r7, `microposts`.`id` AS t1_r0, `microposts`.`content` AS t1_r1, `microposts`.`user_id` AS t1_r2, `microposts`.`created_at` AS t1_r3, `microposts`.`updated_at` AS t1_r4 " +
|
14
14
|
"FROM `users` " +
|
15
15
|
"LEFT OUTER JOIN `microposts` " +
|
16
|
-
"#{hint_type} INDEX (index_microposts_on_user_id_and_created_at) " +
|
16
|
+
"#{hint_type.to_s.upcase} INDEX (`index_microposts_on_user_id_and_created_at`) " +
|
17
17
|
"ON `microposts`.`user_id` = `users`.`id` " +
|
18
18
|
"WHERE `microposts`.`id` = 1"
|
19
19
|
end
|
@@ -32,15 +32,15 @@ describe "arel-mysql-index-hint" do
|
|
32
32
|
users: {index_users_on_email: hint_type},
|
33
33
|
microposts: {index_microposts_on_user_id_and_created_at: hint_type},
|
34
34
|
).
|
35
|
-
to_sql
|
35
|
+
to_sql.gsub(/\s+/, " ")
|
36
36
|
end
|
37
37
|
|
38
38
|
let(:sql) do
|
39
39
|
"SELECT `users`.`id` AS t0_r0, `users`.`name` AS t0_r1, `users`.`email` AS t0_r2, `users`.`created_at` AS t0_r3, `users`.`updated_at` AS t0_r4, `users`.`password_digest` AS t0_r5, `users`.`remember_token` AS t0_r6, `users`.`admin` AS t0_r7, `microposts`.`id` AS t1_r0, `microposts`.`content` AS t1_r1, `microposts`.`user_id` AS t1_r2, `microposts`.`created_at` AS t1_r3, `microposts`.`updated_at` AS t1_r4 " +
|
40
40
|
"FROM `users` " +
|
41
|
-
"
|
41
|
+
"#{hint_type.to_s.upcase} INDEX (`index_users_on_email`) " +
|
42
42
|
"LEFT OUTER JOIN `microposts` " +
|
43
|
-
"#{hint_type} INDEX (index_microposts_on_user_id_and_created_at) " +
|
43
|
+
"#{hint_type.to_s.upcase} INDEX (`index_microposts_on_user_id_and_created_at`) " +
|
44
44
|
"ON `microposts`.`user_id` = `users`.`id` " +
|
45
45
|
"WHERE `microposts`.`id` = 1"
|
46
46
|
end
|
@@ -6,14 +6,14 @@ describe "arel-mysql-index-hint" do
|
|
6
6
|
includes(:microposts).
|
7
7
|
where(microposts: {id: 1}).
|
8
8
|
hint(microposts: {index_microposts_on_user_id_and_created_at: hint_type}).
|
9
|
-
to_sql
|
9
|
+
to_sql.gsub(/\s+/, " ")
|
10
10
|
end
|
11
11
|
|
12
12
|
let(:sql) do
|
13
13
|
"SELECT `users`.`id` AS t0_r0, `users`.`name` AS t0_r1, `users`.`email` AS t0_r2, `users`.`created_at` AS t0_r3, `users`.`updated_at` AS t0_r4, `users`.`password_digest` AS t0_r5, `users`.`remember_token` AS t0_r6, `users`.`admin` AS t0_r7, `microposts`.`id` AS t1_r0, `microposts`.`content` AS t1_r1, `microposts`.`user_id` AS t1_r2, `microposts`.`created_at` AS t1_r3, `microposts`.`updated_at` AS t1_r4 " +
|
14
14
|
"FROM `users` " +
|
15
15
|
"LEFT OUTER JOIN `microposts` " +
|
16
|
-
"#{hint_type} INDEX (index_microposts_on_user_id_and_created_at) " +
|
16
|
+
"#{hint_type.to_s.upcase} INDEX (`index_microposts_on_user_id_and_created_at`) " +
|
17
17
|
"ON `microposts`.`user_id` = `users`.`id` " +
|
18
18
|
"WHERE `microposts`.`id` = 1"
|
19
19
|
end
|
@@ -32,15 +32,15 @@ describe "arel-mysql-index-hint" do
|
|
32
32
|
users: {index_users_on_email: hint_type},
|
33
33
|
microposts: {index_microposts_on_user_id_and_created_at: hint_type},
|
34
34
|
).
|
35
|
-
to_sql
|
35
|
+
to_sql.gsub(/\s+/, " ")
|
36
36
|
end
|
37
37
|
|
38
38
|
let(:sql) do
|
39
39
|
"SELECT `users`.`id` AS t0_r0, `users`.`name` AS t0_r1, `users`.`email` AS t0_r2, `users`.`created_at` AS t0_r3, `users`.`updated_at` AS t0_r4, `users`.`password_digest` AS t0_r5, `users`.`remember_token` AS t0_r6, `users`.`admin` AS t0_r7, `microposts`.`id` AS t1_r0, `microposts`.`content` AS t1_r1, `microposts`.`user_id` AS t1_r2, `microposts`.`created_at` AS t1_r3, `microposts`.`updated_at` AS t1_r4 " +
|
40
40
|
"FROM `users` " +
|
41
|
-
"
|
41
|
+
"#{hint_type.to_s.upcase} INDEX (`index_users_on_email`) " +
|
42
42
|
"LEFT OUTER JOIN `microposts` " +
|
43
|
-
"#{hint_type} INDEX (index_microposts_on_user_id_and_created_at) " +
|
43
|
+
"#{hint_type.to_s.upcase} INDEX (`index_microposts_on_user_id_and_created_at`) " +
|
44
44
|
"ON `microposts`.`user_id` = `users`.`id` " +
|
45
45
|
"WHERE `microposts`.`id` = 1"
|
46
46
|
end
|
@@ -5,13 +5,13 @@ describe "arel-mysql-index-hint" do
|
|
5
5
|
User.
|
6
6
|
joins(:microposts).
|
7
7
|
hint(microposts: {index_microposts_on_user_id_and_created_at: hint_type}).
|
8
|
-
to_sql
|
8
|
+
to_sql.gsub(/\s+/, " ")
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:sql) do
|
12
12
|
"SELECT `users`.* FROM `users` " +
|
13
13
|
"INNER JOIN `microposts` " +
|
14
|
-
"#{hint_type} INDEX (index_microposts_on_user_id_and_created_at) " +
|
14
|
+
"#{hint_type.to_s.upcase} INDEX (`index_microposts_on_user_id_and_created_at`) " +
|
15
15
|
"ON `microposts`.`user_id` = `users`.`id`"
|
16
16
|
end
|
17
17
|
|
@@ -39,14 +39,14 @@ describe "arel-mysql-index-hint" do
|
|
39
39
|
users: {index_users_on_email: hint_type},
|
40
40
|
microposts: {index_microposts_on_user_id_and_created_at: hint_type},
|
41
41
|
).
|
42
|
-
to_sql
|
42
|
+
to_sql.gsub(/\s+/, " ")
|
43
43
|
end
|
44
44
|
|
45
45
|
let(:sql) do
|
46
46
|
"SELECT `users`.* FROM `users` " +
|
47
|
-
"#{hint_type} INDEX (index_users_on_email) " +
|
47
|
+
"#{hint_type.to_s.upcase} INDEX (`index_users_on_email`) " +
|
48
48
|
"INNER JOIN `microposts` " +
|
49
|
-
"#{hint_type} INDEX (index_microposts_on_user_id_and_created_at) " +
|
49
|
+
"#{hint_type.to_s.upcase} INDEX (`index_microposts_on_user_id_and_created_at`) " +
|
50
50
|
"ON `microposts`.`user_id` = `users`.`id`"
|
51
51
|
end
|
52
52
|
|
@@ -71,13 +71,13 @@ describe "arel-mysql-index-hint" do
|
|
71
71
|
User.
|
72
72
|
hint(microposts: {index_microposts_on_user_id_and_created_at: hint_type}).
|
73
73
|
joins(:microposts).
|
74
|
-
to_sql
|
74
|
+
to_sql.gsub(/\s+/, " ")
|
75
75
|
end
|
76
76
|
|
77
77
|
let(:sql) do
|
78
78
|
"SELECT `users`.* FROM `users` " +
|
79
79
|
"INNER JOIN `microposts` " +
|
80
|
-
"#{hint_type} INDEX (index_microposts_on_user_id_and_created_at) " +
|
80
|
+
"#{hint_type.to_s.upcase} INDEX (`index_microposts_on_user_id_and_created_at`) " +
|
81
81
|
"ON `microposts`.`user_id` = `users`.`id`"
|
82
82
|
end
|
83
83
|
|
@@ -90,7 +90,7 @@ describe "arel-mysql-index-hint" do
|
|
90
90
|
subject do
|
91
91
|
User.
|
92
92
|
joins(:microposts).
|
93
|
-
to_sql
|
93
|
+
to_sql.gsub(/\s+/, " ")
|
94
94
|
end
|
95
95
|
|
96
96
|
let(:sql) do
|
@@ -5,13 +5,13 @@ describe "arel-mysql-index-hint" do
|
|
5
5
|
where(id: 1).
|
6
6
|
preload(:microposts).
|
7
7
|
hint(users: {index_users_on_email: hint_type}).
|
8
|
-
to_sql
|
8
|
+
to_sql.gsub(/\s+/, " ")
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:sql) do
|
12
12
|
"SELECT `users`.* " +
|
13
13
|
"FROM `users` " +
|
14
|
-
"
|
14
|
+
"#{hint_type.to_s.upcase} INDEX (`index_users_on_email`) " +
|
15
15
|
"WHERE `users`.`id` = 1"
|
16
16
|
end
|
17
17
|
|
@@ -3,13 +3,13 @@ describe "arel-mysql-index-hint" do
|
|
3
3
|
subject do
|
4
4
|
User.
|
5
5
|
hint(index_users_on_email: hint_type).
|
6
|
-
to_sql
|
6
|
+
to_sql.gsub(/\s+/, " ")
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:sql) do
|
10
10
|
"SELECT `users`.* " +
|
11
11
|
"FROM `users` " +
|
12
|
-
"#{hint_type} INDEX (index_users_on_email)"
|
12
|
+
"#{hint_type.to_s.upcase} INDEX (`index_users_on_email`)"
|
13
13
|
end
|
14
14
|
|
15
15
|
let(:hint_type) { :force }
|
@@ -4,13 +4,13 @@ describe "arel-mysql-index-hint" do
|
|
4
4
|
User.
|
5
5
|
all.
|
6
6
|
hint(users: {index_users_on_email: hint_type}).
|
7
|
-
to_sql
|
7
|
+
to_sql.gsub(/\s+/, " ")
|
8
8
|
end
|
9
9
|
|
10
10
|
let(:sql) do
|
11
11
|
"SELECT `users`.* " +
|
12
12
|
"FROM `users` " +
|
13
|
-
"#{hint_type} INDEX (index_users_on_email)"
|
13
|
+
"#{hint_type.to_s.upcase} INDEX (`index_users_on_email`)"
|
14
14
|
end
|
15
15
|
|
16
16
|
let(:hint_type) { :force }
|
@@ -22,13 +22,13 @@ describe "arel-mysql-index-hint" do
|
|
22
22
|
subject do
|
23
23
|
User.
|
24
24
|
hint(users: {index_users_on_email: hint_type}).
|
25
|
-
to_sql
|
25
|
+
to_sql.gsub(/\s+/, " ")
|
26
26
|
end
|
27
27
|
|
28
28
|
let(:sql) do
|
29
29
|
"SELECT `users`.* " +
|
30
30
|
"FROM `users` " +
|
31
|
-
"#{hint_type} INDEX (index_users_on_email)"
|
31
|
+
"#{hint_type.to_s.upcase} INDEX (`index_users_on_email`)"
|
32
32
|
end
|
33
33
|
|
34
34
|
let(:hint_type) { :force }
|
@@ -41,13 +41,13 @@ describe "arel-mysql-index-hint" do
|
|
41
41
|
User.
|
42
42
|
limit(1).
|
43
43
|
hint(users: {index_users_on_email: hint_type}).
|
44
|
-
to_sql
|
44
|
+
to_sql.gsub(/\s+/, " ")
|
45
45
|
end
|
46
46
|
|
47
47
|
let(:sql) do
|
48
|
-
"SELECT
|
48
|
+
"SELECT `users`.* " +
|
49
49
|
"FROM `users` " +
|
50
|
-
"#{hint_type} INDEX (index_users_on_email)
|
50
|
+
"#{hint_type.to_s.upcase} INDEX (`index_users_on_email`) " +
|
51
51
|
"LIMIT 1"
|
52
52
|
end
|
53
53
|
|
@@ -64,8 +64,8 @@ describe "arel-mysql-index-hint" do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
let(:sql) do
|
67
|
-
"SELECT
|
68
|
-
"#{hint_type} INDEX (index_users_on_email)
|
67
|
+
"SELECT `users`.* FROM `users` " +
|
68
|
+
"#{hint_type.to_s.upcase} INDEX (`index_users_on_email`) " +
|
69
69
|
"ORDER BY `users`.`id` ASC " +
|
70
70
|
"LIMIT 1"
|
71
71
|
end
|
@@ -74,7 +74,7 @@ describe "arel-mysql-index-hint" do
|
|
74
74
|
|
75
75
|
it do
|
76
76
|
subject
|
77
|
-
expect(sql_log).to
|
77
|
+
expect(sql_log.first).to eq sql
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -86,8 +86,8 @@ describe "arel-mysql-index-hint" do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
let(:sql) do
|
89
|
-
"SELECT
|
90
|
-
"#{hint_type} INDEX (index_users_on_email)
|
89
|
+
"SELECT `users`.* FROM `users` " +
|
90
|
+
"#{hint_type.to_s.upcase} INDEX (`index_users_on_email`) " +
|
91
91
|
"LIMIT 1"
|
92
92
|
end
|
93
93
|
|
@@ -95,7 +95,7 @@ describe "arel-mysql-index-hint" do
|
|
95
95
|
|
96
96
|
it do
|
97
97
|
subject
|
98
|
-
expect(sql_log).to
|
98
|
+
expect(sql_log.first).to eq sql
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,13 +9,15 @@ if ENV['TRAVIS']
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
require "active_record"
|
12
13
|
require "arel-mysql-index-hint"
|
13
14
|
require "models"
|
14
15
|
|
15
16
|
$__arel_mysql_index_hint_sql_log__ = []
|
16
17
|
|
17
18
|
ActiveSupport::Notifications.subscribe('sql.active_record') do |name, start, finish, id, payload|
|
18
|
-
|
19
|
+
sql = payload[:sql]
|
20
|
+
$__arel_mysql_index_hint_sql_log__ << sql.gsub(/\s+/, " ") if sql
|
19
21
|
end
|
20
22
|
|
21
23
|
RSpec.configure do |config|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -14,28 +14,28 @@ dependencies:
|
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 4.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: arel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 5.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 5.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: appraisal
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: Add index hint to MySQL query in Arel.
|
126
140
|
email:
|
127
141
|
- sgwr_dts@yahoo.co.jp
|
@@ -132,15 +146,18 @@ files:
|
|
132
146
|
- .gitignore
|
133
147
|
- .rspec
|
134
148
|
- .travis.yml
|
149
|
+
- Appraisals
|
135
150
|
- Gemfile
|
136
151
|
- LICENSE.txt
|
137
152
|
- README.md
|
138
153
|
- Rakefile
|
139
154
|
- Schemafile
|
140
155
|
- arel-mysql-index-hint.gemspec
|
156
|
+
- gemfiles/activerecord_4.1.gemfile
|
157
|
+
- gemfiles/activerecord_4.2.gemfile
|
141
158
|
- lib/arel-mysql-index-hint.rb
|
142
159
|
- lib/arel-mysql-index-hint/active_record-hint_methods.rb
|
143
|
-
- lib/arel-mysql-index-hint/
|
160
|
+
- lib/arel-mysql-index-hint/arel-table.rb
|
144
161
|
- lib/arel-mysql-index-hint/arel-visitors-mysql.rb
|
145
162
|
- spec/arel-mysql-index-hint/eager_load_spec.rb
|
146
163
|
- spec/arel-mysql-index-hint/includes_spec.rb
|