public inbox for [email protected]
help / color / mirror / Atom feedFrom: Adrian Klaver <[email protected]>
To: Daniele Varrazzo <[email protected]>
To: Vladimir Ryabtsev <[email protected]>
Cc: [email protected]
Subject: Re: psycopg3, prepared statements
Date: Thu, 24 Dec 2020 08:41:25 -0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <CA+mi_8aoK_wbSQimZ4WHHXZT2YTBPfxLj9Zsbfbx8o=gfBWyaQ@mail.gmail.com>
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]>
<CAMqTPq=G1E=b32JxNo6dGk1-9qGHSCP7Puo5FCqf68nakiBo_Q@mail.gmail.com>
<CA+mi_8YhQVo8xouWnc6hCR6RvE1THRB0Wz0OzHhMHsuvdLNYnw@mail.gmail.com>
<CA+mi_8akdCJC=q9_EH5n5Prj32ttLKCY8-=yncxRr7K8V2mZhw@mail.gmail.com>
<[email protected]>
<CAMqTPq=-CQ6Pm3cjn9j77W7zEqiwz2atxxj+JtbxKYY_xzV-7w@mail.gmail.com>
<CA+mi_8aoK_wbSQimZ4WHHXZT2YTBPfxLj9Zsbfbx8o=gfBWyaQ@mail.gmail.com>
On 12/23/20 4:14 PM, Daniele Varrazzo wrote:
> On Wed, 23 Dec 2020 at 23:23, Vladimir Ryabtsev <[email protected]> wrote:
>>
>> Cause (query, types) can give more combinations than (query,)?
>
> Yes, that's the reason
>
> In [1]: import psycopg3
> In [2]: cnn = psycopg3.connect()
> In [3]: cnn.prepare_threshold = 2
>
> In [4]: cnn.execute("select 1 + %s", [1]).fetchone()
> Out[4]: (2,)
> In [5]: cnn.execute("select 1 + %s", [None]).fetchone()
> Out[5]: (None,)
> In [7]: cnn.execute("select 1 + %s", [2]).fetchone()
> Out[7]: (3,)
Alright, I was misunderstanding. I thought you where referring to
something like:
cur.execute("select * from some table where id > %s and user_name = %s
and current = %s", [2, 'aklaver', True])
>
> After 3 times the expression should have been prepared, but the tally
> has been spread in two values (0 is unknown oid, 20 is int oid).
>
> In [8]: cnn._prepared_statements
> Out[8]: OrderedDict([((b'select 1 + $1', (0,)), 1), ((b'select 1 +
> $1', (20,)), 2)])
>
> In [9]: cnn.execute("select 1 + %s", [3]).fetchone()
> Out[9]: (4,)
>
> However, when either key passes the threshold, eventually preparation happens.
>
> In [10]: cnn._prepared_statements
> Out[10]:
> OrderedDict([((b'select 1 + $1', (0,)), 1),
> ((b'select 1 + $1', (20,)), b'_pg3_0')])
>
> _pg3_0 is the name under which that combination of query and types is
> now prepared (it is local per session).
>
> -- Daniele
>
--
Adrian Klaver
[email protected]
view thread (13+ messages)
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: <[email protected]>
* 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