zoukankan      html  css  js  c++  java
  • 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) ...也许你能从数据中再发现些什么欢迎补充

  • 相关阅读:
    Class.forName和ClassLoader.loadClass的区别
    数据库连接池优化配置(druid,dbcp,c3p0)
    MySQL在默认事务下各SQL语句使用的锁分析
    ArrayList vs LinkedList 空间占用
    MySQL锁详解
    利用ConcurrentHashMap来实现一个ConcurrentHashSet
    list与Set、Map区别及适用场景
    实现一个原子的正整数类:AtomicPositiveInteger
    mysql如何处理亿级数据,第一个阶段——优化SQL语句
    java性能优化
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1990083.html
Copyright © 2011-2022 走看看