Re: LIMIT clause extremely slow

Поиск
Список
Период
Сортировка
От Laurenz Albe
Тема Re: LIMIT clause extremely slow
Дата
Msg-id 235e74c6189774e822d51f3504adbd223de9beb3.camel@cybertec.at
обсуждение исходный текст
Ответ на LIMIT clause extremely slow  ("Melzer Kassensysteme" <office@melzer-kassen.com>)
Список pgsql-bugs
On Wed, 2023-11-15 at 17:46 +0100, Melzer Kassensysteme wrote:
> SELECT * FROM table WHERE (index1 > 1 OR (index1 = 1 AND index2 > 5)) ORDER BY index1, index2 LIMIT 1
>  
> index1 and index2 are index fields of datatype integer.
>  
> This takes some 100 times longer than in Mysql or other databases

This is not a bug; at worst, it is a performance problem.

For good performance, rewrite the query to

  SELECT * FROM "table"
  WHERE (index1, index2) > (1, 5)
  ORDER BY index1, index2
  LIMIT 1;

and make sure you have an index on (index1, index2).

Yours,
Laurenz Albe



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

Предыдущее
От: Laurenz Albe
Дата:
Сообщение: Re: BUG #18196: Databases Created in Turkish Language Will Not Run on the Latest Version of Windows
Следующее
От: Halil Han Badem
Дата:
Сообщение: Re: BUG #18196: Databases Created in Turkish Language Will Not Run on the Latest Version of Windows