Re: patch: Allow the UUID type to accept non-standard formats

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: patch: Allow the UUID type to accept non-standard formats
Дата
Msg-id 603c8f070810100519w65857a95h72bc2ab8ff6ab4a@mail.gmail.com
обсуждение исходный текст
Ответ на Re: patch: Allow the UUID type to accept non-standard formats  (Mark Mielke <mark@mark.mielke.cc>)
Ответы Re: patch: Allow the UUID type to accept non-standard formats  (Mark Mielke <mark@mark.mielke.cc>)
Список pgsql-hackers
>   1) Reduced error checking.
>   2) The '-' is not the only character that people have used. ClearCase uses
> '.' and ':' as punctuation.
>   3) People already have the option of translating the UUID from their
> application to a standard format.
>   4) As you find below, and is probably possible to improve on, a fixed
> format can be parsed more efficient.

Scenario 1.  I have some standard format UUIDs and I want to parse
them.  This change doesn't bother me at all because if I'm parsing
anywhere enough UUIDs for it to matter, the speed of my CPU, disk, and
memory subsystems will vastly outweigh the difference between the two
implementations.  I measured the different between the two by running
them both in a tight loop on a fixed string.  I challenge anyone to
produce a measurable performance distinction by issuing SQL queries.
I doubt that it is possible.

Scenario 2. I have some non-standard format UUIDs and I want to parse
them.  This change helps me a lot, because I'm almost positive that
calling regexp_replace() and then uuid_in() is going to be MUCH slower
than just calling uuid_in().  And if I do that then my error checking
will be REALLY weak, unless I write a custom PL function to make sure
that dashes only occur where they're supposed to be, in which case it
will be even slower.

Scenario 3. I only want standard-format UUIDs to be accepted into my
database.  Any non-standard format UUIDs should be rejected at parse
time.  This change is pretty irritating, because now I have to use
regexp matching or something to make sure I've got the right format,
and it's going to be significantly slower.

My suspicion is that scenario 2 is a lot more common than scenario 3.

> I don't know which implementation was used for the PostgreSQL core, but any
> hard coded constants would allow for the optimizer to generate instructions
> that can run in parallel, or that are better aligned to machine words.
>
> 2-3% slow down for what gain? It still doesn't handle all cases, and it's
> less able to check the format for correctness.

This change is a long way from letting any old thing through as a
UUID.  I'm sure there are lots of crazy ways to write UUIDs, but
everything I found with a quick Google search would be covered by this
patch, so I think that's pretty good.  A key point for me is that it's
hard to imagine this patch accepting anything that was intended to be
something other than a UUID.  (I am sure someone will now write back
and tell me about their favorite non-UUID thing that happens to have
32 hex digits with dashes for separators, but come on.)

...Robert


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Block nested loop join
Следующее
От: "Robert Haas"
Дата:
Сообщение: Re: patch: Allow the UUID type to accept non-standard formats