Which is faster — INSTR or LIKE?

前端 未结 4 1865
广开言路
广开言路 2020-11-29 23:04

If your goal is to test if a string exists in a MySQL column (of type \'varchar\', \'text\', \'blob\', etc) which of the following is faster / more efficient / better to use

4条回答
  •  既然无缘
    2020-11-29 23:32

    MySQL - INSTR vs LOCATE vs LIKE vs REGEXP

    For me the INSTR and LOCATE performed the fastest:

    # 5.074 sec
    SELECT BENCHMARK(100000000,INSTR('foobar','foo'));
    
    # 5.086 sec
    SELECT BENCHMARK(100000000,LOCATE('foo','foobar')); 
    
    # 8.990 sec
    SELECT BENCHMARK(100000000,'foobar' LIKE '%foo%');
    
    # 14.433 sec
    SELECT BENCHMARK(100000000,'foobar' REGEXP 'foo'); 
    
    # 5.5.35-0ubuntu0.12.10.2 
    SELECT @@version;
    

提交回复
热议问题