From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Michael Paquier <michael.paquier@gmail.com>
To: Nikhil Deshpande <ndeshpande@vmware.com>
Cc: PostgreSQL mailing lists <pgsql-odbc@postgresql.org>
Subject: Re: [PATCH] Remove unncessary localtime() calls during data type conversion
Date: Tue, 01 Sep 2015 12:11:56 +0300
Message-ID: <55E56BDC.8020906@iki.fi> (raw)
In-Reply-To: <CAB7nPqT0Hy8yGdEnW7xjdDT2o=9veKhK+=Upap+oYFNCSUbn6Q@mail.gmail.com>
References: <557B7C76.1030502@vmware.com>
<CAB7nPqT0Hy8yGdEnW7xjdDT2o=9veKhK+=Upap+oYFNCSUbn6Q@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>
On 06/14/2015 06:36 AM, Michael Paquier wrote:
> On Sat, Jun 13, 2015 at 9:42 AM, Nikhil Deshpande <ndeshpande@vmware.com> wrote:
>> While doing some profiling work on an ODBC client, we noticed tons
>> of libc localtime() and __tz_convert() calls on a hot code path
>> (SQLFetch()), but most of the fields being retrieved were not of
>> date/time type.
>>
>>
>> These libc calls are costly (non-trivial work in terms of string ops,
>> timzone conversion etc.) and the cost adds up quickly for high-frequency
>> call like SQLFetch(). We noticed that this penalty is paid even
>> for data types which aren't date/time related. Code inspection
>> showed localtime() call in convert.c:copy_and_convert_field()
>> at function start, being invoked regardless of whether output of
>> localtime() is used or not.
>>
>> Attached is a non-intrusive patch that moves the call down
>> to where it's needed (for both getting data from server and
>> sending data to server), but I'm not sure if the patch is complete
>> (it covers the case where source data type is time but
>> destination needs date part, "TIME->DATE[TIME]").
>>
>> Could you please review this patch and modify it for correctness
>> and consider for committing it?
>
> Indeed. I would move as well the declarations of tim more within the
> inner loops.
This changes behaviour, when converting from text to date column.
Without this patch, if the string you're converting from is missing a
year/month/date field, it will be filled with the current date. This
modification to the result-conversions test case shows the difference:
inline patch 1: test/src/result-conversions-test.c (+2/-0 lines) download inline-1.patch--- a/test/src/result-conversions-test.c+++ b/test/src/result-conversions-test.c@@ -626,6 +626,8 @@ int main(int argc, char **argv)
test_conversion("float8", "Infinity", SQL_C_DOUBLE, "SQL_C_DOUBLE", 20);
test_conversion("float8", "-Infinity", SQL_C_DOUBLE, "SQL_C_DOUBLE", 20);
+ test_conversion("text", "", SQL_C_TYPE_DATE, "SQL_C_TYPE_DATE", 20);+
/* Clean up */
test_disconnect();
We don't currently contain tests like that in the test suite, as
mentioned in the comment earlier in result-conversions-test.c:
> /*
> * Converting arbitrary things to date and timestamp produces results that
> * depend on the current timestamp, because the driver substitutes the
> * current year/month/datefor missing values. Disable for now, to get a
> * reproducible result.
> */
Would be nice to include those tests, perhaps by printing the difference
to current date instead of the absolute date.
- Heikki
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: hlinnaka@iki.fi, michael.paquier@gmail.com, ndeshpande@vmware.com
Subject: Re: [PATCH] Remove unncessary localtime() calls during data type conversion
In-Reply-To: <55E56BDC.8020906@iki.fi>
References: <557B7C76.1030502@vmware.com> <CAB7nPqT0Hy8yGdEnW7xjdDT2o=9veKhK+=Upap+oYFNCSUbn6Q@mail.gmail.com> <55E56BDC.8020906@iki.fi>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox