質問編集履歴
2
追加情報
test
CHANGED
File without changes
|
test
CHANGED
@@ -74,7 +74,7 @@
|
|
74
74
|
|
75
75
|
|
76
76
|
|
77
|
-
###追加情報
|
77
|
+
###追加情報1
|
78
78
|
|
79
79
|
|
80
80
|
|
@@ -173,3 +173,81 @@
|
|
173
173
|
) ENGINE=InnoDB AUTO_INCREMENT=45097 DEFAULT CHARSET=utf8mb4 |
|
174
174
|
|
175
175
|
```
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
###追加情報2
|
180
|
+
|
181
|
+
**offsetの数が大きくなるほど遅くなります**
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
offsetの数が49700の場合は6秒もかかってしまいました
|
186
|
+
|
187
|
+
```MySQL
|
188
|
+
|
189
|
+
mysql> select * from `repositories` where `stars_per_day` is not null and `repositories`.`checked_at` > '2016-12-13 11:59:34.000000' order by `stars_per_day` desc limit 10 offset 49700;
|
190
|
+
|
191
|
+
10 rows in set (6.50 sec)
|
192
|
+
|
193
|
+
```
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
offsetの数が0の場合は爆速です
|
198
|
+
|
199
|
+
```ここに言語を入力
|
200
|
+
|
201
|
+
mysql> select * from `repositories` where `stars_per_day` is not null and `repositories`.`checked_at` > '2016-12-13 11:59:34.000000' order by `stars_per_day` desc limit 10 offset 0;
|
202
|
+
|
203
|
+
10 rows in set (0.01 sec)
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
**Extraは変わりありませんでした**
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
force indexを付け加えた場合
|
214
|
+
|
215
|
+
```ここに言語を入力
|
216
|
+
|
217
|
+
mysql> explain select * from `repositories` force index (idx_1) where `stars_per_day` is not null and `repositories`.`checked_at` > '2016-12-13 11:59:34.000000' order by `stars_per_day` desc limit 10 offset 49700;
|
218
|
+
|
219
|
+
+----+-------------+--------------+------------+-------+---------------+-------+---------+------+-------+----------+-----------------------+
|
220
|
+
|
221
|
+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
222
|
+
|
223
|
+
+----+-------------+--------------+------------+-------+---------------+-------+---------+------+-------+----------+-----------------------+
|
224
|
+
|
225
|
+
| 1 | SIMPLE | repositories | NULL | range | idx_1 | idx_1 | 5 | NULL | 19628 | 33.33 | Using index condition |
|
226
|
+
|
227
|
+
+----+-------------+--------------+------------+-------+---------------+-------+---------+------+-------+----------+-----------------------+
|
228
|
+
|
229
|
+
1 row in set, 1 warning (0.00 sec)
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
force indexを付け加えない場合
|
236
|
+
|
237
|
+
```ここに言語を入力
|
238
|
+
|
239
|
+
mysql> explain select * from `repositories` where `stars_per_day` is not null and `repositories`.`checked_at` > '2016-12-13 11:59:34.000000' order by `stars_per_day` desc limit 10 offset 49700;
|
240
|
+
|
241
|
+
+----+-------------+--------------+------------+-------+---------------+-------+---------+------+-------+----------+-----------------------+
|
242
|
+
|
243
|
+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
244
|
+
|
245
|
+
+----+-------------+--------------+------------+-------+---------------+-------+---------+------+-------+----------+-----------------------+
|
246
|
+
|
247
|
+
| 1 | SIMPLE | repositories | NULL | range | idx_1,idx_2 | idx_1 | 5 | NULL | 19628 | 50.00 | Using index condition |
|
248
|
+
|
249
|
+
+----+-------------+--------------+------------+-------+---------------+-------+---------+------+-------+----------+-----------------------+
|
250
|
+
|
251
|
+
1 row in set, 1 warning (0.00 sec)
|
252
|
+
|
253
|
+
```
|
1
情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -71,3 +71,105 @@
|
|
71
71
|
)
|
72
72
|
|
73
73
|
```
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
###追加情報
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
データーベース情報は以下のようになりました。何故かMySQLクライアントからだと高速に発行できます
|
82
|
+
|
83
|
+
```Mysql
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
mysql> EXPLAIN select count(*) as aggregate from `repositories` where `stars_per_day` is not null and `repositories`.`checked_at` > '2016-12-13 07:48:38.000000';
|
88
|
+
|
89
|
+
+----+-------------+--------------+------------+-------+--------------------------+---------------+---------+------+-------+----------+-----------------------------------------------+
|
90
|
+
|
91
|
+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
92
|
+
|
93
|
+
+----+-------------+--------------+------------+-------+--------------------------+---------------+---------+------+-------+----------+-----------------------------------------------+
|
94
|
+
|
95
|
+
| 1 | SIMPLE | repositories | NULL | range | stars_per_day,checked_at | stars_per_day | 5 | NULL | 16287 | 50.00 | Using index condition; Using where; Using MRR |
|
96
|
+
|
97
|
+
+----+-------------+--------------+------------+-------+--------------------------+---------------+---------+------+-------+----------+-----------------------------------------------+
|
98
|
+
|
99
|
+
1 row in set, 1 warning (0.00 sec)
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
mysql> EXPLAIN select * from `repositories` where `stars_per_day` is not null and `repositories`.`checked_at` > '2016-12-13 07:48:38.000000' order by `stars_per_day` desc limit 10 offset 0;
|
106
|
+
|
107
|
+
+----+-------------+--------------+------------+-------+--------------------------+---------------+---------+------+-------+----------+------------------------------------+
|
108
|
+
|
109
|
+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
110
|
+
|
111
|
+
+----+-------------+--------------+------------+-------+--------------------------+---------------+---------+------+-------+----------+------------------------------------+
|
112
|
+
|
113
|
+
| 1 | SIMPLE | repositories | NULL | range | stars_per_day,checked_at | stars_per_day | 5 | NULL | 16287 | 50.00 | Using index condition; Using where |
|
114
|
+
|
115
|
+
+----+-------------+--------------+------------+-------+--------------------------+---------------+---------+------+-------+----------+------------------------------------+
|
116
|
+
|
117
|
+
1 row in set, 1 warning (0.01 sec)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
mysql> show create table repositories;
|
124
|
+
|
125
|
+
| repositories | CREATE TABLE `repositories` (
|
126
|
+
|
127
|
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
128
|
+
|
129
|
+
`repository_id` int(11) NOT NULL,
|
130
|
+
|
131
|
+
`full_name` varchar(255) DEFAULT NULL,
|
132
|
+
|
133
|
+
`name` varchar(255) DEFAULT NULL,
|
134
|
+
|
135
|
+
`master_branch` varchar(255) DEFAULT NULL,
|
136
|
+
|
137
|
+
`readme` longtext,
|
138
|
+
|
139
|
+
`stargazers_count` int(11) DEFAULT NULL,
|
140
|
+
|
141
|
+
`language_id` int(11) DEFAULT NULL,
|
142
|
+
|
143
|
+
`description` longtext,
|
144
|
+
|
145
|
+
`description_ja` longtext,
|
146
|
+
|
147
|
+
`homepage` longtext,
|
148
|
+
|
149
|
+
`created_at` datetime DEFAULT NULL,
|
150
|
+
|
151
|
+
`updated_at` datetime DEFAULT NULL,
|
152
|
+
|
153
|
+
`pushed_at` datetime DEFAULT NULL,
|
154
|
+
|
155
|
+
`stars_per_day` float DEFAULT NULL,
|
156
|
+
|
157
|
+
`similar_repositories` longtext,
|
158
|
+
|
159
|
+
`checked_at` datetime DEFAULT NULL,
|
160
|
+
|
161
|
+
`avatar_url` longtext,
|
162
|
+
|
163
|
+
PRIMARY KEY (`id`),
|
164
|
+
|
165
|
+
UNIQUE KEY `repositories_repository_id` (`repository_id`),
|
166
|
+
|
167
|
+
KEY `stars_per_day` (`stars_per_day`),
|
168
|
+
|
169
|
+
KEY `checked_at` (`checked_at`),
|
170
|
+
|
171
|
+
FULLTEXT KEY `repositories` (`full_name`,`name`,`description`)
|
172
|
+
|
173
|
+
) ENGINE=InnoDB AUTO_INCREMENT=45097 DEFAULT CHARSET=utf8mb4 |
|
174
|
+
|
175
|
+
```
|