在100K行视图上进行以下简单查询,需要25秒才能处理。
SELECT id
FROM View_MyView
LIMIT 1
视图非常复杂,因为它连接了7个(大多数更小,更小)的表。我正在努力减少这个查询的持续时间,我不清楚这里视图的含义。似乎当从这里涉及的主表(也是100K行)完成SELECT时,性能很好(<1秒)。
我怎么追求这个?
mysql> explain select * from view_myview limit 1
+----+------+--------+--------------------------+----------+--------+----------+------+---------------------------------+
| id | table| type | possible_keys | key | keylen | ref | rows | Extra |
+----+------+--------+--------------------------+----------+--------+----------+------+---------------------------------+
| 1 | tc | ALL | PRIMARY | NULL | NULL | NULL | 16 | Using temporary; Using filesort |
| 1 | t1 | ref | PRIMARY,colr | colr | 2 | tc.id | 28 | Using where |
| 1 | ut | ref | t_id | t_id | 4 | t1.id | 1 | Using index |
| 1 | g | ref | t1_id,t2_id,sp_id,gf_id | t1_id | 4 | ut.t_id | 9 | Using where |
| 1 | gf | eq_ref | PRIMARY | PRIMARY | 2 | g.gf_id | 1 | |
| 1 | t2 | eq_ref | PRIMARY,colr | PRIMARY | 4 | g.t2_id | 1 | |
| 1 | s | eq_ref | PRIMARY | PRIMARY | 1 | g.sp_id | 1 | |
| 1 | tc2 | eq_ref | PRIMARY | PRIMARY | 1 | t2.colr | 1 | |
答案 0 :(得分:0)
View有7个连接和where子句。答案是根据where子句查询第一个选择。这种观点掩盖了我的复杂性。