voice_file表有2000条数据,search_job_result表有250万条。
sqlString = "select  v.voice_file_id,time_to_sec(v.duration) as duration,   " +
"v.audio_channel,v.create_time,  s.confidence_score,s.phrase_id,  " +
"time_to_sec(s.start_time) as start_time,  time_to_sec(s.end_time) as end_time " +
"from   (select confidence_score, phrase_id, start_time, end_time, voice_file_id " +
"from search_job_result limit "+(j * 100000)+",100000"+") s, voice_file v where s.voice_file_id = v.voice_file_id";其中参数j是外层一个for循环的传入参数。即for(int j=0;j<25;j++).现在的问题是当j为10以内时,查询速度很快,而j数值越大时,查询速度越来越慢。大家能帮我分析其中的原因吗?

解决方案 »

  1.   

    做了个实验分别是limit 0,100000和limit 2300000,100000
    果然后者的速度很慢,而前者很快。为什么呢,是否是因为limit a,b中的a需要大量时间去locate
      

  2.   

    MYSQL需要逐一记录处理到a,然后再取出b条记录。实质上MYSQL依然是处理了 a+b 条记录,只不过是仅仅显示了b条记录而已。
      

  3.   

    问题解决了,现在速度超快,办法是在黑体字上建立索引    sqlString = "select v.voice_file_id,time_to_sec(v.duration) as duration, " + "v.audio_channel,v.create_time, s.confidence_score,s.phrase_id, " + "time_to_sec(s.start_time) as start_time, time_to_sec(s.end_time) as end_time " + "from (select confidence_score, phrase_id, start_time, end_time, voice_file_id " + "from search_job_result limit "+(j * 100000)+",100000"+") s, voice_file v where s.voice_file_id = v.voice_file_id";
      

  4.   


    关键问题不在于select里面的索引
    而是在于where里面的索引
    刚好你的voice_file_id在where里面
    所以速度才超快
      

  5.   

    建立的复合索引在SQL语句 中使用到了
      

  6.   

    是的,confidence_score, phrase_id, start_time, voice_file_id四个是复合主键,而end_time是索引
      

  7.   

    不对,在调优之前,confidence_score, phrase_id, start_time, voice_file_id四个是复合主键,end_time什么都不是,当在end_time上建立索引后,速度超快。很明显是end_time影响了性能。