mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Revert refactoring of hex code to src/common/
This is a combined revert of the following commits: -c3826f8, a refactoring piece that moved the hex decoding code to src/common/. This code was cleaned up byaef8948, as it originally included no overflow checks in the same way as the base64 routines in src/common/ used by SCRAM, making it unsafe for its purpose. -aef8948, a more advanced refactoring of the hex encoding/decoding code to src/common/ that added sanity checks on the result buffer for hex decoding and encoding. As reported by Hans Buschmann, those overflow checks are expensive, and it is possible to see a performance drop in the decoding/encoding of bytea or LOs the longer they are. Simple SQLs working on large bytea values show a clear difference in perf profile. -ccf4e27, a cleanup made possible byaef8948. The reverts of all those commits bring back the performance of hex decoding and encoding back to what it was in ~13. Fow now and post-beta3, this is the simplest option. Reported-by: Hans Buschmann Discussion: https://postgr.es/m/1629039545467.80333@nidsa.net Backpatch-through: 14
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
#include "catalog/pg_collation.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "common/hashfn.h"
|
||||
#include "common/hex.h"
|
||||
#include "common/int.h"
|
||||
#include "common/unicode_norm.h"
|
||||
#include "lib/hyperloglog.h"
|
||||
@@ -305,12 +304,10 @@ byteain(PG_FUNCTION_ARGS)
|
||||
if (inputText[0] == '\\' && inputText[1] == 'x')
|
||||
{
|
||||
size_t len = strlen(inputText);
|
||||
uint64 dstlen = pg_hex_dec_len(len - 2);
|
||||
|
||||
bc = dstlen + VARHDRSZ; /* maximum possible length */
|
||||
bc = (len - 2) / 2 + VARHDRSZ; /* maximum possible length */
|
||||
result = palloc(bc);
|
||||
|
||||
bc = pg_hex_decode(inputText + 2, len - 2, VARDATA(result), dstlen);
|
||||
bc = hex_decode(inputText + 2, len - 2, VARDATA(result));
|
||||
SET_VARSIZE(result, bc + VARHDRSZ); /* actual length */
|
||||
|
||||
PG_RETURN_BYTEA_P(result);
|
||||
@@ -399,15 +396,11 @@ byteaout(PG_FUNCTION_ARGS)
|
||||
|
||||
if (bytea_output == BYTEA_OUTPUT_HEX)
|
||||
{
|
||||
uint64 dstlen = pg_hex_enc_len(VARSIZE_ANY_EXHDR(vlena));
|
||||
|
||||
/* Print hex format */
|
||||
rp = result = palloc(dstlen + 2 + 1);
|
||||
rp = result = palloc(VARSIZE_ANY_EXHDR(vlena) * 2 + 2 + 1);
|
||||
*rp++ = '\\';
|
||||
*rp++ = 'x';
|
||||
|
||||
rp += pg_hex_encode(VARDATA_ANY(vlena), VARSIZE_ANY_EXHDR(vlena), rp,
|
||||
dstlen);
|
||||
rp += hex_encode(VARDATA_ANY(vlena), VARSIZE_ANY_EXHDR(vlena), rp);
|
||||
}
|
||||
else if (bytea_output == BYTEA_OUTPUT_ESCAPE)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user