我正在尝试通过使用视图来优化算法查询。我创建了如下视图:
简化版:
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
如果有人有线索、建议或答案,那就太好了!
谢谢!