Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wpvyo-0001ad-0F for pgsql-jdbc@arkaria.postgresql.org; Thu, 29 May 2014 08:46:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Wpvym-0003eD-Vz for pgsql-jdbc@arkaria.postgresql.org; Thu, 29 May 2014 08:46:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Wpvym-0003e7-9z for pgsql-jdbc@postgresql.org; Thu, 29 May 2014 08:46:28 +0000 Received: from mail-db3ln0119.outbound.protection.outlook.com ([2a01:111:f400:7e04::119] helo=emea01-db3-obe.outbound.protection.outlook.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wpvye-0006pS-Lq for pgsql-jdbc@postgresql.org; Thu, 29 May 2014 08:46:26 +0000 Received: from AM2PR07MB0659.eurprd07.prod.outlook.com (25.160.55.150) by AM2PR07MB0659.eurprd07.prod.outlook.com (25.160.55.150) with Microsoft SMTP Server (TLS) id 15.0.949.11; Thu, 29 May 2014 08:46:13 +0000 Received: from AM2PR07MB0659.eurprd07.prod.outlook.com ([25.160.55.150]) by AM2PR07MB0659.eurprd07.prod.outlook.com ([25.160.55.150]) with mapi id 15.00.0949.001; Thu, 29 May 2014 08:46:13 +0000 From: Mikko Tiihonen To: Joshua Engel , "pgsql-jdbc@postgresql.org" Subject: Re: getFastLong gets longs slowly Thread-Topic: [JDBC] getFastLong gets longs slowly Thread-Index: AQHPer+EvJue/hPHRUeZcXXjFJjFNZtXOTJQ Date: Thu, 29 May 2014 08:46:12 +0000 Message-ID: <1401353163152.48455@nitorcreations.com> References: In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [94.101.5.161] x-forefront-prvs: 022649CC2C x-forefront-antispam-report: SFV:NSPM; SFS:(6009001)(428001)(199002)(189002)(164054003)(64706001)(83072002)(66066001)(80022001)(19580395003)(36756003)(20776003)(92726001)(76176999)(79102001)(16236675002)(21056001)(86362001)(92566001)(74502001)(87936001)(4396001)(2656002)(50986999)(76482001)(54356999)(85852003)(81542001)(77982001)(15975445006)(19580405001)(99396002)(81342001)(46102001)(83322001)(101416001)(74662001)(31966008)(19607625010); DIR:OUT; SFP:; SCL:1; SRVR:AM2PR07MB0659; H:AM2PR07MB0659.eurprd07.prod.outlook.com; FPR:; MLV:sfv; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (: nitorcreations.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Mikko.Tiihonen@nitorcreations.com; Content-Type: multipart/alternative; boundary="_000_140135316315248455nitorcreationscom_" MIME-Version: 1.0 X-OriginatorOrg: nitorcreations.com X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org --_000_140135316315248455nitorcreationscom_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable If you use prepared statements the long is transferred as the raw 8 byte re= presentation, not as numeric ascii that needs to be formatted and parsed. B= y default the n-th (3-5 depending on jdbc driver version) invocation of the= prepared statement will switch to the binary representation. If you do not reuse prepared statements you can set the prepareThreshold to= -1 to force the binary transfers from the start (at the cost of extra init= ial round-trip to figure out the exact in/out parameter types). The above setting works at in latest git code. In latest released driver yo= u have to use -Dorg.postgresql.forcebinary=3Dtrue instead. -Mikko ________________________________ From: pgsql-jdbc-owner@postgresql.org on = behalf of Joshua Engel Sent: 29 May 2014 00:54 To: pgsql-jdbc@postgresql.org Subject: [JDBC] getFastLong gets longs slowly I tracked down a performance problem to the JDBC driver's getFastLong funct= ion. For very large long values (in particular, Long.MAX_VALUE and MIN_VALUE), a= special case in getFastLong throws an exception (FAST_NUMBER_FAILED) becau= se it's 19 digits rather than 18. It's then caught and reprocessed using th= e regular long processing code (mostly, deferring to Long.getLong). In the JVMs I'm using (JDK 6 and 7), the delay introduced by that exception= is substantial. It's not large on a per-instance basis but I'm sorting thr= ough a great many records, many of which are MAX_VALUE. Several different p= erformance measurement tools all put the blame right there. I compiled the code myself with larger values for that cutoff, and get a hu= ge performance increase. So... is there a way I can check that change in? And incidentally, while I'm at it... is there any reason it's storing my lo= ng values as binary coded decimal? Can I get it to stop doing that? The who= le point of using a long rather than a string value was presumably to have = it work faster. Thanks, Joshua Engel --_000_140135316315248455nitorcreationscom_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

If you use prepared statements the long is transferred as the raw 8= byte representation, not as numeric ascii that needs to be formatted and p= arsed. By default the n-th (3-5 depending on jdbc driver ver= sion) invocation of the prepared statement will switch to the binary representation.


If you do not reuse prepared statements you can set the prepareThre= shold to -1 to force the binary transfers from the start (at the cost of ex= tra initial round-trip to figure out the exact in/out parameter types).

The above setting works at in latest git code. In latest released d= river you have to use -Dorg.postgresql.forcebinary=3Dtrue instead.


-Mikko


From: pgsql-jdbc-owner@po= stgresql.org <pgsql-jdbc-owner@postgresql.org> on behalf of Joshua En= gel <postgres@purgo.net>
Sent: 29 May 2014 00:54
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] getFastLong gets longs slowly
 
I tracked down a performance problem to the JDBC driver's = getFastLong function.

For very large long values (in particular, Long.MAX_VALUE and MIN_VALU= E), a special case in getFastLong throws an exception (FAST_NUMBER_FAILED) = because it's 19 digits rather than 18. It's then caught and reprocessed usi= ng the regular long processing code (mostly, deferring to Long.getLong).

In the JVMs I'm using (JDK 6 and 7), the delay introduced by that exce= ption is substantial. It's not large on a per-instance basis but I'm sortin= g through a great many records, many of which are MAX_VALUE. Several differ= ent performance measurement tools all put the blame right there.

I compiled the code myself with larger values for that cutoff, and get= a huge performance increase.

So... is there a way I can check that change in?

And incidentally, while I'm at it... is there any reason it's storing = my long values as binary coded decimal? Can I get it to stop doing that? Th= e whole point of using a long rather than a string value was presumably to = have it work faster.

Thanks,
Joshua Engel
--_000_140135316315248455nitorcreationscom_--