Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fc9kB-00010u-Ne for pgsql-jdbc@arkaria.postgresql.org; Sun, 08 Jul 2018 13:28:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fc9k9-0007qq-Vd for pgsql-jdbc@arkaria.postgresql.org; Sun, 08 Jul 2018 13:28:49 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fc9k9-0007qb-A0 for pgsql-jdbc@lists.postgresql.org; Sun, 08 Jul 2018 13:28:49 +0000 Received: from sonic316-13.consmr.mail.bf2.yahoo.com ([74.6.130.123]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fc9k5-0008TE-I0 for pgsql-jdbc@lists.postgresql.org; Sun, 08 Jul 2018 13:28:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1531056523; bh=a4SCIzN3yGOAJOk6Voh5XHM5aqF8FgOsxPN8NAOgTa8=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From:Subject; b=qn/NK2cioHnsMV74HR5IGO8+G/9pt1s0D/JkJjxfoHHSpVwUBJZBz2VHaqacyMvW965EGfhpGd2Wh1BAeVo/DP/1HyLXwHrlTqLX5wNiAzvmvH1gEJTf6eOjctteHa5oP4W+JXCM19qifn72R6A211c+RmuPuf+Ql1UmvkxEQqFwXJLYQhPPQsBDo5bTcFff1B8YyL23IIDvBAUGsqCE9SknW/5pdeKicoi3a+tiUphORYRwOe2/un5udYuNzXdPIFKm0vEM/rqlXCpjSN4Ztj06kBtiIUc4hcF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yahoo.com with HTTP; Sun, 8 Jul 2018 13:28:43 +0000 Date: Sun, 8 Jul 2018 13:28:39 +0000 (UTC) From: Alessandro Gherardi To: Vladimir Sitnikov , Craig Ringer Cc: Message-ID: <1813302550.684598.1531056519357@mail.yahoo.com> In-Reply-To: References: <1326195889.5524206.1527300602365.ref@mail.yahoo.com> <1326195889.5524206.1527300602365@mail.yahoo.com> Subject: Re: IN or ANY for batch queries MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_684597_1446473716.1531056519354" X-Mailer: WebService/1.1.12062 YMailNorrin Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 Content-Length: 8604 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_684597_1446473716.1531056519354 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi,Thanks everyone for your feedback. I have one more question. I'm working on enhancing Hibernate to take advantage of WHERE ... =3D ANY(?= ) for batch queries and .The enhancement is specific to postgres so it has = to be added to one of the Hibernate postgres "dialect" classes. Hibernate has separate dialect classes for postgres 8.1, 8.2, 9, 9.1, 9.2, = 9.3, 9.4 and 9.5. Each class extends the previous release class - i.e., 9.5= extends 9.4 which extends 9.3, etc. I'm trying to figure out to which class I should add this enhancement. Idea= lly, it should be the class associated with the earliest release of postgre= s that supports this functionality. I tried to find out in which release WH= ERE ... =3D ANY(?) was first implemented but have had no luck. Does anyone have any idea? Thanks again,Alessandro On Monday, May 28, 2018, 7:01:40 AM MDT, Craig Ringer wrote: =20 =20 On 28 May 2018 at 18:34, Vladimir Sitnikov w= rote: Hi, >However, since in my application the number of values in the array can var= y, I'm wondering if using ANY has the benefit of causing the driver/DB to c= ache a smaller number of prepared statement. Right you are. In case you use Array, the whole thing is passed as a single= bind, and it results in a single prepared statement.Naive use of (?, ?, ?,= ?, ?) would result in multiple prepared statements that would consume memo= ry at both client and server sides. Right. I didn't think you'd do that, I assumed you'd interpolate properly q= uoted SQL literals. Not only is that more vulnerable to potential issues if= your quoting is flawed, it often uses more memory and CPU for the string p= rocessing, so an array bind is definitely better. I had my "writing TAP tests in Perl" hat on, not my "developing sane SQL" h= at on. Sorry.=C2=A0 1) Note: sometimes you might want to use (?, ?, ?) kind of syntax (e.g. to = support DBs that cannot process arrays), then you might want to use "power = of two" placeholders, and fill the excessive ones with null value or with a= repetition of the last value.For instance, if you want to pass 5 values 1,= 2,3,4,5 you'd better pass it as(1,2,3,4,5,5,5,5) (of course, use ?,?,?,?, ?= ,?,?,? ) I do not advice you to use that extensively, however it is a nice to know t= rick. ... ugh. Cool, but gross. --=20 =C2=A0Craig Ringer=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 http://www.2ndQuadrant.= com/ =C2=A0PostgreSQL Development, 24x7 Support, Training & Services =20 ------=_Part_684597_1446473716.1531056519354 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,
Thanks everyone for your feedback. I have one mo= re question.

I'm working on enhancing Hibernate to= take advantage of WHERE ... =3D ANY(?) for batch queries and .The enhancem= ent is specific to postgres so it has to be added to one of the Hibernate p= ostgres "dialect" classes.

Hibernate has separate = dialect classes for postgres 8.1, 8.2, 9, 9.1, 9.2, 9.3, 9.4 and 9.5. Each = class extends the previous release class - i.e., 9.5 extends 9.4 which exte= nds 9.3, etc.

I'm trying to figure out to which cl= ass I should add this enhancement. Ideally, it should be the class associat= ed with the earliest release of postgres that supports this functionality. = I tried to find out in which release WHERE ... =3D ANY(?) was first impleme= nted but have had no luck.

Does anyone have any id= ea?

Thanks again,
Alessandro
<= br>

=20
=20
On Monday, May 28, 2018, 7:01:40 AM MDT, Craig Ringer &= lt;craig@2ndquadrant.com> wrote:


On 28 May 2018 at 18:34, Vladimir Sitnikov = <sitnikov.vladimir@gmail.com= > wrote:
Hi,

>However, since in m= y application the number of values in the array can vary, I'm wondering if = using ANY has the benefit of causing the driver/DB to cache a smaller numbe= r of prepared statement.

<= /div>
Right you are. In case you use Array, the whole thing is pa= ssed as a single bind, and it results in a single prepared statement.
Naive us= e of (?, ?, ?, ?, ?) would result in multiple prepared statements that woul= d consume memory at both client and server sides.


Right. I didn't t= hink you'd do that, I assumed you'd interpolate properly quoted SQL literal= s. Not only is that more vulnerable to potential issues if your quoting is = flawed, it often uses more memory and CPU for the string processing, so an = array bind is definitely better.

I = had my "writing TAP tests in Perl" hat on, not my "developing sane SQL" hat= on. Sorry.
 
1) Note: sometimes you might want to use= (?, ?, ?) kind of syntax (e.g. to support DBs that cannot process arrays),= then you might want to use "power of two" placeholders, and fill the exces= sive ones with null value or with a repetition of the last value.
For instance= , if you want to pass 5 values 1,2,3,4,5 you'd better pass it as
(1,2,3,4,5,5,= 5,5) (of course, use ?,?,?,?, ?,?,?,? )

<= font face=3D"times new roman, new york, times, serif">I do not advice you t= o use that extensively, however it is a nice to know trick.

... ugh. Cool, but= gross.

--
 Craig Ringer       =             http://www.2ndQuadrant.com/
 PostgreSQL D= evelopment, 24x7 Support, Training & Services

------=_Part_684597_1446473716.1531056519354--