Het probleem is dat MySQL 5.0 alle 300k rows uit de chat1 tabel van disk lijkt te lezen en dat duurt extreem lang. Weet iemand hoe ik deze query kan verbeteren zodat het wel in een redelijke tijd gebeurd?
SQL:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| mysql> describe xwi_chat_to; +---------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+---------+------+-----+---------+-------+ | chat_id | int(11) | NO | MUL | | | | nid | int(11) | NO | MUL | | | +---------+---------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> describe xwi_chat1; +---------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+----------------+ | chat_id | int(11) | NO | PRI | NULL | auto_increment | | from | int(11) | NO | MUL | | | | msg | varchar(255) | NO | | | | | time | int(11) | NO | | | | +---------+--------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec) mysql> explain select c.* from xwi_chat1 c inner join xwi_chat_to using (chat_id) where xwi_chat_to.nid in (122) order by chat_id desc limit 1000; +----+-------------+-------------+--------+---------------+---------+---------+-------------------------+--------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------------+--------+---------------+---------+---------+-------------------------+--------+---------------------------------+ | 1 | SIMPLE | xwi_chat_to | ref | chat_id,nid | nid | 4 | const | 298612 | Using temporary; Using filesort | | 1 | SIMPLE | c | eq_ref | PRIMARY | PRIMARY | 4 | xcc.xwi_chat_to.chat_id | 1 | | +----+-------------+-------------+--------+---------------+---------+---------+-------------------------+--------+---------------------------------+ 2 rows in set (0.00 sec) mysql> select chat_id from xwi_chat_to where nid in (122) order by chat_id desc limit 1000; 1000 rows in set (3.74 sec) |