數據庫查詢優化方案(處理上百萬級記錄如何提高處理查詢速度)
摘要: 1.對查詢進行優化,應盡量避免全表掃描,首先應考慮在 where 及 order by 涉及的列上建立索引。2.應盡量避免在 where 子句中對字段進行 null 值判斷,否則將導致引擎放棄使用索引而進行全表掃描,如:
select id from t where num is null
可以在num上設置默認值0,確保表中num列沒有null值,然后這樣查詢:
select id from t where num=0 閱讀全文
posted @ 2009-12-19 15:23 MichaelLee 閱讀(10903) | 評論 (6) 編輯