強制SQL語句使用某個索引

2022-02-22 06:01:41 字數 361 閱讀 5966

sql語句範例:select * fromwith (nolock,index=ix_bydate)where billdate >= '' and billdate < ''

注: ix_bybilldate為此表中根據欄位billdate建立的字段索引。

最近接到客戶反映,某個模組的查詢非常慢,經查,此表有8千萬多條記錄,查某個sql語句時耗時1分18秒,在sql查詢分析器中用ctrl+l來檢視執行計畫時,發現查詢沒有利用到sql索引,而是表掃瞄table scan,

後將sql語句改成最上面的sql語句,就是多加了乙個with (nolock,index=ix_bydate) ,結果查詢速度由1分18秒縮短為不到2秒。

mysql語句強制使用索引

mysql強制使用索引 force index 索引名稱 對table one表中的id新增普通索引,索引名稱為id index。新增語句為 alter table 表名 add index 縮影名稱 列名 查詢語句 select from table one order by id desc li...

mysql強制索引和禁止某個索引

1 mysql強制使用索引 force index 索引名或者主鍵pri 例如 select from table force index pri limit 2 強制使用主鍵 select from table force index ziduan1 index limit 2 強制使用索引 zi...

oracle強制索引使用

強制索引格式 select tablename.from tablename table alias where fieldname 說明 index table alias indexname 必須出現在select 之後,字段之前 tablename 為表名,如果sql中表有別名,則必須使用表的...