Use hex_decode_safe() to speed up UUID input.

Previously, string_to_uuid() decoded one byte at a time, calling
isxdigit() twice and strtoul() once for every pair of hexadecimal
digits. Commit ec8719ccbfcd made hex_decode_safe() decode a run of
hexadecimal digits in bulk, so add a fast path for the two common
shapes: 32 contiguous hexadecimal digits, and the canonical
8x-4x-4x-4x-12x form, each optionally wrapped in braces.

Anything else, and any decoding error, falls back to the
byte-at-a-time parser, so the accepted grammar and the error messages
don't change. hex_decode_safe() also skips whitespace, which the UUID
grammar forbids, so we treat a short decode as an error too. Rejecting
an input that has a fast-path shape therefore costs a second
parse. But this only happens for syntax-error cases, so it's not a
problem in practice.

Reviewed-by: Bharath Rupireddy <[email protected]>
Reviewed-by: Haibo Yan <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Reviewed-by: John Naylor <[email protected]>
Discussion: 
https://postgr.es/m/cad21aocqer4uqu77q_yomnnzj7aveio5qzt+4hnzpm4wm-e...@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/72af14bccd2127bf20ddeaf198b78de46e9e892b

Modified Files
--------------
src/backend/utils/adt/uuid.c       | 101 +++++++++++++++++++++++++++++++++++--
src/test/regress/expected/uuid.out |  74 +++++++++++++++++++++++++++
src/test/regress/sql/uuid.sql      |  24 +++++++++
3 files changed, 194 insertions(+), 5 deletions(-)

Reply via email to