Re: 15x slower PreparedStatement vs raw query

Поиск
Список
Период
Сортировка
От Justin Pryzby
Тема Re: 15x slower PreparedStatement vs raw query
Дата
Msg-id 20210503201811.GA27406@telsasoft.com
обсуждение исходный текст
Ответ на 15x slower PreparedStatement vs raw query  (Alex <cdalxndr@yahoo.com>)
Ответы Re: 15x slower PreparedStatement vs raw query  (Justin Pryzby <pryzby@telsasoft.com>)
Список pgsql-performance
On Sun, May 02, 2021 at 07:45:26PM +0000, Alex wrote:
> PreparedStatement: 15s
> Raw query with embedded params: 1s
> See issue on github with query and explain analyze:
> https://github.com/pgjdbc/pgjdbc/issues/2145

| ..PostgreSQL Version?  12
|Prepared statement
|...
|Planning Time: 11.596 ms
|Execution Time: 14799.266 ms
|
|Raw statement
|Planning Time: 22.685 ms
|Execution Time: 1012.992 ms

The prepared statemnt has 2x faster planning time, which is what it's meant to
improve.

The execution time is slower, and I think you can improve it with this.
https://www.postgresql.org/docs/12/runtime-config-query.html#GUC-PLAN-CACHE_MODE
|plan_cache_mode (enum)
|    Prepared statements (either explicitly prepared or implicitly generated, for example by PL/pgSQL) can be executed
usingcustom or generic plans. Custom plans are made afresh for each execution using its specific set of parameter
values,while generic plans do not rely on the parameter values and can be re-used across executions. Thus, use of a
genericplan saves planning time, but if the ideal plan depends strongly on the parameter values then a generic plan may
beinefficient. The choice between these options is normally made automatically, but it can be overridden with
plan_cache_mode.The allowed values are auto (the default), force_custom_plan and force_generic_plan. This setting is
consideredwhen a cached plan is to be executed, not when it is prepared. For more information see PREPARE.
 

-- 
Justin



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

Предыдущее
От: Alex
Дата:
Сообщение: 15x slower PreparedStatement vs raw query
Следующее
От: Alex
Дата:
Сообщение: Re: 15x slower PreparedStatement vs raw query