public inbox for [email protected]
help / color / mirror / Atom feedFrom: Vladimir Ryabtsev <[email protected]>
To: Adrian Klaver <[email protected]>
Cc: Daniele Varrazzo <[email protected]>
Cc: [email protected]
Subject: Re: psycopg3, prepared statements
Date: Mon, 21 Dec 2020 21:39:19 -0800
Message-ID: <CAMqTPq=G1E=b32JxNo6dGk1-9qGHSCP7Puo5FCqf68nakiBo_Q@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CA+mi_8aAuORkdXZ9bG_GpU34iPCGktMO83ktn+ODjL+Y=Y=e3Q@mail.gmail.com>
<[email protected]>
<CA+mi_8YoZ6_0NM4TbfqE8SQY8-b=RgaBH-jUVxzbWQdp+4oZGQ@mail.gmail.com>
<[email protected]>
> it's a moment in your
> program's lifetime where you know the query to run and the arguments:
> most likely now you want to run the query too, not only to prepare it.
I am just thinking about type issues in some edge cases...
What if the data is such that in the first row it has some small integers,
but on subsequent rows it has larger numbers that do not fit into "integer"?
There are probably other cases similar to this, including "None" values
on the moment you want to capture types... Maybe it is more reliable to
oblige the user, who knows their data better, to explicitly supply the types
for preparation... Will any type inference work in case of types mismatch?
If yes, to what extent?
Generally I think that automatic preparation is a great idea, but if it is
achieved
by sacrificing reliability to any extent, I would prefer to have such a
feature
switched off by default.
> - if more than `connection.prepared_number` queries are prepared, the
> one used least recently is deallocated and evicted from the cache
> (proposed default: 100).
Why do you need such logic? Why not just keep some limited number of
prepared statements? Is it a problem if a PS is in cache but rarely used?
--
Vlad
On Mon, 21 Dec 2020 at 13:55, Adrian Klaver <[email protected]>
wrote:
> On 12/21/20 12:26 PM, Daniele Varrazzo wrote:
> > On Mon, 21 Dec 2020 at 16:02, Adrian Klaver <[email protected]>
> wrote:
> >
>
> >
> > I mistakenly replied Adrian privately. Following, his reply.
> >
>
> > I think so. Personally, I prefer the two step approach as I am becoming
> > less and less enthusiastic about hidden 'magic'. To that end a
> > global(maybe connection) setting that would disable prepare would be
> nice.
> >
> > ----
> >
> > To which, 1) thank you very much, Adrian, for the plpython pointer,
> > I'll take a look at it.
> >
> > 2) About disabling the automatic prepare: the mechanism I have in mind
> > is to set prepare_threshold to None on the connection instance;
>
> So the above is something the user would have to do on each connection?
>
> > however we could make sure to have the default attribute defined on
> > the class: this way who really hates the idea of prepared statements
> > can be cheeky and set `psycopg3.Connection.prepare_threshold = None`
>
> I could get behind that. This all may be premature optimization on my
> part. As long as there is some way to turn it off at some level I could
> live with it.
>
> > instead of `myconn.prepare_threshold`... More seriously, if there is a
> > large base of people who think that something can go wrong with
> > prepared statement we can either provide a better interface to control
> > it globally or to have the feature opt-in.
> >
> >
> > -- Daniele
> >
>
>
> --
> Adrian Klaver
> [email protected]
>
>
>
view thread (13+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: psycopg3, prepared statements
In-Reply-To: <CAMqTPq=G1E=b32JxNo6dGk1-9qGHSCP7Puo5FCqf68nakiBo_Q@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox