質問編集履歴
2
テーブルの設計を表からcreate文に変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,21 +8,39 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
```ここに言語を入力
|
12
12
|
|
13
|
-
|
13
|
+
CREATE TABLE `enters` (
|
14
14
|
|
15
|
-
|
15
|
+
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
16
16
|
|
17
|
-
|
17
|
+
`event_id` BIGINT UNSIGNED NOT NULL,
|
18
18
|
|
19
|
-
|
19
|
+
FOREIGN KEY (event_id) REFERENCES events(id),
|
20
20
|
|
21
|
-
|
21
|
+
`name` varchar(255),
|
22
22
|
|
23
|
-
|
23
|
+
`status` TINYINT UNSIGNED NOT NULL,
|
24
24
|
|
25
|
+
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
26
|
+
|
27
|
+
`edited_at` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
28
|
+
|
29
|
+
);
|
30
|
+
|
31
|
+
|
32
|
+
|
25
|
-
|
33
|
+
CREATE TABLE `events` (
|
34
|
+
|
35
|
+
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
36
|
+
|
37
|
+
`name` varchar(255),
|
38
|
+
|
39
|
+
(省略)
|
40
|
+
|
41
|
+
);
|
42
|
+
|
43
|
+
```
|
26
44
|
|
27
45
|
|
28
46
|
|
1
誤字修正、補足説明追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -70,13 +70,13 @@
|
|
70
70
|
|
71
71
|
[SELECT...] ORDER BY created_at ASC LIMIT 1000
|
72
72
|
|
73
|
-
[SELECT...] W
|
73
|
+
[SELECT...] WHERE event_id = 1 ORDER BY created_at DESC
|
74
74
|
|
75
|
-
[SELECT...] W
|
75
|
+
[SELECT...] WHERE event_id = 1 AND status = 0 ORDER BY created_at ASC LIMIT 1000
|
76
76
|
|
77
|
-
[SELECT...] W
|
77
|
+
[SELECT...] WHERE event_id = 1 AND status = 0 AND created_at >= '2020-01-01 00:00:00'
|
78
78
|
|
79
|
-
[SELECT...] W
|
79
|
+
[SELECT...] WHERE created_at BETWEEN '2020-01-01 00:00:00' AND '2020-12-31 23:59:59' ORDER BY created_at DESC
|
80
80
|
|
81
81
|
```
|
82
82
|
|
@@ -88,7 +88,7 @@
|
|
88
88
|
|
89
89
|
上記を踏まえ、まず最初の画面初期表示時に発行されるクエリの為に、"created_at"カラムにインデックスが必要だとは思うのですが、
|
90
90
|
|
91
|
-
それ以外のカラムについてはクエリのパターンが多く、どのようにすべきか悩んでいます。
|
91
|
+
それ以外のカラムについては"発行されるクエリ例"のようにクエリのパターンが多く、どのようにすべきか悩んでいます。
|
92
92
|
|
93
93
|
あらゆるパターンを考慮して複合インデックス含め作成しておくべきでしょうか。
|
94
94
|
|