UUID data format 4x-4x-4x-4x-4x-4x-4x-4x

Lists: pgsql-hackers
From: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
To: "Pg Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-27 23:15:00
Message-ID: 758d5e7f0802271515q432b00f6l15cbf0cdf5c73e1b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello.

I am currently playing with UUID data type and try to use it to store provided
by third party (Hewlett-Packard) application. The problem is they
format UUIDs as
0000-0000-0000-0000-0000-0000-0000-0000, so I have to
replace(text,'-','')::uuid for
this kind of data.

Nooow, the case is quite simple and it might be that there are other
applications
formatting UUIDs too liberally.

I am working on a patch to support this format (yes, it is a simple
modification).

And in the meanwhile I would like to ask you what do you think about it?

Cons: Such format is not standard.

Pros: This will help UUID data type adoption. [1] While good
applications format
their data well, there are others which don't follow standards. Also
I think it is
easier for a human being to enter UUID as 8 times 4 digits.

Your thoughts? Should I submit a patch?

Regards,
Dawid

[1]: My first thought when I received the error message was "hey! this
is not an UUID,
it is too long/too short!", only later did I check that they just
don't format it too well.


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-27 23:54:05
Message-ID: 200802271554.05741.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Dawid,

> I am working on a patch to support this format (yes, it is a simple
> modification).

I'd suggest writing a formatting function for UUIDs instead. Not sure what
it should be called, though. "to_char" is pretty overloaded right now.

--
--Josh

Josh Berkus
PostgreSQL @ Sun
San Francisco


From: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>
To: <josh(at)agliodbs(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Cc: "'Dawid Kuroczko'" <qnex42(at)gmail(dot)com>
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-28 00:12:53
Message-ID: 003e01c8799e$aa713a40$0a01a8c0@gevmus
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


> > I am working on a patch to support this format (yes, it is a simple
> > modification).

There was a proposal and a discussion regarding how this datatype would be
before I started developing it. We decided to go with the format proposed in
RFC. Unless there is strong case, I doubt any non standard formatting will
be accepted into core. IIRC we where also opposed to support java like
formatted uuid's back then. This is no different.

Regards,
Gevik.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: josh(at)agliodbs(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org, "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-28 00:19:38
Message-ID: 13019.1204157978@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Josh Berkus <josh(at)agliodbs(dot)com> writes:
>> I am working on a patch to support this format (yes, it is a simple
>> modification).

> I'd suggest writing a formatting function for UUIDs instead.

That seems like overkill, if not outright encouragement of people to
come up with yet other nonstandard formats for UUIDs.

I think the question we have to answer is whether we want to be
complicit in the spreading of a nonstandard UUID format. Even if
we answer "yes" for this HP case, it doesn't follow that we should
create a mechanism for anybody to do anything with 'em. That way
lies the madness people already have to cope with for datetime
data :-(

regards, tom lane


From: "Jochem van Dieten" <jochemd(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-28 10:25:01
Message-ID: f96a9b830802280225u17bab27v8ef55d9c962512db@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Feb 28, 2008 at 1:19 AM, Tom Lane wrote:
> I think the question we have to answer is whether we want to be
> complicit in the spreading of a nonstandard UUID format.

I don't.

I have patched the UUID input and output functions to be compatible
with Adobe ColdFusion (http://adobe.com/products/coldfusion/ uses
8x-4x-4x-16x), and while I have released them I have deliberately made
the changes incompatible with other formats and will not submit them
to PostgreSQL because I want Adobe to fix ColdFusion to use the
standard format.

Jochem


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-28 16:58:01
Message-ID: 200802280858.01213.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom,

> I think the question we have to answer is whether we want to be
> complicit in the spreading of a nonstandard UUID format. Even if
> we answer "yes" for this HP case, it doesn't follow that we should
> create a mechanism for anybody to do anything with 'em. That way
> lies the madness people already have to cope with for datetime
> data :-(

Well, I guess the question is: if we don't offer some builtin way to render
non-standard formats built into company products, will those companies fix
their format or just not use PostgreSQL?

--
Josh Berkus
PostgreSQL @ Sun
San Francisco


From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-28 17:46:43
Message-ID: 20080228174643.GA22016@crankycanuck.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Feb 28, 2008 at 08:58:01AM -0800, Josh Berkus wrote:

> Well, I guess the question is: if we don't offer some builtin way to render
> non-standard formats built into company products, will those companies fix
> their format or just not use PostgreSQL?

Well, there is an advantage that Postgres has that some others don't: you
can extend Postgres pretty easily. That suggests to me a reason to be
conservative in what we "build in". This is consistent with the principle,
"Be conservative in what you send, and liberal in what you accept."

A


From: "Zeugswetter Andreas ADI SD" <Andreas(dot)Zeugswetter(at)s-itsolutions(dot)at>
To: "Andrew Sullivan" <ajs(at)crankycanuck(dot)ca>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-28 19:06:46
Message-ID: E1539E0ED7043848906A8FF995BDA57902D06765@m0143.s-mxs.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


> > Well, I guess the question is: if we don't offer some builtin way to
render
> > non-standard formats built into company products, will those
companies fix
> > their format or just not use PostgreSQL?
>
> Well, there is an advantage that Postgres has that some others don't:
you
> can extend Postgres pretty easily. That suggests to me a reason to be
> conservative in what we "build in". This is consistent with the
principle,
> "Be conservative in what you send, and liberal in what you accept."

Well, then the uuid input function should most likely disregard all -,
and accept the 4x-, 8x- formats and the like on input.

Andreas


From: Kenneth Marshall <ktm(at)rice(dot)edu>
To: Zeugswetter Andreas ADI SD <Andreas(dot)Zeugswetter(at)s-itsolutions(dot)at>
Cc: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-28 19:20:34
Message-ID: 20080228192034.GA15497@it.is.rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Feb 28, 2008 at 08:06:46PM +0100, Zeugswetter Andreas ADI SD wrote:
>
> > > Well, I guess the question is: if we don't offer some builtin way to
> render
> > > non-standard formats built into company products, will those
> companies fix
> > > their format or just not use PostgreSQL?
> >
> > Well, there is an advantage that Postgres has that some others don't:
> you
> > can extend Postgres pretty easily. That suggests to me a reason to be
> > conservative in what we "build in". This is consistent with the
> principle,
> > "Be conservative in what you send, and liberal in what you accept."
>
> Well, then the uuid input function should most likely disregard all -,
> and accept the 4x-, 8x- formats and the like on input.
>
> Andreas
>
>
We need to support the standard definition. People not using the standard
need to know that and explicitly acknowledge that by implementing the
conversion process themselves. Accepting random input puts a performance
hit on everybody following the standard. It is the non-standard users who
should pay that cost.

Cheers,
Ken


From: James Mansion <james(at)mansionfamily(dot)plus(dot)com>
To: Kenneth Marshall <ktm(at)rice(dot)edu>
Cc: Zeugswetter Andreas ADI SD <Andreas(dot)Zeugswetter(at)s-itsolutions(dot)at>, Andrew Sullivan <ajs(at)crankycanuck(dot)ca>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-28 23:27:37
Message-ID: 47C74369.5080000@mansionfamily.plus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Kenneth Marshall wrote:
> conversion process themselves. Accepting random input puts a performance
> hit on everybody following the standard.
Why is that necessarily the case?

Why not have a liberal parser and a configurable switch that determines
whether non-standard
forms are liberally accepted, accepted with a logged warning, or rejected?

James


From: Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
To: James Mansion <james(at)mansionfamily(dot)plus(dot)com>
Cc: Kenneth Marshall <ktm(at)rice(dot)edu>, Zeugswetter Andreas ADI SD <Andreas(dot)Zeugswetter(at)s-itsolutions(dot)at>, Andrew Sullivan <ajs(at)crankycanuck(dot)ca>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-28 23:45:18
Message-ID: 47C7478E.9020106@mark.mielke.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

James Mansion wrote:
> Kenneth Marshall wrote:
>> conversion process themselves. Accepting random input puts a performance
>> hit on everybody following the standard.
> Why is that necessarily the case?
>
> Why not have a liberal parser and a configurable switch that
> determines whether non-standard
> forms are liberally accepted, accepted with a logged warning, or
> rejected?

I recall there being a measurable performance difference between the
most liberal parser, and the most optimized parser, back when I wrote
one for PostgreSQL. I don't know how good the one in use for PostgreSQL
8.3 is. As to whether the cost is noticeable to people or not - that
depends on what they are doing. The problem is that a UUID is pretty
big, and parsing it liberally means a loop.

My personal opinion is that this is entirely a philosophical issue, and
that both sides have merits. There is no reason for PostgreSQL to
support all formats, not matter how non-standard, for every single type.
So, why would UUID be special? Because it's easy to do is not
necessarily a good reason. But then, it's not a bad reason either.

Cheers,
mark

--
Mark Mielke <mark(at)mielke(dot)cc>


From: James Mansion <james(at)mansionfamily(dot)plus(dot)com>
To: Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
Cc: Kenneth Marshall <ktm(at)rice(dot)edu>, Zeugswetter Andreas ADI SD <Andreas(dot)Zeugswetter(at)s-itsolutions(dot)at>, Andrew Sullivan <ajs(at)crankycanuck(dot)ca>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-29 00:07:33
Message-ID: 47C74CC5.1090200@mansionfamily.plus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Mark Mielke wrote:
> I recall there being a measurable performance difference between the
> most liberal parser, and the most optimized parser, back when I wrote
> one for PostgreSQL. I don't know how good the one in use for
> PostgreSQL 8.3 is. As to whether the cost is noticeable to people or
> not - that depends on what they are doing. The problem is that a UUID
> is pretty big, and parsing it liberally means a loop.
>
It just seems odd - I would have thought one would use re2c or ragel to
generate something and the performance would essentially be O[n] on the
input length in characters - using either a collection of allowed forms
or an engine that normalises case and discards the '-' characters
between any hex pairs. So yes these would have a control loop. Is that
so bad?

Either way its hard to imagine how parsing a string of this length could
create a measurable performance issue compared to what will happen with
the value post parse.

James


From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-29 00:09:45
Message-ID: 20080229000945.GK1653@frubble.xen.chris-lamb.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Feb 28, 2008 at 06:45:18PM -0500, Mark Mielke wrote:
> My personal opinion is that this is entirely a philosophical issue, and
> that both sides have merits.

I think it depends on what you're optimising for: initial development
time, maintaince time or run time.

> There is no reason for PostgreSQL to
> support all formats, not matter how non-standard, for every single type.
> So, why would UUID be special? Because it's easy to do is not
> necessarily a good reason. But then, it's not a bad reason either.

I never really buy the "performance" argument. I much prefer the
correctness argument, if the code is doing something strange I'd prefer
to know about it as soon as possible. This generally means that I'm
optimising for maintaince.

It's a similar argument to why lots of automatic casts were removed from
8.3, it generally doesn't hurt but the few times it does it's going to
be bad and if you're doing something strange to start with it's better
to be explicit about it.

Sam


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-29 03:56:53
Message-ID: 21410.1204257413@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Sullivan <ajs(at)crankycanuck(dot)ca> writes:
> "Be conservative in what you send, and liberal in what you accept."

Yeah, I was about to quote that same maxim myself. I don't have a big
problem with allowing uuid_in to accept known format variants. (I'm
not sure about allowing a hyphen *anywhere*, because that could lead to
accepting things that weren't meant to be a UUID at all, but this HP
format seems regular enough that that's not a serious objection to it.)

What I was really complaining about was Josh's suggestion that we invent
a function to let users *output* UUIDs in random-format-of-the-week.
I can't imagine much good coming of that. I think we should keep
uuid_out emitting only the RFC-standardized format.

regards, tom lane


From: Mark Mielke <mark(at)mark(dot)mielke(dot)cc>
To: James Mansion <james(at)mansionfamily(dot)plus(dot)com>
Cc: Kenneth Marshall <ktm(at)rice(dot)edu>, Zeugswetter Andreas ADI SD <Andreas(dot)Zeugswetter(at)s-itsolutions(dot)at>, Andrew Sullivan <ajs(at)crankycanuck(dot)ca>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-29 05:24:59
Message-ID: 47C7972B.1020202@mark.mielke.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

James Mansion wrote:
> Mark Mielke wrote:
>> I recall there being a measurable performance difference between the
>> most liberal parser, and the most optimized parser, back when I wrote
>> one for PostgreSQL. I don't know how good the one in use for
>> PostgreSQL 8.3 is. As to whether the cost is noticeable to people or
>> not - that depends on what they are doing. The problem is that a UUID
>> is pretty big, and parsing it liberally means a loop.
>>
> It just seems odd - I would have thought one would use re2c or ragel
> to generate something and the performance would essentially be O[n] on
> the input length in characters - using either a collection of allowed
> forms or an engine that normalises case and discards the '-'
> characters between any hex pairs.

Instruction level parallelism allows for multiple hex values to be
processed in parallel, whereas a loop relies on branch prediction and
speculative load and store? :-)

The liberal version is difficult to unroll. The strict version is easy
to unroll.

> So yes these would have a control loop. Is that so bad?
>
> Either way its hard to imagine how parsing a string of this length
> could create a measurable performance issue compared to what will
> happen with the value post parse.

I think so too.

Cheers,
mark

--
Mark Mielke <mark(at)mielke(dot)cc>


From: "Tom Dunstan" <pgsql(at)tomd(dot)cc>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Andrew Sullivan" <ajs(at)crankycanuck(dot)ca>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-29 05:40:39
Message-ID: ca33c0a30802282140h4102658bi5202f28a6b79d812@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Feb 29, 2008 at 9:26 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Andrew Sullivan <ajs(at)crankycanuck(dot)ca> writes:
> > "Be conservative in what you send, and liberal in what you accept."
>
> Yeah, I was about to quote that same maxim myself. I don't have a big
> problem with allowing uuid_in to accept known format variants. (I'm
> not sure about allowing a hyphen *anywhere*, because that could lead to
> accepting things that weren't meant to be a UUID at all, but this HP
> format seems regular enough that that's not a serious objection to it.)

This seems like a good enough opportunity to mention an idea that I
had while/after doing the enum patch. The patch was fairly intrusive
for something that was just adding a type because postgresql isn't
really set up for parameterized types other than core types. The idea
would be to extend the enum mechanism to allow UDTs etc to be
parameterized, and enums would just become one use of the mechanism.
Other obvious examples that I had in mind were allowing variable
lengths for that binary data type with hex IO for e.g. differently
sized checksums that people want, and allowing different formats for
uuids.

So the idea as applied to this case would be to do the enum-style
typesafe thing, ie:

create type coldfusion_uuid as generic_uuid('xxxx-xxxx-xxxx-xxxx');

...then just use that. I had some thoughts about whether it would be
worth allowing inline declarations of such types inside table creation
statements as well, and there are various related issues and thoughts
on implementation which I won't go into in this email. Do people think
the idea has legs, though?

> What I was really complaining about was Josh's suggestion that we invent
> a function to let users *output* UUIDs in random-format-of-the-week.
> I can't imagine much good coming of that. I think we should keep
> uuid_out emitting only the RFC-standardized format.

Well, if the application is handing them to us in that format, it
might be a bit surprised if it gets back a "fixed" one. The custom
type approach wouldn't have that side effect.

Cheers

Tom


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Tom Dunstan" <pgsql(at)tomd(dot)cc>
Cc: "Andrew Sullivan" <ajs(at)crankycanuck(dot)ca>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-02-29 06:09:26
Message-ID: 22967.1204265366@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Tom Dunstan" <pgsql(at)tomd(dot)cc> writes:
> This seems like a good enough opportunity to mention an idea that I
> had while/after doing the enum patch. The patch was fairly intrusive
> for something that was just adding a type because postgresql isn't
> really set up for parameterized types other than core types. The idea
> would be to extend the enum mechanism to allow UDTs etc to be
> parameterized, and enums would just become one use of the mechanism.

Isn't this reasonably well covered by Teodor's work to support
typmods for user-defined types? We've discussed how the typmod could
be effectively a key into a system catalog someplace, thus allowing it
to represent more than just an int32 worth of stuff. I'm not seeing
where your proposal accomplishes more than that can.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Dawid Kuroczko <qnex42(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: UUID data format 4x-4x-4x-4x-4x-4x-4x-4x
Date: 2008-03-03 19:03:56
Message-ID: 200803031903.m23J3ue24994@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Added to TODO:

* Allow the UUID type to accept non-standard formats

http://archives.postgresql.org/pgsql-hackers/2008-02/msg01214.php

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

Dawid Kuroczko wrote:
> Hello.
>
> I am currently playing with UUID data type and try to use it to store provided
> by third party (Hewlett-Packard) application. The problem is they
> format UUIDs as
> 0000-0000-0000-0000-0000-0000-0000-0000, so I have to
> replace(text,'-','')::uuid for
> this kind of data.
>
> Nooow, the case is quite simple and it might be that there are other
> applications
> formatting UUIDs too liberally.
>
> I am working on a patch to support this format (yes, it is a simple
> modification).
>
> And in the meanwhile I would like to ask you what do you think about it?
>
> Cons: Such format is not standard.
>
> Pros: This will help UUID data type adoption. [1] While good
> applications format
> their data well, there are others which don't follow standards. Also
> I think it is
> easier for a human being to enter UUID as 8 times 4 digits.
>
> Your thoughts? Should I submit a patch?
>
> Regards,
> Dawid
>
> [1]: My first thought when I received the error message was "hey! this
> is not an UUID,
> it is too long/too short!", only later did I check that they just
> don't format it too well.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
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. +