select User,Sex count(*) from table_User
group by User,Sex
table_User上有User,Sex的联合索引
为什么这条语句不走索引?
如果要用索引 应该怎么建立索引?

解决方案 »

  1.   

    索引一般建立在检索数据的列上,如where select_condition_column
    而不是排序或者分组的属性列上;
      

  2.   


    oracle 索引介绍
      

  3.   

    那么大虾 这个语句现在是
    select User,Sex count(*) from table_User 
    where time < to_date('2011-06-17','yyyy-mm-dd')
    group by User,Sex
    stime已经做了索引
    还能有优化的空间吗?
      

  4.   

    最好不要在建有索引的时间字段上使用任何函数,除非建有基于函数的索引。如果time字段上已经建立的索引,那么这种写法就能够很好的利用索引:
    where time < to_date('2011-06-17','yyyy-mm-dd')