當前位置:首頁 » 操作系統 » 千萬級資料庫查詢優化

千萬級資料庫查詢優化

發布時間: 2023-08-18 10:39:58

㈠ 怎麼樣提高千萬級SQL資料庫查詢速度

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

3.應盡量避免在 where 子句中使用!=或<>操作符,否則將引擎放棄使用索引而進行全表掃描。

4.應盡量避免在 where 子句中使用 or 來連接條件,否則將導致引擎放棄使用索引而進行全表掃描,如:

select id from t where num=10 or num=20

可以這樣查詢:

select id from t where num=10

union all

select id from t where num=20

5.in 和 not in 也要慎用,否則會導致全表掃描,如:

select id from t where num in(1,2,3)

對於連續的數值,能用 between 就不要用 in 了:

select id from t where num between 1 and 3

6.下面的查詢也將導致全表掃描:

select id from t where name like '%abc%'

若要提高效率,可以考慮全文檢索。

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:646
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:937
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:633
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:822
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:732
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1067
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:300
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:161
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:853
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:764