gizzard 0.3.0 → 0.4.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 +4 -4
- data/lib/gizzard/mysql.rb +46 -0
- data/lib/gizzard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 596d0cfa663366781099c024fa3c3c67e81efbc8d51a5da7a28c70eff4600847
|
4
|
+
data.tar.gz: be1352bd27470a2ab2cadd9bec92177e98db7cfe61b380f515ef58b871cd4d6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8111d130463ea240e9e5da53a9addfc663149bbcb99fd7e62016eaf66345d979aa493f44b05b97121ea3cce71383e268af12c22f898862c8f12231920b3b52e
|
7
|
+
data.tar.gz: 3e768b7678325d733e204776945a5636a1ceb6c09d591ace769be251ff81253eea1ea370e3c2f6e4778ab25a0e08dded62e13685b8cf99cf779609c9b2ad6d01
|
data/lib/gizzard/mysql.rb
CHANGED
@@ -30,9 +30,55 @@ module Gizzard
|
|
30
30
|
from("#{table_name} FORCE INDEX(#{Array(indexes).join(', ')})")
|
31
31
|
end
|
32
32
|
|
33
|
+
def joins_with_use_index(relation_name, indexes)
|
34
|
+
joins_with_index_hint(relation_name, indexes, join_type: :inner_join, hint: :use)
|
35
|
+
end
|
36
|
+
|
37
|
+
def joins_with_force_index(relation_name, indexes)
|
38
|
+
joins_with_index_hint(relation_name, indexes, join_type: :inner_join, hint: :force)
|
39
|
+
end
|
40
|
+
|
41
|
+
def left_outer_joins_with_use_index(relation_name, indexes)
|
42
|
+
joins_with_index_hint(relation_name, indexes, join_type: :left_outer_join, hint: :use)
|
43
|
+
end
|
44
|
+
|
45
|
+
def left_outer_joins_with_force_index(relation_name, indexes)
|
46
|
+
joins_with_index_hint(relation_name, indexes, join_type: :left_outer_join, hint: :force)
|
47
|
+
end
|
48
|
+
|
33
49
|
def lock_in_share
|
34
50
|
lock('LOCK IN SHARE MODE')
|
35
51
|
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def joins_with_index_hint(relation_name, indexes, join_type: :inner_join, hint: :use)
|
56
|
+
relation = reflections[relation_name.to_s]
|
57
|
+
join_table_name = relation.klass.table_name
|
58
|
+
|
59
|
+
join = case join_type
|
60
|
+
when :inner_join
|
61
|
+
'INNER JOIN'
|
62
|
+
when :left_outer_join
|
63
|
+
'LEFT OUTER JOIN'
|
64
|
+
else
|
65
|
+
raise
|
66
|
+
end
|
67
|
+
|
68
|
+
index_hint = case hint
|
69
|
+
when :use
|
70
|
+
'USE INDEX'
|
71
|
+
when :force
|
72
|
+
'FORCE INDEX'
|
73
|
+
else
|
74
|
+
raise
|
75
|
+
end
|
76
|
+
|
77
|
+
c = connection
|
78
|
+
joins <<-SQL
|
79
|
+
#{join} #{c.quote_table_name(join_table_name)} #{index_hint} (#{Array(indexes).join(', ')}) ON #{c.quote_table_name(table_name)}.#{c.quote_column_name(relation.association_primary_key)} = #{c.quote_table_name(join_table_name)}.#{c.quote_column_name(relation.foreign_key)}
|
80
|
+
SQL
|
81
|
+
end
|
36
82
|
end
|
37
83
|
|
38
84
|
def to_id
|
data/lib/gizzard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gizzard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takahiro Ooishi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11
|
11
|
+
date: 2019-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|