Re: Bad query plan decision when using multiple column index -postgresql uses only first column then filters

Поиск
Список
Период
Сортировка
От Laurenz Albe
Тема Re: Bad query plan decision when using multiple column index -postgresql uses only first column then filters
Дата
Msg-id bae745374a919bfa16462750189485cf78b1a5f5.camel@cybertec.at
обсуждение исходный текст
Ответ на Re: Bad query plan decision when using multiple column index -postgresql uses only first column then filters  (Cosmin Prund <cprund@gmail.com>)
Ответы Re: Bad query plan decision when using multiple column index -postgresql uses only first column then filters  (Cosmin Prund <cprund@gmail.com>)
Список pgsql-performance
On Thu, 2020-01-16 at 19:18 +0200, Cosmin Prund wrote:
> Indexes:
>     "PK_LucrareBugetDate" PRIMARY KEY, btree ("LucrareBugetVersiuneId", "LucrareBugetDateId")
>     "IX_LucrareBugetDate_LucrareBugetVersiuneId_LucrareBugetDateId" btree ("LucrareBugetVersiuneId",
"LucrareBugetDateId")
> Foreign-key constraints:
>     "FK_LucrareBugetDate_LucrareBugetVersiune_LucrareBugetVersiuneId" FOREIGN KEY ("LucrareBugetVersiuneId")
REFERENCES"LucrareBugetVersiune"("LucrareBugetVersiuneId") ON DELETE CASCADE
 
> 
> EXPLAIN (ANALYZE, BUFFERS) select "IdRand", "IdColoana", "Valoare" from "LucrareBugetDate" where
("LucrareBugetVersiuneId"= 92) and ("LucrareBugetDateId" in (10,11));
 
>                                                                                       QUERY PLAN
>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>  Index Scan using "IX_LucrareBugetDate_LucrareBugetVersiuneId_LucrareBugetDateId" on "LucrareBugetDate"
(cost=0.56..2.37rows=1 width=13) (actual time=0.096..978.398 rows=2 loops=1)
 
>    Index Cond: ("LucrareBugetVersiuneId" = 92)
>    Filter: ("LucrareBugetDateId" = ANY ('{10,11}'::integer[]))
>    Rows Removed by Filter: 1869178
>    Buffers: shared hit=161178
>  Planning time: 0.699 ms
>  Execution time: 978.433 ms

Well, what should the poor thing do?
There is no index on "LucrareBugetDateId".

Rather, you have two indexes on ("LucrareBugetVersiuneId", "LucrareBugetDateId"),
one of which should be dropped.

Try with an index on "LucrareBugetDateId".

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com




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

Предыдущее
От: Cosmin Prund
Дата:
Сообщение: Re: Bad query plan decision when using multiple column index -postgresql uses only first column then filters
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Bad query plan decision when using multiple column index - postgresql uses only first column then filters