I'm trying to optimize my queries by using ColdFusion's Query of Queries feature to access a cached query of about 45,000 words.
With this below query I had lots of success in speed switching to QoQ:
<cfquery name="FindAnagrams" dbtype="query" >
SELECT AllWords.Word, AllWords.AnagramKey
FROM AllWords
WHERE AllWords.WordLength = #i#
</cfquery>
Executions went from ~400ms to ~15ms.
This below query however was only slightly reduced in execution time (from ~500ms to ~400ms):
<cfquery name="TopStartWith" dbtype="query" maxrows="15">
SELECT AllWords.Word
FROM AllWords
WHERE AllWords.Word LIKE <cfoutput>'#Word#%' </cfoutput>
AND AllWords.Word <> '#Word#'
ORDER BY AllWords.Frequency DESC;
</cfquery>
Removing 'Maxrows' did not really help. My Database fields are indexed and I'm ad the end of my knowledge of optimizing queries (Can you index a column of a CF QoQ object?) I suspect it is the 'ORDER BY' that is causing the delay, but am unsure. How can I further improve the speed of such queries? Many thanks.