為什么需要強制索引?
`數據庫沒有使用我們設想的索引進行sql查詢,導致查詢特別慢。`
mysql強制索引查詢語句
select * from test where tt = 1 force index(idx_tt); // 強制索引
select * from test where tt = 1 use index(idx_tt); // 優先按照這種索引查找
laravel中實現強制索引查詢
$this->model
->setTable(DB::connection('test_db')->raw('test' . ' FORCE INDEX(tt)'))
->where('tt', 1)
->get();