2015-11-04 24 views
0

哪个会更好地执行搜索SQL表中的一列: -SQl性能b/w喜欢和修剪

喜欢或修剪。

由于本专栏在开始或结束时都有空格,所以两者都能达到目的,但哪一个会更快。

感谢

回答

0

你应该建立一个测试,看看它们是如何执行。在下面的例子中,我使用了dbms_utility.get_time。我测试了两种功能的相同输入,并重复测试以排除任何外部影响。 这是一个“plsql环境”,如果我可以这样调用它,你应该用实际的表和实际的测试来替换查询,并做更多的“sql”测试。

declare 
v_start number; 
v_end number; 
time_trim number:=0; 
time_like number:=0; 
cnt_trim number:=0; 
cnt_like number:=0; 
begin 
for N in 1..10 --repeat test 
loop 
    for type_oper in 1..2 
    loop 
     v_start := dbms_utility.get_time; 
     for k in (
      select 'abc ' as col from dual connect by level <= 100000 
      union all 
      select 'ccc ' as col from dual connect by level <= 100000 
      union all 
      select 'acbc ' as col from dual connect by level <= 100000 
      union all 
      select ' acbc ' as col from dual connect by level <= 100000 
     ) 
     loop 
     if type_oper = 1 then 
      if trim(k.col) = 'abc' then cnt_trim := cnt_trim + 1; end if; 
     else 
      if k.col like '%abc%' then cnt_like := cnt_like + 1; end if; 
     end if; 
     end loop; --end loop table 
     v_end := dbms_utility.get_time; 
     if type_oper = 1 then 
      time_trim := time_trim + v_end-v_start; 
     else 
      time_like := time_like + v_end-v_start; 
     end if; 

    end loop; --end loop type 
end loop; --end loop repeat test 
dbms_output.put_line('time trim:'||time_trim/100); 
dbms_output.put_line('time like:'||time_like/100); 
end; 
/

结果:

CNT修剪:1000000时间修剪:6.33
CNT等:1000000时间等:5.83