Re: psycopg3, prepared statements
От | Karsten Hilbert |
---|---|
Тема | Re: psycopg3, prepared statements |
Дата | |
Msg-id | X+DA52EKAZg6S45N@hermes.hilbert.loc обсуждение исходный текст |
Список | psycopg |
Am Mon, Dec 21, 2020 at 02:24:37PM +0000 schrieb Daniele Varrazzo: > What I'm thinking about is to prepare queries automatically with a schema such: > > - decisions are made after the query is transformed to postgres format > (i.e. it is reduced to bytes, all the client-side manipulations have > been done, placeholders have been transformed to $ format). There is > an object in psycopg3 that takes care of this transformation [2] > - the number of times a query is seen is stored in a LRU cache on the connection > - if a query is seen more than `connection.prepare_threshold` times > (proposed default: 5) then it is prepared with the name > f'pg3_{hash(query)}' and the following executions are prepared. > - if more than `connection.prepared_number` queries are prepared, the > one used least recently is deallocated and evicted from the cache > (proposed default: 100). > - Parameters may be fudged on the connection: prepared_threshold=0 > would prepare all queries, prepared_threshold=None would disable > preparing. > - For the control freak, cursor.execute(query, params, prepare=True) > would prepare the query immediately, if it isn't already, > prepare=False would avoid preparation. The default None would enable > the automatic choice. :-) seems like a well-balanced scheme to me ! Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B
В списке psycopg по дате отправления: