Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qTSMw-009e6G-7H for pgsql-jdbc@arkaria.postgresql.org; Tue, 08 Aug 2023 19:27:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qTSMu-000LpN-6s for pgsql-jdbc@arkaria.postgresql.org; Tue, 08 Aug 2023 19:27:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qTSMt-000LpE-S4 for pgsql-jdbc@lists.postgresql.org; Tue, 08 Aug 2023 19:27:48 +0000 Received: from mail-db5eur01olkn081c.outbound.protection.outlook.com ([2a01:111:f400:fe02::81c] helo=EUR01-DB5-obe.outbound.protection.outlook.com) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qTSMm-001GHf-K4 for pgsql-jdbc@postgresql.org; Tue, 08 Aug 2023 19:27:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=alz/So+hEZFZ9tUOlpTtsdNJTvfPXtTk4trpbs1CNrMsv+wg2smfZ9aC/ZOmo7SudWw2ru5uVOjnSTkMktJpZpP/L5J/lSeXX0eNMxk5XZn2o2I3mMlJy0sMh4UO9YRI1YnOVz+v+euaCV9U1oJ56hXQkFaB6PfookRU7D7DZ00SVsr7SxXiEr+WhbMa3wHsGDYHu0QDPU1MGFF0oi+HAtNVTYlU1qVWYQPvVFSTYTYwyBAVYVipMBM7buN/nYuVbGlOhFqHaQ9/nIl3VnQpuGHd/2i4Go97TcyhGSuFAVT4D+JfSALnEedOYq2ROAdfbSter4xyjjCLOc+vkqONjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NIV0taRtxcqtQW+DNLXUjNEC6RMysjmDjD0jVEHXKb0=; b=OHblRTZ/0tgcebB+e1rcdFhO9q0sL8/N7DgLY0qvCqQqSACsnsZdPWirBkOLfGorKVqD/5lOgii4rVpfQwLFNpjYtdevc/xLnM/3LtexJ82vLa8ACSHegBuEDcYYotbTHKw90tHepqNCfLVx9W7nApBWs3uA28uaPv8pqdXQriYLD9Q9LNuMmHirs8Ybw8kz9/m3UH2lqKv0Q0+V30tAZN6Hvpdx1z3IrkJf/WFVJRHPNO46tvVwgr5VAxCvZVXOIGuDMX3ErjbRwRukfzpvuxkgj4bdVGkOB2KBjRbSv4Gh7HJrRnwsi3nmQX1ihlwCm2AD5Oj4lhFA6wamY8T6uA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PRAP192MB1628.EURP192.PROD.OUTLOOK.COM (2603:10a6:102:298::14) by PAWP192MB2227.EURP192.PROD.OUTLOOK.COM (2603:10a6:102:35d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.27; Tue, 8 Aug 2023 19:27:36 +0000 Received: from PRAP192MB1628.EURP192.PROD.OUTLOOK.COM ([fe80::5630:f1fa:a34d:3300]) by PRAP192MB1628.EURP192.PROD.OUTLOOK.COM ([fe80::5630:f1fa:a34d:3300%4]) with mapi id 15.20.6652.026; Tue, 8 Aug 2023 19:27:36 +0000 From: ihab sabiq To: "pgsql-jdbc@postgresql.org" Subject: PrepareStatement and parameters data types Thread-Topic: PrepareStatement and parameters data types Thread-Index: AQHZyi4lMynpkbjX9kyRTclbgNizhQ== Date: Tue, 8 Aug 2023 19:27:35 +0000 Message-ID: Accept-Language: fr-FR, en-US Content-Language: fr-FR X-MS-Has-Attach: X-MS-TNEF-Correlator: x-tmn: [KmnDB40Ri7yIgbXca2q9CBwd5n5wZpPv] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PRAP192MB1628:EE_|PAWP192MB2227:EE_ x-ms-office365-filtering-correlation-id: 8e670e77-6074-41a6-986f-08db98458551 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dEre2/1STUin88GNWGGQf40Kc+Z4POUGProW7pOtPC3PZo8h5C7DNTGp8Zmsmx7cl8Q8iPQsSaNLu6qeWeAVfgcP1UjtMqsDKFYGYZRfz9J96J7UNMozyyU1vyd0ebQcSyK9qXs+HlIk1eB2TD6N8nRMwlk10a892+CFxxKzkkFC8DB3FA3uHsoXRU09E+uv1gycmd/dkmIWcfWTTSRjsmVn5Sx0D10agn4eKS8pt7Z1v3eA0vdimM7ZlWZqj9zq2SS/w4VF/hxUwYB2rXuFC1bkcGw/UlKBMhXFkiVQ4b69C6SK9CcBIyYEXbAPBWMRk+Bx66K48LIQV2Ct/oSaWQSjbRsKCRrpI956wmItkUFQfl/C60gAjAemVqUXAYBiFD5XaFX/rZox2Ztj9pqaB0JpeS3UmMYDbnx4DdH0TbLhCO0tKmJPAWoao1fp3yD+HNw3Agmrpbm0jAkMXqzjmxk2Bp/GhBAWh53Qy7WucNsKs5K0QzJun4fcCLNdWF2MvV7506CorMCPeq8odDLoo+BQPcvQBAdi7lX4QgoucT+snk6wsYkQe5jKdRXe/fYq x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?zYe8qVYr0obgArMM7VgBMts90ESmyMfx3KYdT1s39M0sgBp+oN+yeO0LK8xv?= =?us-ascii?Q?0LaJu7E3SDpQE8NVOrUXlR0rLcC7xCERzWgdI8naJeLoacRxhgSd6PGed3Bt?= =?us-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oqH801Xr1oPhp+9uwpv1h+2kASWoa3?= =?us-ascii?Q?gqB9dbZo/5Fy/SezJQcOJF4aKc5J8ewCWqPxF/5MfnzChuY9Zc3wqg5nKC1R?= =?us-ascii?Q?XsCY6vSxVaGg985Fvo4VRDylOr7zz5NUGshQj45snAOVJqATZy88IEDwAajp?= =?us-ascii?Q?sk635RsUXd+Gu6Hfx1sA5DlYTLnD1W2GEed2Vqp7+XRFepudGEeXQVTyqgeh?= =?us-ascii?Q?R3DPNot1q6JoXC8y+UngqPigfN24Chnd8FG84TZKw9eqDxp4ltt/zIaLbs0?= =?us-ascii?Q?=3D?= Content-Type: multipart/alternative; boundary="_000_PRAP192MB16285D5564F9EFEFDAAD1AC2FE0DAPRAP192MB1628EURP_" MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-fb43a.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PRAP192MB1628.EURP192.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 8e670e77-6074-41a6-986f-08db98458551 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2023 19:27:35.9484 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWP192MB2227 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_PRAP192MB16285D5564F9EFEFDAAD1AC2FE0DAPRAP192MB1628EURP_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, I was doing some experimenting to try and reduce the execution time of a qu= ery used in a PreparedStatement. To do that, I normally use the Prepare and= Execute statements of Postgresql. What I notice is that explicit casting h= as a considerable performance impact. So using the good data types in the P= repare and avoid casting gives much better performance. My questions are : * Does the implementation of PreparedStatment in Postgresql driver uses= the Prepare and Execute * If so why I cannot see the Prepare and the parameters type in the log= s if not how can I simulate the same mechanism from the command line * Is it possible to avoid explicit casting without getting the error co= uld not determine data type of parameter The query is bit complex on large tables but the main part is : cast($1 as= text) is null or cast($2 as text) is null or ( field < cast(cast($3 as tex= t) as date) and field > cast(cast($4 as text) as date) ) Thanks for your help. Sabiq --_000_PRAP192MB16285D5564F9EFEFDAAD1AC2FE0DAPRAP192MB1628EURP_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Hello,

I was doing some experimenting to try and reduce the execution tim= e of a query used in a PreparedStatement. To do that, I normally use the Pr= epare and Execute statements of Postgresql. What I notice is that explicit casting has a considerable performance impa= ct. So using the good data types in the Prepare and avoid casting gives muc= h better performance. My questions are :
  • Does the implementation of PreparedStatment in Postgresql driver = uses the Prepare and Execute
  • If so why I cannot see th= e Prepare and the parameters type in the logs if not how can I simulate the= same mechanism from the command line
  • Is it possible t= o avoid explicit casting without getting the error could not determ= ine data type of parameter
The query is bit complex on large tables but the main par= t is :  cast($1 as text) is null or cast($2 as text) is null or ( fiel= d < cast(cast($3 as text) as date) and field > cast(cast($4 as text) as date) )

Thanks for your help.

Sabiq
--_000_PRAP192MB16285D5564F9EFEFDAAD1AC2FE0DAPRAP192MB1628EURP_--