百萬級資料量sql優化
阿新 • • 發佈:2018-12-24
sql分頁優化:
1.SELECT * FROM mt_data_subtitle_site_task_download where id > #{id} limit 10;
2.SELECT * FROM mt_data_subtitle_site_task_download where id >= (SELECT id FROM mt_data_subtitle_site_task_download LIMIT #{count }, 1)
總結:最重要還是有效的利用索引去進行分頁查詢
mybatis:
<select id="selectByQueryWithPage" resultMap="ResultMapWithBLOBs"> SELECT * FROM TABLE where id <![CDATA[>=]]> ( SELECT id FROM TABLE where id is not null <if test="status != ''"> and status = #{status} </if> order by id asc LIMIT ${offset},1 ) <if test="status != ''"> and status = #{status} </if> order by id asc limit 10 </select>