Multicolumn indexes and equal conditions

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Multicolumn indexes and equal conditions
Дата
Msg-id 20030414014547.GA19450@wolff.to
обсуждение исходный текст
Список pgsql-performance
I noticed that when a multicolumn index exists it isn't necessarily
fully used when the first column is constrained by an equals condition.
However by adding a redundant sort condition you can get both columns
used.

In the following examples crate has an index on gameid and areaid.

The examples below are for 7.4 development, but 7.3.2 behaves similarly.

explain analyze select areaid from crate where gameid = 'TTN' order by areaid;
                                                         QUERY PLAN
    

----------------------------------------------------------------------------------------------------------------------------
 Sort  (cost=132.93..133.02 rows=36 width=11) (actual time=5.44..5.57 rows=287 loops=1)
   Sort Key: areaid
   ->  Index Scan using crate_game on crate  (cost=0.00..132.00 rows=36 width=11) (actual time=0.06..1.94 rows=287
loops=1)
         Index Cond: (gameid = 'TTN'::text)
 Total runtime: 5.81 msec
(5 rows)


explain analyze select areaid from crate where gameid = 'TTN' order by gameid, areaid;
                                                      QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
 Index Scan using crate_game on crate  (cost=0.00..132.00 rows=36 width=18) (actual time=0.08..2.06 rows=287 loops=1)
   Index Cond: (gameid = 'TTN'::text)
 Total runtime: 2.51 msec
(3 rows)


В списке pgsql-performance по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: update query blows out
Следующее
От: linweidong
Дата:
Сообщение: for help!