[BUGS] Query with "LIMIT 1" 10x slower than without LIMIT

Поиск
Список
Период
Сортировка
От Aaron Tate
Тема [BUGS] Query with "LIMIT 1" 10x slower than without LIMIT
Дата
Msg-id CA+U=beDrOXhTJ6sZ10hqgs3AtN_49peHBT=Y0uK6ghTUTyu6OQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: [BUGS] Query with "LIMIT 1" 10x slower than without LIMIT  (John R Pierce <pierce@hogranch.com>)
Список pgsql-bugs
We have a number of queries that do a lot of summarization of data. The base query only returns one row, but due to a Rails quirk, we have to call rel.first to get the first (only) element of the list, which in some cases uses a "LIMIT 1" for the underlying query. With or without the LIMIT 1, the results are identical, but with the LIMIT 1, a 400ms query might take 5000ms to execute.

Please note that this does occur on PostgreSQL version 9.6.1, on Linux or OSX. We can certainly work around it if we're mindful of it, but it's a surprising "gotcha".

Cheers,
Aaron Tate

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

Предыдущее
От: serovov@gmail.com
Дата:
Сообщение: [BUGS] BUG #14807: Query Planner should ignore nulls last/first conditionfor not-null fields in btree index [order by]
Следующее
От: John R Pierce
Дата:
Сообщение: Re: [BUGS] Query with "LIMIT 1" 10x slower than without LIMIT