Re: Example code Re: Singleton SELECT inside cursor loop

Поиск
Список
Период
Сортировка
От Peter J. Holzer
Тема Re: Example code Re: Singleton SELECT inside cursor loop
Дата
Msg-id 20221001122000.jq7f5wnmzbewimpn@hjp.at
обсуждение исходный текст
Ответ на Example code Re: Singleton SELECT inside cursor loop  (Ron <ronljohnsonjr@gmail.com>)
Ответы Re: Example code Re: Singleton SELECT inside cursor loop  (Ron <ronljohnsonjr@gmail.com>)
Список pgsql-general
On 2022-10-01 02:22:22 -0500, Ron wrote:
> I extracted the singleton into a function, and that helped me isolate the
> problem.

I don't know what a singleton select is (duckduckgo tells me it has
something to do with DB2 and/or COBOL, or maybe it's a whisky), but:


> Note how quickly it runs the first five times, but takes 780x longer the
> sixth time I run it.  Exiting psql and entering again causes the same
> slowness the sixth time it's run.

PostgresSQL evaluates the exact plan the first 5 times it encounters the
same prepared query. After that it switches to a generic plan if it
thinks that the generic plan isn't worse than the specialized plans.

If the plan suddenly gets worse after 5 executions, you've probably run
into a case where the generic plan is worse although the cost computed
by the planner isn't.

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Вложения

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

Предыдущее
От: "Peter J. Holzer"
Дата:
Сообщение: Names of run-time configuration parameters (was: Limiting the operations that client-side code can perform upon its database backend's artifacts)
Следующее
От: Christoph Moench-Tegeder
Дата:
Сообщение: Re: Example code Re: Singleton SELECT inside cursor loop