| From: | Masahiko Sawada <msawada(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Use hex_decode_safe() to speed up UUID input. |
| Date: | 2026-09-15 22:07:43 |
| Message-ID: | E1x6bJX-00000000UqH-1lvi@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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 <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Reviewed-by: Haibo Yan <tristan(dot)yim(at)gmail(dot)com>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Reviewed-by: John Naylor <johncnaylorls(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAD21AoCqeR4UQU77Q_yOMNNzJ7AVeiO5QZT+4HnzPm4Wm-e02Q@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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2026-09-16 01:11:34 | pgsql: Tweak tests related to oid8 in amcheck and test_decoding |
| Previous Message | Peter Geoghegan | 2026-09-15 18:37:28 | pgsql: Have read_stream_reset reset pending_read_nblocks. |