Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtcNg-0001pP-4l for pgsql-performance@arkaria.postgresql.org; Fri, 11 Jan 2013 11:02:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TtcNf-0002Q0-Lv for pgsql-performance@arkaria.postgresql.org; Fri, 11 Jan 2013 11:02:35 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtcNe-0002Pv-VA for pgsql-performance@postgresql.org; Fri, 11 Jan 2013 11:02:35 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtcNY-00036Q-Ry for pgsql-performance@postgresql.org; Fri, 11 Jan 2013 11:02:34 +0000 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 9CCD828700; Fri, 11 Jan 2013 03:02:25 -0800 (PST) Received: from zcs-prod-ext-mta-1.vmware.com (zcs-prod-ext-mta-1.vmware.com [10.113.62.223]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 971FA184FF; Fri, 11 Jan 2013 03:02:25 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id 658EE121991; Fri, 11 Jan 2013 03:04:28 -0800 (PST) X-Virus-Scanned: amavisd-new at zcs-prod-ext-mta-1.vmware.com Received: from zcs-prod-ext-mta-1.vmware.com ([127.0.0.1]) by localhost (zcs-prod-ext-mta-1.vmware.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R-ur7QzCOt02; Fri, 11 Jan 2013 03:04:28 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id 3E0D1121993; Fri, 11 Jan 2013 03:04:28 -0800 (PST) X-Virus-Scanned: amavisd-new at zcs-prod-ext-mta-1.vmware.com Received: from zcs-prod-ext-mta-1.vmware.com ([127.0.0.1]) by localhost (zcs-prod-ext-mta-1.vmware.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id X_bQK2iB2hQ9; Fri, 11 Jan 2013 03:04:28 -0800 (PST) Received: from [192.168.1.90] (unknown [10.113.62.14]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTPSA id 44D73121991; Fri, 11 Jan 2013 03:04:27 -0800 (PST) Message-ID: <50EFF145.1050306@vmware.com> Date: Fri, 11 Jan 2013 13:02:29 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121122 Icedove/10.0.11 MIME-Version: 1.0 To: Matheus de Oliveira CC: pgsql-performance , Charles Gomes Subject: Re: Partition insert trigger using C language References: <50EF0E81.1010808@vmware.com> <50EF14F1.5070901@vmware.com> <50EFE74B.9040007@vmware.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 11.01.2013 12:36, Matheus de Oliveira wrote: > On Fri, Jan 11, 2013 at 8:19 AM, Heikki Linnakangas> wrote: > >> One thing that caught my eye: >> >> CREATE OR REPLACE FUNCTION partition_insert_trigger_spi() >>> RETURNS trigger >>> LANGUAGE C >>> VOLATILE STRICT >>> AS 'partition_insert_trigger_spi'**,'partition_insert_trigger_**spi' >>> SET DateStyle TO 'ISO'; >> >> Calling a function with SET options has a fair amount of overhead, to >> set/restore the GUC on every invocation. That should be avoided in a >> performance critical function like this. > > I (stupidly) used SPI_getvalue [1] and expected it to always return as > YYYY-MM-DD, but them I remembered it would do that only with DateStyle=ISO. > > But the truth is that I couldn't see any overhead, because the function was > without that on my first tests, and after that I saw no difference on the > tests. Oh, ok then. I would've expected it to make a measurable difference. > I think I should use SPI_getbinvalue instead, but I don't know how > to parse the result to get year and month, any help on that? The fastest way is probably to use j2date like date_out does: DateADT date = DatumGetDateADT(x) int year, month, mday; if (DATE_NOT_FINITE(date)) elog(ERROR, "date must be finite"); j2date(date + POSTGRES_EPOCH_JDATE, &year, &month, &mday); - Heikki -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance