diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2023-12-27 19:46:43 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2023-12-28 02:47:56 +0100 |
commit | a70fc447652c92c3f19651c1ad27b5a31852b077 (patch) | |
tree | d532edc4d54ab9a4a54e4f03df681368adb79c26 | |
parent | 042fd36ada2cff0bd96e6235c92268119b2af261 (diff) | |
download | gallery-a70fc447652c92c3f19651c1ad27b5a31852b077.tar.gz gallery-a70fc447652c92c3f19651c1ad27b5a31852b077.tar.xz gallery-a70fc447652c92c3f19651c1ad27b5a31852b077.zip |
Optimize search query
-rw-r--r-- | main.go | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -968,11 +968,16 @@ const searchCTE = `WITH JOIN matches AS m ON m.sha1 = ta.sha1 ), scoredtags(tag, score) AS ( + -- The cross join is a deliberate optimization, + -- and this query may still be really slow. SELECT st.tag, AVG(IFNULL(ta.weight, 0)) AS score - FROM supertags AS st, matches AS m + FROM matches AS m + CROSS JOIN supertags AS st LEFT JOIN tag_assignment AS ta ON ta.sha1 = m.sha1 AND ta.tag = st.tag GROUP BY st.tag + -- Using the column alias doesn't fail, but it also doesn't work. + HAVING AVG(IFNULL(ta.weight, 0)) >= 0.01 ) ` |