• 300万条记录 like 和 charindex 函数性能比较


    300万条记录 like 和 charindex 函数性能比较

    环境:sql2005

    数据量:300万

    查询结果数据量:127221

    机器环境

    P4 3.0双核 1G内存

    1. 执行语句

    --无索引

    select count(*) from testing where [name] like '%00%'

    select count(*) from testing where charindex('00',[name])>0

    --有索引

    select id from testing where [name] like '%00%'

    select id from testing where charindex('00',[name])>0

    --查询字段全部为索引

    select id,[name] from testing where [name] like '%00%'

    select id,[name] from testing where charindex('00',[name])>0

    --查询所有字段

    select * from testing where [name] like '%00%'

    select * from testing where charindex('00',[name])>0

     

    --查询字段不全部为索引

    select id,bname from testing where [name] like '%00%'

    select id,bname from testing where charindex('00',[name])>0

    2. 没有 索引的情况下测试

     

    结论:

    a) 在完全没有添加索引时 charindex函数的性能比like好

    3. 为name字段添加索引测试:

     

    结论:

    a) charindex函数的性能比like好

    b) 检索的全部为索引项耗时要少的多,性能提升很高

    4. 对单字段查询测试

     

    结论:

    a) charindex函数的性能比like好

    5. 对查询字段全部为索引项的测试

     

    结论:

    a) charindex函数的性能比like好

    6. 对表全字段查询测试

     

    结论:

    a) charindex函数的性能比like略好

    7. 查询同等列数一个字段为索引项一个不是索引项字段的测试

     

    结论:

    a) charindex函数的性能比like略好

    b) bname不为索引项查询的速度近似于第一的测试。

    总结:

    a) 在模糊查询时用charindex函数比用like性能好

    b) 查询的字段数量越多速度越慢,在查询时只查需要的字段

    c) 查询字段中如果有字段不为索引项则查询的速度和无索引时差不多即使where条件查询字段是索引项

    d) ...也许你能从数据中再发现些什么欢迎补充

  • 相关阅读:
    表单提交时,更新的操作
    提交后刷新本页面与移除本页面的JS写法
    jquery的$.each如何退出循环和退出本次循环
    修改本机host文件,使upf报表操作变的快
    代码记录
    JQuery简介
    Ubuntu安装
    PHP笔记(PHP高级篇)
    将Session写入Memcache
    将Session写入数据库
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1990083.html
Copyright © 2020-2023  润新知