質問編集履歴
1
fix
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
|
24
24
|
### 聞きたいこと
|
25
25
|
SQL1はwhere句でfirst_name, last_nameを指定しているので作成済みのインデックスの通りindexが利用されています。
|
26
|
-
SQL2はwhere句で
|
26
|
+
SQL2はwhere句でfirst_nameのみを指定しているのですがpossible_keysがあるのでindexが利用されているように見ます。
|
27
27
|
|
28
28
|
Q1. 複合インデックスを作っている場合、where句で1つだけを指定してもインデックスが効きますか?
|
29
29
|
(B木で作成されるインデックスは複数列専用では無く、1つだけの場合も考慮された構造になっているのでしょうか?)
|
@@ -38,15 +38,17 @@
|
|
38
38
|
|
39
39
|
SQL2
|
40
40
|
```SQL
|
41
|
-
select * from users where first_name = 'tarou1'
|
41
|
+
select * from users where first_name = 'tarou1'
|
42
|
-
explain select * from users where first_name = 'tarou1'
|
42
|
+
explain select * from users where first_name = 'tarou1'
|
43
43
|
```
|
44
44
|
|
45
|
+
|
45
46
|
---
|
46
47
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
47
48
|
| ---: | --- | --- | --- | --- | --- | --- | --- | ---: | --- |
|
48
|
-
| 1 | SIMPLE | users | ref | first_name_last_name | first_name_last_name |
|
49
|
+
| 1 | SIMPLE | users | ref | first_name_last_name | first_name_last_name | 50 | const | 1 | Using index condition |
|
49
50
|
|
50
51
|
|
52
|
+
|
51
53
|
### 補足情報(FW/ツールのバージョンなど)
|
52
54
|
- 10.2.12-MariaDB
|