Patch for PGunescapeBytea

From: Ben Lamb <pgsql-patches(at)zurgy(dot)org>
To: pgsql-patches(at)postgresql(dot)org
Cc: "Billy G(dot) Allie" <bill(dot)allie(at)mug(dot)org>
Subject: Patch for PGunescapeBytea
Date: 2003-05-04 20:54:18
Message-ID: 200305042154.18504.pgsql-patches@zurgy.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Hi,

I found the libpq function PGunescapeBytea a little slow. It was taking a
minute and a half to decode a 500Kb on a fairly fast machine. I think the
culprit is sscanf.

I attach a patch that replaces the function with one used to perform the same
task in pyPgSQL (a Python interface to PostgreSQL). This code was written by
Billy Allie, author of pyPgSQL. I've changed a few variable names to match
those in the original code and removed a bit of Pythonness.

Billy has kindly looked at the code and points out that it is slightly
stricter than the original implementation and if it encounters an invalid
bytea such as '\12C' it drops the unescape '\' and outputs '12C'.

The code is licensed by the author under a BSD license.

I've performed limited testing of the function by putting JPEGs into
PostgreSQL, extracting them using them using the new function and diffing
against the original files.

The new function is significantly faster on my machine with the JPEGs being
decoded in less than a second. I attach a modified libpq example program that
I used for my testing.

Regards,

Ben Lamb.

The patch modifies fe-exec.c in /src/interfaces/libpq from PostgreSQL 7.3.2.

Attachment Content-Type Size
fe-exec.c.patch text/x-diff 3.8 KB
testlibpq.c text/x-csrc 3.3 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Joe Conway 2003-05-05 00:49:30 Re: array support patch phase 1 patch
Previous Message Tom Lane 2003-05-04 14:27:28 Re: apply outer->inner join optimisation to OR clauses