私は過去数日間、インデックス作成についてかなりの読み物をしてきましたが、多くの制約があるクエリにインデックスを付ける正しい方法を見つけようとしています。配列データ型と GIN および GIST インデックス型をサポートするためにpostgres_ext gemを使用しています。
2つのクエリがあります
.where("a_id IN (?) and b = ? and active = ? and ? != ALL(c) and ? = ANY(d)")
.where("a_id =? and active =? and ? != ALL(c)")
c と d は整数配列です
追加する予定のインデックス:
add_index :deals, [:a, :b], :where => "active = true"
add_index :deals [:c, :d], :index_type => :gin, :where => "active = true"
postgres は最初のクエリでこれらの複数列インデックスの両方を使用しますか?
配列データ型は常に "gin" インデックス型にする必要がありますか? または、それらをbツリーインデックスに入れることもできますか?
最後に、両方のクエリで最初のインデックスが「a」に使用されますか?
追加情報:
PostgreSQL 9.1.3 を使用しています
create_table "table", :force => true do |t|
t.integer "a_id" ##foreign key
t.string "title"
t.text "description", :default => ""
t.boolean "active", :default => true
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "b",
t.integer "c", :limit => 8, :array => true
t.integer "d", :array => true
end