BUG #4414: PQescapeByteaInternal very slow/inefficient - Mailing list pgsql-bugs

From Rudolf Leitgeb
Subject BUG #4414: PQescapeByteaInternal very slow/inefficient
Date
Msg-id 200809101112.m8ABCwxg080817@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #4414: PQescapeByteaInternal very slow/inefficient
List pgsql-bugs
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.

pgsql-bugs by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: issue with postgres/xml
Next
From: Tom Lane
Date:
Subject: Re: BUG #4414: PQescapeByteaInternal very slow/inefficient