我一直在做索引的最后几天有些沉重的阅读和我想以正确的方式找出该索引的查询我有一个很大的制约。我正在使用postgres_ext gem来支持数组数据类型和GIN和GIST索引类型。PostgreSQL中复杂的索引类型和排序
我有两个查询
.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的在使用这两个多列索引第一个查询?
数组数据类型应该总是处于“杜松子酒”索引类型中吗?或者你也可以把它们放在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
请显示您的表定义或等效的Rails模型和PostgreSQL版本。 – 2013-03-09 00:33:43
增加了额外的信息@CraigRinger – 2013-03-09 00:56:57
Re数组和GIN,你可以有一个数组的b-tree索引,但对于像“array contains element”这样的操作没有用。你需要GIN,或者使用'intarray'扩展名和'GiST'索引类型来完成整数阵列,这将在写入负载下表现更好,但在读取负载下会更糟糕。 – 2013-03-09 01:21:00