MySQL中Join算法实现原理分析
2009-04-04 11:18:13 来源:WEB开发网使用Query如下:
1 select m.subject msg_subject, c.content msg_content
2
3 from user_group g,group_message m,group_message_content c
4
5 where g.user_id = 1
6
7 and m.group_id = g.group_id
8
9 and c.group_msg_id = m.id
看看我们的 Query 的执行计划:
1 sky@localhost : example 11:17:04> explain select m.subject msg_subject, c.content msg_content
2
3 -> from user_group g,group_message m,group_message_content c
4
5 -> where g.user_id = 1
6
7 -> and m.group_id = g.group_id
8
9 -> and c.group_msg_id = m.idG
10
11 *************************** 1. row ***************************
12
13 id: 1
14
15 select_type: SIMPLE
16
17 table: g
18
19 type: ref
20
21 possible_keys: user_group_gid_ind,user_group_uid_ind,user_group_gid_uid_ind
22
23 key: user_group_uid_ind
24
25 key_len: 4
26
27 ref: const
28
29 rows: 2
30
31 Extra:
32
33 *************************** 2. row ***************************
34
35 id: 1
36
37 select_type: SIMPLE
38
39 table: m
40
41 type: ref
42
43 possible_keys: PRIMARY,idx_group_message_gid_uid
44
45 key: idx_group_message_gid_uid
46
47 key_len: 4
48
49 ref: example.g.group_id
50
51 rows: 3
52
53 Extra:
54
55 *************************** 3. row ***************************
56
57 id: 1
58
59 select_type: SIMPLE
60
61 table: c
62
63 type: ref
64
65 possible_keys: idx_group_message_content_msg_id
66
67 key: idx_group_message_content_msg_id
68
69 key_len: 4
70
71 ref: example.m.id
72
73 rows: 2
74
75 Extra:
更多精彩
赞助商链接