Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZWhcG-0007Rt-LM for pgsql-odbc@arkaria.postgresql.org; Tue, 01 Sep 2015 09:12:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZWhcF-0006te-Ob for pgsql-odbc@arkaria.postgresql.org; Tue, 01 Sep 2015 09:12:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZWhbt-0006UZ-4i for pgsql-odbc@postgresql.org; Tue, 01 Sep 2015 09:12:09 +0000 Received: from mail-pa0-x231.google.com ([2607:f8b0:400e:c03::231]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZWhbp-00006O-2N for pgsql-odbc@postgresql.org; Tue, 01 Sep 2015 09:12:08 +0000 Received: by pader10 with SMTP id er10so191014pad.3 for ; Tue, 01 Sep 2015 02:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=Z+gTzl0r7PJrw/kvn6OVuVyfIf09pg9Md+Kt9V4ScIg=; b=w43DyocsLrWKsNoOafV1SBrImip3SMNMwWgtFAZ/Lx0ObWP/2YpL1W40WPbQ+gpcFY dR+iNpiy7JwT1caGahmwbzSCGNtrZ49DlroP3iJVioBkJV9QglWAu1Tmb0Zen0HNg6Br s7KS5iYNjnwiNgZGxvWi6i1ddfdmwSP1+NdszPNDPHRfDKKvVjP0lLhejf609Uhszj3G fIElMdwQMwztRH9C2a2kOEVfdKlTyuv2kzZ7SxKzFak4x8PjtqC41404gblIfQCqsuzH 2gOnLu446rBM/OXp8h82Mokc/5vuvb+FtLup5PhgfdmZryiJ36vEHsUBRUZYyjgrqcNt yb9w== X-Received: by 10.68.57.137 with SMTP id i9mr27817003pbq.101.1441098721963; Tue, 01 Sep 2015 02:12:01 -0700 (PDT) Received: from [10.64.249.126] ([216.253.193.158]) by smtp.gmail.com with ESMTPSA id kn8sm17485883pab.38.2015.09.01.02.11.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Sep 2015 02:12:01 -0700 (PDT) Message-ID: <55E56BDC.8020906@iki.fi> Date: Tue, 01 Sep 2015 12:11:56 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 MIME-Version: 1.0 To: Michael Paquier , Nikhil Deshpande CC: PostgreSQL mailing lists Subject: Re: [PATCH] Remove unncessary localtime() calls during data type conversion References: <557B7C76.1030502@vmware.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org On 06/14/2015 06:36 AM, Michael Paquier wrote: > On Sat, Jun 13, 2015 at 9:42 AM, Nikhil Deshpande 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: --- 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