mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
Optimize hex_encode() and hex_decode() using SIMD.
The hex_encode() and hex_decode() functions serve as the workhorses for hexadecimal data for bytea's text format conversion functions, and some workloads are sensitive to their performance. This commit adds new implementations that use routines from port/simd.h, which testing indicates are much faster for larger inputs. For small or invalid inputs, we fall back on the existing scalar versions. Since we are using port/simd.h, these optimizations apply to both x86-64 and AArch64. Author: Nathan Bossart <nathandbossart@gmail.com> Co-authored-by: Chiranmoy Bhattacharya <chiranmoy.bhattacharya@fujitsu.com> Co-authored-by: Susmitha Devanga <devanga.susmitha@fujitsu.com> Reviewed-by: John Naylor <johncnaylorls@gmail.com> Discussion: https://postgr.es/m/aLhVWTRy0QPbW2tl%40nathan
This commit is contained in:
@@ -260,6 +260,64 @@ SELECT reverse('\xabcd'::bytea);
|
||||
\xcdab
|
||||
(1 row)
|
||||
|
||||
SELECT ('\x' || repeat(' ', 32))::bytea;
|
||||
bytea
|
||||
-------
|
||||
\x
|
||||
(1 row)
|
||||
|
||||
SELECT ('\x' || repeat('!', 32))::bytea;
|
||||
ERROR: invalid hexadecimal digit: "!"
|
||||
SELECT ('\x' || repeat('/', 34))::bytea;
|
||||
ERROR: invalid hexadecimal digit: "/"
|
||||
SELECT ('\x' || repeat('0', 34))::bytea;
|
||||
bytea
|
||||
--------------------------------------
|
||||
\x0000000000000000000000000000000000
|
||||
(1 row)
|
||||
|
||||
SELECT ('\x' || repeat('9', 32))::bytea;
|
||||
bytea
|
||||
------------------------------------
|
||||
\x99999999999999999999999999999999
|
||||
(1 row)
|
||||
|
||||
SELECT ('\x' || repeat(':', 32))::bytea;
|
||||
ERROR: invalid hexadecimal digit: ":"
|
||||
SELECT ('\x' || repeat('@', 34))::bytea;
|
||||
ERROR: invalid hexadecimal digit: "@"
|
||||
SELECT ('\x' || repeat('A', 34))::bytea;
|
||||
bytea
|
||||
--------------------------------------
|
||||
\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
(1 row)
|
||||
|
||||
SELECT ('\x' || repeat('F', 32))::bytea;
|
||||
bytea
|
||||
------------------------------------
|
||||
\xffffffffffffffffffffffffffffffff
|
||||
(1 row)
|
||||
|
||||
SELECT ('\x' || repeat('G', 32))::bytea;
|
||||
ERROR: invalid hexadecimal digit: "G"
|
||||
SELECT ('\x' || repeat('`', 34))::bytea;
|
||||
ERROR: invalid hexadecimal digit: "`"
|
||||
SELECT ('\x' || repeat('a', 34))::bytea;
|
||||
bytea
|
||||
--------------------------------------
|
||||
\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
(1 row)
|
||||
|
||||
SELECT ('\x' || repeat('f', 32))::bytea;
|
||||
bytea
|
||||
------------------------------------
|
||||
\xffffffffffffffffffffffffffffffff
|
||||
(1 row)
|
||||
|
||||
SELECT ('\x' || repeat('g', 32))::bytea;
|
||||
ERROR: invalid hexadecimal digit: "g"
|
||||
SELECT ('\x' || repeat('~', 34))::bytea;
|
||||
ERROR: invalid hexadecimal digit: "~"
|
||||
SET bytea_output TO escape;
|
||||
SELECT E'\\xDeAdBeEf'::bytea;
|
||||
bytea
|
||||
|
||||
@@ -82,6 +82,22 @@ SELECT reverse(''::bytea);
|
||||
SELECT reverse('\xaa'::bytea);
|
||||
SELECT reverse('\xabcd'::bytea);
|
||||
|
||||
SELECT ('\x' || repeat(' ', 32))::bytea;
|
||||
SELECT ('\x' || repeat('!', 32))::bytea;
|
||||
SELECT ('\x' || repeat('/', 34))::bytea;
|
||||
SELECT ('\x' || repeat('0', 34))::bytea;
|
||||
SELECT ('\x' || repeat('9', 32))::bytea;
|
||||
SELECT ('\x' || repeat(':', 32))::bytea;
|
||||
SELECT ('\x' || repeat('@', 34))::bytea;
|
||||
SELECT ('\x' || repeat('A', 34))::bytea;
|
||||
SELECT ('\x' || repeat('F', 32))::bytea;
|
||||
SELECT ('\x' || repeat('G', 32))::bytea;
|
||||
SELECT ('\x' || repeat('`', 34))::bytea;
|
||||
SELECT ('\x' || repeat('a', 34))::bytea;
|
||||
SELECT ('\x' || repeat('f', 32))::bytea;
|
||||
SELECT ('\x' || repeat('g', 32))::bytea;
|
||||
SELECT ('\x' || repeat('~', 34))::bytea;
|
||||
|
||||
SET bytea_output TO escape;
|
||||
SELECT E'\\xDeAdBeEf'::bytea;
|
||||
SELECT E'\\x De Ad Be Ef '::bytea;
|
||||
|
||||
Reference in New Issue
Block a user