Thread: BUG #4414: PQescapeByteaInternal very slow/inefficient

BUG #4414: PQescapeByteaInternal very slow/inefficient

From
"Rudolf Leitgeb"
Date:
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.

Re: BUG #4414: PQescapeByteaInternal very slow/inefficient

From
Tom Lane
Date:
"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