2015-05-26 55 views
-1

我有5个布尔列的表。为布尔列创建索引

on_stock | paid | received_payment | on_the_way | received 

如何为此表创建索引?我应该这样做吗?我想优化这样的查询:

SELECT "order".* FROM "order" INNER JOIN "seller_users" ON "order"."seller_foreign_id" = "seller_users"."google_id" 
WHERE(((("order"."on_stock" <> true AND "order"."on_the_way" <> true) AND "order"."paid" <> true) AND "order"."received_payment" <> true) AND "order"."received" <> true) AND ("seller_users"."google_id" = '[email protected]') 
ORDER BY "order"."updated_at" DESC ; 

当我尝试添加此索引 - 什么也没有发生。该索引未被使用。

add_index :order, [:on_stock, :on_the_way, :paid, :received_payment, :received], :name => "state_index" 

如果我为每列添加单独的index - 没有任何反应。

EXPLAIN ANALYZE输出: http://explain.depesz.com/s/FS2

+0

您必须为每列创建单独的“索引”。 – usmanali

+0

@usmanali,它没有改变任何东西。 –

+1

请你可以在EXPLAIN ANALYZE输出中作为文本[编辑]。或者将其粘贴到http://explain.depesz.com – IMSoP

回答

1

你的表具有共8行的,不需要在此情况下的指标。测试这8行中的每一行与where子句相比,在这里使用索引要快得多。