用我的真实数据进行一些性能测试
t1 => 100,000 行并且还在增长
t2 => 207 行
测试 1
SELECT
t2.fullname,
count(t1.id) AS total
FROM
table_1 AS t1
RIGHT JOIN
table_2 AS t2 ON t1.text REGEXP t2.keyword
GROUP BY t2.fullname
ORDER BY total DESC
212 seconds
测试 2
SELECT
t2.fullname,
count(t1.id) AS total
FROM
table_1 AS t1
RIGHT JOIN
table_2 AS t2 ON t1.text LIKE CONCAT('%', t2.keyword, '%')
GROUP BY t2.fullname
ORDER BY total DESC
30 seconds
测试 3
SELECT
t2.fullname,
count(t1.id) AS total
FROM
table_1 AS t1
RIGHT JOIN
table_2 AS t2 ON t1.text LIKE lower(CONCAT('%', t2.name, '%')) AND t1.text LIKE lower(CONCAT('%', t2.surname, '%'))
GROUP BY t2.fullname
ORDER BY total DESC
32 seconds
测试 4
SELECT
t2.fullname,
count(t1.id) AS total
FROM
table_1 AS t1
RIGHT JOIN
table_2 AS t2 ON t1.text LIKE lower(CONCAT('%', t2.name, '%')) OR t1.text LIKE lower(CONCAT('%', t2.surname, '%'))
GROUP BY t2.fullname
ORDER BY total DESC
40 seconds
测试 5
SELECT
t2.fullname,
count(t1.id) as total
FROM
table_1 as t1
RIGHT JOIN
table_2 as t2 ON t1.text LIKE CONCAT('%', t2.keyword, '%') OR (t1.text LIKE lower(CONCAT('%', t2.name, '%')) AND t1.text LIKE lower(CONCAT('%', t2.surname, '%')))
GROUP BY t2.fullname
ORDER BY total DESC
41 seconds
我会选择测试 5。最佳折衷结果/性能
有什么进一步的建议吗?
再次感谢你的帮助!