我不明白爲什麼我的查詢正在執行順序掃描。Postgresql不使用我的索引
select columns
from table
where (column_1 ilike '%whatever%' or column_2 ilike '%whatever%')
我在column_1和column_2上都有一個索引。
兩列的基數都很高。
我的表格大約有2500萬行。
您認爲我可能會做錯什麼?無論我做什麼,它總是進行順序掃描。
編輯#1: 我的指標是這樣的:
Create index xxx on table (column_1, column_2);
編輯#2: 更改我的SQL查詢來
select columns
from table
where (column_1 ilike 'whatever%' and column_2 ilike 'whatever%')
仍然取得了我的查詢使用順序掃描。當我剛剛使用like
而不是ilike
時,我得到了相同的結果。但此查詢:
select columns
from table
where (column_1 = 'whatever' and column_2 = whatever)
使我的查詢使用索引掃描和我的查詢就快得多:)
請參閱:http://dba.stackexchange.com/q/144899/1822 –