Re: [HACKERS] Text <-> C string

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Brendan Jurd <direvus(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Gregory Stark <stark(at)enterprisedb(dot)com>, pgsql-hackers(at)postgresql(dot)org, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Text <-> C string
Date: 2007-11-03 19:47:03
Message-ID: 200711031947.lA3Jl3f00902@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches


This has been saved for the 8.4 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

Brendan Jurd wrote:
> As discussed on -hackers, I'm trying to get rid of some redundant code
> by creating a widely useful set of functions to convert between text
> and C string in the backend.
>
> The new extern functions, declared in include/utils/builtins.h and
> defined in backend/utils/adt/varlena.c, are:
>
> char * text_cstring(const text *t)
> char * text_cstring_limit(const text *t, int len)
> text * cstring_text(const char *s)
> text * cstring_text_limit(const char *s, int len)
>
> Within varlena.c, the actual conversions are performed by:
>
> char * do_text_cstring(const text *t, const int len)
> text * do_cstring_text(const char *s, const int len)
>
> These functions now do the work for the fmgr functions textin and
> textout, as well as being directly accessible by backend code.
>
> I've searched through the backend for any code which converted between
> text and C string manually (with memcpy and VARDATA), replacing with
> calls to one of the four new functions as appropriate.
>
> I came across some areas which were using the same, or similar,
> conversion technique on other varlena data types, such as bytea or
> xmltype. In cases where the conversion was completely identical I
> used the new functions. In cases with any differences (even if they
> seemed minor) I played it safe and left them alone.
>
> I'd now like to submit my work so far for review. This patch compiled
> cleanly on Linux and passed all parallel regression tests. It appears
> to be performance-neutral based on a few rough tests; I haven't tried
> to profile the changes in detail.
>
> There is still a lot of code out there using DirectFunctionCall1 to
> call text(in|out)). I've decided to wait for some community feedback
> on the patch as it stands before replacing those calls. There are a
> great many, and it would be a shame to have to go through them more
> than once.
>
> I would naively expect that replacing fmgr calls with direct calls
> would lead to a performance gain (no fmgr overhead), but honestly I'm
> not sure whether that would actually make a difference.
>
> Thanks for your time,
> BJ

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-11-03 19:47:40 Re: type money causes unrestorable dump
Previous Message D'Arcy J.M. Cain 2007-11-03 19:42:08 Re: type money causes unrestorable dump

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2007-11-03 22:01:16 Re: [PATCHES] Eliminate more detoast copies for packed varlenas
Previous Message Gevik Babakhani 2007-11-03 18:24:38 Re: V0.2 patch for TODO Item: SQL-language referenceparameters by name.