Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ksDJR-0004jp-EL for psycopg@arkaria.postgresql.org; Wed, 23 Dec 2020 23:12:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ksDJQ-0000pL-7G for psycopg@arkaria.postgresql.org; Wed, 23 Dec 2020 23:12:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ksDJP-0000p8-AA for psycopg@lists.postgresql.org; Wed, 23 Dec 2020 23:12:56 +0000 Received: from [64.147.123.20] (helo=wout4-smtp.messagingengine.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ksDJL-00044Y-8o for psycopg@postgresql.org; Wed, 23 Dec 2020 23:12:54 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id DDC46885; Wed, 23 Dec 2020 18:12:38 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 23 Dec 2020 18:12:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=Y LX2YIIgcQdFlsmWO88KD1lk3zNaEYdF7SMDIjEGXdc=; b=aGTYVpfnLq/ZZYkN0 dcNzzg++dhMaK6en5hddSd4RnDPovKVpZ6Qs1Wl+R8+YxT9Ar+66uy3yGt0NVRsV mj5zR7vU9oDNFGQUzk4LHlUb4SYIkDJFYQt/6/wniMq/nXs00R07TXkKFiGpd/Ji pFZX/zLhjibjykR9KeYjybN2SP6CnzE0/lGEa2l7z8ChtxGP8FyeRB22BgRBzSte eo/tVTxz6ZaRaEiietyW8rpzd2/3NOmwiVrIm9As0pHYWo+NeYQ0pj6SIHrffP3J bkts4xhDDTiZ/b1gHqZIevKLdiaR+5kvQKCLD/dIrcfNO8QFD+c3Ws4IooDMFCu8 vUKUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=YLX2YIIgcQdFlsmWO88KD1lk3zNaEYdF7SMDIjEGX dc=; b=IbzDqNhB/btAVuL5mMxS/SqbC1PqikhGnJjrSeeQrTbFXTx3eqjEiIOo2 J3Gvw9qHj/8zjg16mmlczpN2U7eBXB1npqJApi0ik0iK5rk/IKX801KpWv46Q6Kv aB0gyA2EjrEPm/IISkZnoQHC5KvIU6BVDjtM8d/lDttpmOhmcE+Vi2TwFd7nS+eo QOI6nMbOp+tgPs0J6O4S7WLAk1vL3UYSPhsJIJuzAUxIhJUwfLi+t6RkRqTgmzOU 7/Kx/ANGNZGXmOfb74p0VjgUXYnNrjjViJG7qdEVpUUclpzG61/whtRV/k9h2Jdx zlLrovhHL8UofbRGYWcc7TzWxBNRA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddtkedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpefgffeiffffgfehtdeufeelfeeuudffteelfeegleel teehgedvveefvdelleeukeenucffohhmrghinhepghhithhhuhgsrdgtohhmnecukfhppe ejhedrudejvddrudegrddujeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.4] (75-172-14-17.tukw.qwest.net [75.172.14.17]) by mail.messagingengine.com (Postfix) with ESMTPA id B7EB0240057; Wed, 23 Dec 2020 18:12:37 -0500 (EST) Subject: Re: psycopg3, prepared statements To: Daniele Varrazzo , Vladimir Ryabtsev Cc: psycopg@postgresql.org References: <25a137a0-9ad3-bb9f-b008-263dcc81a645@aklaver.com> <331f273f-fc13-8d80-b209-c94c0960268b@aklaver.com> From: Adrian Klaver Message-ID: Date: Wed, 23 Dec 2020 15:12:36 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 64.147.123.20 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/23/20 2:53 PM, Daniele Varrazzo wrote: > On Tue, 22 Dec 2020 at 22:36, Daniele Varrazzo > wrote: >> >> On Tue, 22 Dec 2020 at 05:39, Vladimir Ryabtsev wrote: > > > Heads up about this: it's better than I thought! > > I wrote a first implementation of the prepared statements cache using > the query as a key, but it's actually enough to use the (query, types) > tuple in order to tell apart statements that are executed with > different types. This way even the "SELECT %s" case won't be a > problem. Of course a statement executed with a mix of types will be > prepared later than `prepare_threshold`, but I think it's perfectly Alright I was following you until you got to above. I'm not following why it would overshoot prepare_threshold? > acceptable: the case doesn't happen often and having the query > prepared after 10 times instead of 5 doesn't change much if it will be > executed hundreds of times or more. > > What seems a feature-complete branch is available in [1]. The tests > [2] illustrate the main behaviour of the prepared statements system. > > [1]: https://github.com/psycopg/psycopg3/tree/prepared-statements>. > [2]: https://github.com/psycopg/psycopg3/blob/prepared-statements/tests/test_prepared.py > > Off to do some benchmarks now... > > -- Daniele > -- Adrian Klaver adrian.klaver@aklaver.com