Re: WIP: libpq: add a possibility to not send D(escribe) when executing a prepared statement

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: WIP: libpq: add a possibility to not send D(escribe) when executing a prepared statement
Дата
Msg-id 3666238.1701018825@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: WIP: libpq: add a possibility to not send D(escribe) when executing a prepared statement  (Ivan Trofimov <i.trofimow@yandex.ru>)
Ответы Re: WIP: libpq: add a possibility to not send D(escribe) when executing a prepared statement  (Ivan Trofimov <i.trofimow@yandex.ru>)
Список pgsql-hackers
Ivan Trofimov <i.trofimow@yandex.ru> writes:
> Afaik changing prepared statement result structure is prohibited by
> Postgres server-side, and should always lead to "ERROR: cached plan
> must not change result type", see src/test/regress/sql/plancache.sql.

Independently of whether we're willing to guarantee that that will
never change, I think this patch is basically a bad idea as presented.
It adds a whole new set of programmer-error possibilities, and I doubt
it saves enough in typical cases to justify creating such a foot-gun.

Moreover, it will force us to devote attention to the problem of
keeping libpq itself from misbehaving badly in the inevitable
situation that somebody passes the wrong tuple descriptor.
That is developer effort we could better spend elsewhere.

I say this as somebody who deliberately designed the v3 protocol
to allow clients to skip Describe steps if they were confident
they knew the query result type.  I am not disavowing that choice;
I just think that successful use of that option requires a client-
side coding structure that allows tying a previously-obtained
tuple descriptor to the current query with confidence.  The proposed
API fails badly at that, or at least leaves it up to the end-user
programmer while providing no tools to help her get it right.

Instead, I'm tempted to suggest having PQprepare/PQexecPrepared
maintain a cache that maps statement name to result tupdesc, so that
this is all handled internally to libpq.  The main hole in that idea
is that it's possible to issue PREPARE, DEALLOCATE, etc via PQexec, so
that a user could possibly redefine a prepared statement without libpq
noticing it.  Maybe that's not a big issue.  For a little more safety,
we could add some extra step that the library user has to take to
enable caching of result tupdescs, whereupon it's definitely caller
error if she does that and then changes the statement behind our back.

BTW, the submitted patch lacks both documentation and tests.
For a feature like this, there is much to be said for writing
the documentation *first*.  Having to explain how to use something
often helps you figure out weak spots in your initial design.

            regards, tom lane



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

Предыдущее
От: Ivan Trofimov
Дата:
Сообщение: Re: WIP: libpq: add a possibility to not send D(escribe) when executing a prepared statement
Следующее
От: Shay Rojansky
Дата:
Сообщение: Re: Missing docs on AT TIME ZONE precedence?