• λ我爱Aspx >> Asp.Net >> SQL Server 索引结构及其使用(二)
  • SQL Server 索引结构及其使用(二)

  • :未知  Դ:internet  :2007-5-20 16:44:48  ؼ:sql
  • 用时:9秒。扫描计数 8,逻辑读 67489 次,物理读 216 次,预读 7499 次。

    看来,用union在通常情况下比用or的效率要高的多。

    但经过试验,笔者发现如果or两边的查询列是一样的话,那么用union则反倒和用or的执行速度差很多,虽然这里union扫描的是索引,而or扫描的是全表。

    select gid,fariqi,neibuyonghu,reader,title from Tgongwen where fariqi=''2004-9-16'' or fariqi=''2004-2-5''

    用时:6423毫秒。扫描计数 2,逻辑读 14726 次,物理读 1 次,预读 7176 次。

    select gid,fariqi,neibuyonghu,reader,title from Tgongwen where fariqi=''2004-9-16'' union select gid,fariqi,neibuyonghu,reader,title from Tgongwen where fariqi=''2004-2-5''

    用时:11640毫秒。扫描计数 8,逻辑读 14806 次,物理读 108 次,预读 1144 次。

    9、字段提取要按照“需多少、提多少”的原则,避免“select *”

    我们来做一个试验:

    select top 10000 gid,fariqi,reader,title from tgongwen order by gid desc

    用时:4673毫秒

    select top 10000 gid,fariqi,title from tgongwen order by gid desc

    用时:1376毫秒

    select top 10000 gid,fariqi from tgongwen order by gid desc

    Ҷƪл˵?
  • һƪSQL Server 索引结构及其使用(三)
    һƪSQL Server 索引结构及其使用(一)