BUG #4414: PQescapeByteaInternal very slow/inefficient

Started by Rudolf Leitgebover 17 years ago2 messagesbugs
Jump to latest
#1Rudolf Leitgeb
r.leitgeb@x-pin.com

The following bug has been logged online:

Bug reference: 4414
Logged by: Rudolf Leitgeb
Email address: r.leitgeb@x-pin.com
PostgreSQL version: 8.3.3
Operating system: Mac OSX, linux
Description: PQescapeByteaInternal very slow/inefficient
Details:

PQescapeByteaInternal uses sprintf to convert a byte to its octal
representation, which slows down escaping of large BLOBs significantly. A
simple replacement table could achieve the same effect with much better
performance with only minimal extra memory requirements.

The routine is located in fe-exec.c
The call
(void) sprintf((char *) rp, "\\%03o", *vp);
could be replaced by
memcpy((char *)rp, lookuptable[*vp]);
rp += otherlookuptable[*vp];
with a properly configured lookuptable and otherlookuptable.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Rudolf Leitgeb (#1)
Re: BUG #4414: PQescapeByteaInternal very slow/inefficient

"Rudolf Leitgeb" <r.leitgeb@x-pin.com> writes:

PQescapeByteaInternal uses sprintf to convert a byte to its octal
representation, which slows down escaping of large BLOBs significantly.

Good point. Fixed in HEAD and 8.3 branches.

regards, tom lane