VIEW上的SELECT很慢

时间:2013-10-30 08:44:03

标签: mysql view sql-order-by stored-functions

我正在尝试使用视图优化算法查询。我创建了视图:

简化版:

CREATE ALGORITHM = MERGE VIEW view_name AS (SELECT field1, fiedl2, field 3,  
    FUNC1(1, 2) AS score1,  
    FUNC2(1, 2) AS score2,  
    FUNC3(1, 2) AS score3,  
    FUNC4(1, 2) AS score4  
FROM table  
WHERE field1 = 1  
); # only 0.003 seconds - approximate 2000 records

但是当我尝试执行SELECT查询时:

SELECT * FROM view_name  
ORDER BY (score1 * 1 + score2 * 2 + score3 * 2 + score4 * 4) DESC  
LIMIT 0,20; # 9 to 11 seconds

查询大约需要10秒才能得到结果。

我已经尝试了其他一些解决方案,但没有成功,请参阅:
MySQL query slow because of ORDER BY with Stored Functions

如果有人有线索,建议或答案会很棒!

谢谢!

0 个答案:

没有答案