Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDcJy-0003g4-0T for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Feb 2014 16:05:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WDcJx-0002wI-Gy for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Feb 2014 16:05:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDUuS-0000LE-5f for pgsql-jdbc@postgresql.org; Wed, 12 Feb 2014 08:11:08 +0000 Received: from mail-ee0-x229.google.com ([2a00:1450:4013:c00::229]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDUuP-0003cM-Ld for pgsql-jdbc@postgresql.org; Wed, 12 Feb 2014 08:11:07 +0000 Received: by mail-ee0-f41.google.com with SMTP id e51so3567536eek.0 for ; Wed, 12 Feb 2014 00:11:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:subject:message-id:date:to:mime-version; bh=aNu5T+2n6HSZ60z/q+GsdWdS5/yWNKS6g4NGtIwA2Bw=; b=bRt8X04aCEGSxpW6ddnpNB0F4Wq+qioWOtUUNOeNieFneDMyWCKYjKaa5LyC4B2UKB CbPqk4Pqj08P1wNYqxNdrOtY0d7u3etr7/bTfB7/2P87PJK7CCAFj3NAxrn7bHSEqF9I cpT0FVDUF71vqZ4LKpwzYQXeOwzgJMeZ0Ut0KHaQpBsNVqHs8rVNftPXehqKnmCqg9oF 2jxF88BUJqgz98dFYrxt2N/IPEATKeXo2h0n7exgJRDBuDPfsJ8U0v94kEjfrpZ0Xssi iqgpw4qmlNUHN+qgmRXW/etccZdR9tLCMU6yjigkGVjNkhCZckePo8Qzv4kSPZHdq3DU 11sA== X-Received: by 10.14.202.136 with SMTP id d8mr2349924eeo.46.1392192663460; Wed, 12 Feb 2014 00:11:03 -0800 (PST) Received: from ?IPv6:2001:43f8:30::557b:9264:3cf3:a912? ([2001:43f8:30:0:557b:9264:3cf3:a912]) by mx.google.com with ESMTPSA id 46sm77647974ees.4.2014.02.12.00.11.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Feb 2014 00:11:02 -0800 (PST) From: Mike O Content-Type: multipart/signed; boundary="Apple-Mail=_EFB9684A-CF69-4A43-A518-173CB3CCD858"; protocol="application/pgp-signature"; micalg=pgp-sha1 Subject: Postgres 9.0.4 with Serverside PreparedStatements never returns with large tables Message-Id: <4D32D385-5CB4-4A04-B25B-85656C0EC492@gmail.com> Date: Wed, 12 Feb 2014 10:10:58 +0200 To: pgsql-jdbc@postgresql.org Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) X-Mailer: Apple Mail (2.1510) X-Pg-Spam-Score: -2.0 (--) 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 --Apple-Mail=_EFB9684A-CF69-4A43-A518-173CB3CCD858 Content-Type: multipart/alternative; boundary="Apple-Mail=_6B0FE2D1-786F-45F7-8943-C73F00598885" --Apple-Mail=_6B0FE2D1-786F-45F7-8943-C73F00598885 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii All, I've experienced a problem with the following conditions: PostgreSQL Server 9.0.4 (fine on 9.1.10) JDBC (Any version) Serverside prepared statements (prepareThreshold=3D1) A very large table (30,000,000+ rows) with indexes on int columns Java (any version) The problem is that the serverside prepared statement doesn't return in = good time when querying a large table. It seems that the serverside prepared statement = tries to do something fancy around the parameterised arguments type = inference and casts the arguments as text or varchar which results in = the query not returning on time because it's using a seqscan rather than = an index scan. If I set the protocolVersion =3D 2 then it works fine (assuming I pass = ints to the setObject or setInt functions) I've tried the following connection parameters (in different = configurations) which didn't work: prepareThreshold=3D1 stringType=3Dunspecified protocolVersion=3D3 The following connection parameters worked (either/or): prepareThreshold=3D0 protocolVersion=3D2 Can anyone confirm or deny this bug/issue/feature? I've attached a test class - adjust the query and comment out the = properties as you see fit (Obviously the large data set is going to be a = problem). Kind regards, Mike O'Connell -- If you don't know where you are going, any road will get you there. --Apple-Mail=_6B0FE2D1-786F-45F7-8943-C73F00598885 Content-Type: multipart/mixed; boundary="Apple-Mail=_2F7E0D07-9297-44F6-A712-959897AB4EE7" --Apple-Mail=_2F7E0D07-9297-44F6-A712-959897AB4EE7 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
  • PostgreSQL Server 9.0.4 (fine on = 9.1.10)
  • JDBC (Any version)
  • Serverside prepared = statements (prepareThreshold=3D1)
  • A very large table = (30,000,000+ rows) with indexes on int columns
  • Java (any = version)

  • The problem is that the = serverside prepared statement doesn't return in good time when querying = a large table.

    <massive_assumption> It = seems that the serverside prepared statement tries to do something fancy = around the parameterised arguments type inference and casts the = arguments as text or varchar which results in the query not returning on = time because it's using a seqscan rather than an index scan. = </massive_assumption>

    If I set the = protocolVersion =3D 2 then it works fine (assuming I pass ints to the = setObject or setInt functions)

    I've tried the = following connection parameters (in different configurations) which = didn't work:

    1. prepareThreshold=3D1
    2. stringType=3Dunspec= ified
    3. protocolVersion=3D3

    The = following connection parameters worked = (either/or):

    1. prepareThreshold=3D0
    2. protocolVersion=3D2=

    Can anyone confirm or deny this = bug/issue/feature?

    I've attached a test class - = adjust the query and comment out the properties as you see fit = (Obviously the large data set is going to be a = problem).

    Kind = regards,

    Mike = O'Connell

    0) { Statement stat = connection.createStatement(); stat.execute("set search_path = '" + schema + "';"); stat.close(); } return connection; } } --Apple-Mail=_2F7E0D07-9297-44F6-A712-959897AB4EE7 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii
    --Apple-Mail=_2F7E0D07-9297-44F6-A712-959897AB4EE7-- --Apple-Mail=_6B0FE2D1-786F-45F7-8943-C73F00598885-- --Apple-Mail=_EFB9684A-CF69-4A43-A518-173CB3CCD858 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJS+yySAAoJEMBdfqCg2in4sP4H/24Dtu6hjWoZXaN+TrqW6sRd 6gvBq0oW3v+QDwJxj51WMVL0pij/S1qSRNabu1jd67HvFiZ/V/k0SRgqENz02Q6S VkHAsEmB9f1R8LITdFES5QMRASWClawTHgb69kc36yx2OzRk7OUcpGH7lH3jbMei yxwNQfzndnAvGcH7K9Fw67LyPL6FLHBytMk1lJ+Q4KBxzysYDrq51vyRxH8N1B6C wng0ueW7KWUT6r/wz6N8tJHNOUO8wy4UdZlArUYCKsFdFmvRCwe9ukBCVyyPz92Y p785SCJJTGjoYb06vXGFEsSFlKORpbfHETNUe2k7TSZRZt7JYKPqzPY/aMPiqLg= =X8pX -----END PGP SIGNATURE----- --Apple-Mail=_EFB9684A-CF69-4A43-A518-173CB3CCD858--