Re: [PATCHES] libpq type system 0.9a

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Gregory Stark" <stark(at)enterprisedb(dot)com>
Cc: "Jeff Davis" <pgsql(at)j-davis(dot)com>, "Andrew Dunstan" <andrew(at)dunslane(dot)net>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Andrew Chernow" <ac(at)esilo(dot)com>, "Joe Conway" <mail(at)joeconway(dot)com>, "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] libpq type system 0.9a
Date: 2008-04-09 11:54:03
Message-ID: b42b73150804090454i30936999q96a9d8b23436f463@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

On Wed, Apr 9, 2008 at 6:13 AM, Gregory Stark <stark(at)enterprisedb(dot)com> wrote:
> > The exclusive use of binary formats is worrisome to me. This circumvents
> > one level of indirection that we have (i.e. that everything moves
> > through in/out functions), and will impose a backwards-compatibility
> > requirement on the internal representation of data types, including
> > user-defined data types. As far as I know, we currently have no such
> > requirement, even for built-in types.
>
> This is actually incorrect. Binary I/O still goes through a function call, the
> send/recv functions instead of the in/out functions. In theory these are also
> supposed to be cross-platform.
>
> In practice they are, uhm, less cross-platform. For example they send floats
> as raw (presumably) IEEE floats. There have also been fewer clients using
> binary mode, so you're more likely to run into bugs.

small correction: you _were_ more likely to run into bugs. in the
process of developing this patch during the 8.3 cycle, we caught,
fixed, and submitted a number of binary format related issues,
including some wacky things that are not possible through the text
parser (a polygon with zero points for example). we used regression
testing heavily in development.

> But the reason fewer clients use binary mode is because they would have to
> implement all this type-specific knowledge. It doesn't make sense to do it for
> every driver or application but if you're implementing it once in a library it
> does start to make more sense.
>
> Note however that not every data type will necessarily provide a binary
> send/recv function. The built-in data types do, but only as a matter of
> policy. It's not an error to create a type with no binary i/o functions.
> So I think you have to support using text mode as an option.

You have this option. there is nothing keeping you from using getvalue
vs. getf. However, due to libpq limitations, if any datatype must
return text the entire result must be text (resultFormat)...this is
also interestingly true for functions that return 'void'. So, at
present, to use PQgetf, you result set must be binary.

In some of the early versions of the patch we introduced parsing code
to compute text results in addition to binary results (so for
getf('%int), the library does the atoi for you, checking range and
such). We ended up dropping this because we were getting nervous
about the size of the patch at that point.

In any event, I think a better solution would be to change
resultformat to mean 'give me binary format if it's available' on a
per column basis...libpq already has a method to check field format of
the result and getf can just raise a run-time error if you try to pass
a native type in when it's not available. This would be a pretty
amazing sequence of events...only likely to occur when developing new
types for example. Is this (mixed text/binary results) possible with
the v3 protocol?

merlin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2008-04-09 12:04:17 Re: [PATCHES] libpq type system 0.9a
Previous Message Gregory Stark 2008-04-09 11:24:19 Re: Concurrent psql API

Browse pgsql-patches by date

  From Date Subject
Next Message Andrew Dunstan 2008-04-09 12:04:17 Re: [PATCHES] libpq type system 0.9a
Previous Message Gregory Stark 2008-04-09 11:24:19 Re: Concurrent psql API