一个有亿条记录的表,列名是 t1,t2,t3................t9
在表上有 t2,t3,t9的复合索引。
现在要求用t3,t9为条件查询全表。
怎么写效率最高?

解决方案 »

  1.   

     select * from 表 where t2=t2 and t3=   and t9=  
      

  2.   

    CREATE INDEX index_tabename
    ON table(t3,t9)
      

  3.   

    select * from 表 where t3=   and t9= 
      

  4.   

    对就是这样
    select   *   from   表   where   t3=       and   t9=   
      

  5.   

    如果where 后面只有 t3 t9  ,这个索引是不起作用的 用到复合索引,没有用到前导列t2
      

  6.   

    2 楼是又重新建了个索引
    要使用这索引 要 T2,T3,T9 一起使用
      

  7.   

    select * from 表 where t3=   and t9= 
      

  8.   

    上面错了,也许是这样
    select * from 表 WITH(INDEX = XXX)where   t3=       and   t9=   
      

  9.   

    Mengmou的好像不对,因为T2没有当前导列出现
      

  10.   

    select   *   from   表   WITH(INDEX   =  indexname )where  t2=t2 and       t3=               and       t9=       
      

  11.   

    mengmou 
     select   *   from   表   WITH(INDEX   =   XXX)where       t3=               and       t9=     和 select * from 表 where t2=t2 and t3=   and t9=  的执行计划是一样的 mengmou  的好一点
      

  12.   

    -- 用到索引的,是index scanselect * from table where t3=    and t9=-- 要求是没有要求用t2
    -- 如果用t2
    -- index seekselect * from table where t2=   and t3=   and t9=  
      

  13.   

    select   *   from   表   where   t3=       and   t9=   就行
    如果加t2
    就按t2= t3= t9= 
      

  14.   

    我测试了下,
    select * from 表 where t2=t2 and t3=  and t9=  

    select * from 表 where t3=  and t9=  
    都用到了上面说的索引,分析的成本也相差无几,可有的书说 select * from 表 where t3=  and t9=  不会用到上面说的索引,真是疑惑?!
      

  15.   

    我做的测试 1楼写的仍然是全表扫描 ojuju10的强制指定index名称才会进行index scan