create table a (x int, y int);
create index a_x_y on a(x, y);
我希望像select distinct x from a where y = 1
查詢僅使用索引,而是使用索引由Y篩選,然後做了位圖堆掃描以獲得x的所有值。
---------------------------------------------------------------------------------------------------------------------
HashAggregate (cost=15.03..15.05 rows=2 width=4) (actual time=0.131..0.131 rows=0 loops=1)
-> Bitmap Heap Scan on a (cost=4.34..15.01 rows=11 width=4) (actual time=0.129..0.129 rows=0 loops=1)
Recheck Cond: (y = 1)
-> Bitmap Index Scan on a_x_y (cost=0.00..4.33 rows=11 width=0) (actual time=0.125..0.125 rows=0 loops=1)
Index Cond: (y = 1)
將需要這種類型的查詢什麼樣的指標?
請張貼真實計劃,而不是空表計劃。我們至少需要知道您有多少行,返回了多少行以及需要多少時間。 – Tometzky 2011-03-18 22:10:19