Question

I have a SELECT query which is using 6 Stored Functions. The Stored Functions are optimized and the query will run in 0.05 seconds when now ORDER BY is used. When I try to ORDER BY the query time drops to 15 seconds.

I tried to use temp tables and tables in memory, but creating these tables take still almost 15 seconds.

I tried to use a view, but then the SELECT with ORDER BY query is still slow.

Example of the query:

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  
ORDER BY (score1 * 1 + score2 * 2 + score3 * 2 + score4 * 4) DESC;

Any help is welcome, thanks!

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top