Re: NOT EXIST for PREPARE

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: NOT EXIST for PREPARE
Дата
Msg-id CAMsr+YH0x_OA+4rpfk7rFxC_=vzF0e5TA_b4fFSmQPVWY5P-ng@mail.gmail.com
обсуждение исходный текст
Ответ на Re: NOT EXIST for PREPARE  (Andres Freund <andres@anarazel.de>)
Ответы Re: NOT EXIST for PREPARE  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-hackers
On 22 March 2016 at 21:01, Andres Freund <andres@anarazel.de> wrote:
Hi,


On 2016-03-22 12:41:43 +0300, Yury Zhuravlev wrote:
> Do I understand correctly the only way know availability PREPARE it will
> appeal to pg_prepared_statements?
> I think this is not a good practice. In some cases, we may not be aware of
> the PREPARE made (pgpool). Moreover, it seems popular question in the
> Internet: http://stackoverflow.com/questions/1193020/php-postgresql-check-if-a-prepared-statement-already-exists
>
> What do you think about adding NOT EXIST functionality to PREPARE?

Not very much. If you're not in in control of the prepared statements, you
can't be sure it's not an entirely different statement. So NOT EXISTS
doesn't really buy you anything, you'd still need to compare the
statement somehow.
 
Yeah, agreed. I don't buy the reasoning given  for using this in PgJDBC and think it'd just be the source of new and exciting subtle bugs.

I can only see it vaguely working if the client were required to checksum the statement text (or the server was) and compare it with a checksum stored against the prepared statement. On mismatch, ERROR.

If the problem Yuri is trying to solve is with pgbouncer in transaction-pooling mode, wouldn't a possible solution be PREPARE LOCAL ? i.e. transaction-scoped prepared statements? 

With PREPARE IF NOT EXISTS the client is also paying parse and network overhead for every time you send that statement. Much better not to send it repeatedly in the first place. 

I think we need to take a step back here and better define the problem before stepping in with a proposed solution. Something that avoids the need to spam the server with endless copies of the same PREPARE statements would be good.

BTW, PgJDBC doesn't use SQL-level PREPARE anyway, it does it with named portals at the protocol level. You can't add IF NOT EXISTS there, at least not the same way.

--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

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

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: VS 2015 support in src/tools/msvc
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: Bug in searching path in jsonb_set when walking through JSONB array