回答編集履歴
1
chousei
test
CHANGED
@@ -1,3 +1,61 @@
|
|
1
1
|
テーブル構成はいじれるのでしょうか?
|
2
2
|
|
3
3
|
生成列を使えばインデックスを貼れるので効率的に検索ができそうですが
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
# 追記
|
8
|
+
|
9
|
+
テーブルがいじれないのでは意味がありませんが、参考までに
|
10
|
+
|
11
|
+
```SQL
|
12
|
+
|
13
|
+
create table tbl(
|
14
|
+
|
15
|
+
id int,
|
16
|
+
|
17
|
+
name_1 varchar(10),
|
18
|
+
|
19
|
+
name_2 varchar(10),
|
20
|
+
|
21
|
+
h_phone1 varchar(10),
|
22
|
+
|
23
|
+
h_phone2 varchar(10),
|
24
|
+
|
25
|
+
h_phone3 varchar(10),
|
26
|
+
|
27
|
+
m_phone1 varchar(10),
|
28
|
+
|
29
|
+
m_phone2 varchar(10),
|
30
|
+
|
31
|
+
m_phone3 varchar(10)
|
32
|
+
|
33
|
+
);
|
34
|
+
|
35
|
+
insert into tbl(id,name_1,name_2,h_phone1,h_phone2,h_phone3,m_phone1,m_phone2,m_phone3) values
|
36
|
+
|
37
|
+
(1,'佐藤','太郎','000','1111','2222','000','3333','4444'),
|
38
|
+
|
39
|
+
(2,'佐藤','太郎','000','1111','2222','000','1111','2222'),
|
40
|
+
|
41
|
+
(3,'佐藤','太郎','000','3333','4444','000','3333','4444'),
|
42
|
+
|
43
|
+
(4,'佐藤','次郎','000','1111','2222','000','1111','2222'),
|
44
|
+
|
45
|
+
(5,'佐藤','三郎','000','1111','2222','000','3333','4444');
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
に対して生成列を追加してインデックスを貼る
|
50
|
+
|
51
|
+
```SQL
|
52
|
+
|
53
|
+
alter table tbl add name varchar(20) as (concat(name_1,name_2));
|
54
|
+
|
55
|
+
alter table tbl add h_phone varchar(20) as (concat(h_phone1,h_phone2,h_phone3));
|
56
|
+
|
57
|
+
alter table tbl add m_phone varchar(20) as (concat(m_phone1,m_phone2,m_phone3));
|
58
|
+
|
59
|
+
alter table tbl add index(name,h_phone,m_phone);
|
60
|
+
|
61
|
+
```
|