5

例を挙げてタイトルをよりよく説明しようとします

表 1 の例

Id  text
1   lorem ipsum doe
2   foo bar lorem ipsum jhon
3   bla bla ipsum tommy

表 2 の例

Id  fullname  name  surname  keyword
1   jhon doe  jhon  doe      jhon
2   tom asd   tom   asd      tom
3   sam frf   sam   frr      sam

likeまたはregexpを使用して予想されるテーブルの結果?

fullname  count(*)
jhon doe  2
tom asd   1
sam frf   0

どうもありがとう!

4

2 に答える 2

3

実際のデータを使用したパフォーマンス テスト

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 を選択します。最良の妥協結果/パフォーマンス

さらにアドバイスはありますか?

ご協力いただきありがとうございます。

于 2013-05-10T23:06:43.690 に答える