![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
Kai Ronan wrote: // Get the bytea data $res = pg_query("SELECT data FROM image WHERE name='big.gif'"); Do you have an index in the image.name column? What does an EXPLAIN ANALYZE SELECT data FROM image WHERE name='big.gif' say? |
#2
| |||
| |||
|
|
I've since isolated the problem to the unescape_bytea function not the SELECT. I inserted the same image to a bytea column using base64 encoding, and extracted it from the table (using base64 decoding) and this worked very fast (<1 second). So, it is the unescape_bytea function that is to blame. |
#3
| |||
| |||
|
|
$tfetch = microtime(true); // Convert to binary and send to the browser // header('Content-type: image/gif'); header('Content-type: text/plain'); $data = pg_unescape_bytea($raw); $dt = microtime(true) - $tfetch; |
|
When run from a browser, accessing an Apache webserver, the results displayed were: fetch time = 3.632ms, 296043 bytes unescape time = 70625.518ms, 296043 bytes When running the same code from command line php, the results were: fetch time = 3.618ms, 296043 bytes unescape time = 8.298ms, 296043 bytes Am running Apache 1.3.33. I can't figure the difference between environments - command line php and apache php are compiled the same (except for the --with-apxs=... instruction for apache version). |
|
As an aside, I'm now using base64 encode/decode to insert data without problems. For GIF images, at least, it is also a much smaller encoding than the escape_bytea encoding. |
#4
| |||
| |||
|
|
On Sat, Feb 04, 2006 at 04:06:11PM -0800, Kalador Tech Support wrote: I've since isolated the problem to the unescape_bytea function not the SELECT. I inserted the same image to a bytea column using base64 encoding, and extracted it from the table (using base64 decoding) and this worked very fast (<1 second). So, it is the unescape_bytea function that is to blame. pg_unescape_bytea is fast here; I just unescaped an 850K jpeg image in about 0.18 seconds on a slow (500MHz) machine. How did you determine that pg_unescape_bytea was the problem? What does something like the following show? $tstart = microtime(true); $data = pg_unescape_bytea(pg_fetch_result($res, 'data')); $dt = microtime(true) - $tstart; header("Content-Type: text/plain"); printf("unescape time = %.3fms, %d bytes\n", $dt * 1000.0, strlen($data)); |
#5
| |||
| |||
|
|
When run from a browser, accessing an Apache webserver, the results displayed were: fetch time = 3.632ms, 296043 bytes unescape time = 70625.518ms, 296043 bytes |
#6
| |||
| |||
|
|
Kalador Tech Support <support (AT) kalador (DOT) com> writes: When run from a browser, accessing an Apache webserver, the results displayed were: fetch time = 3.632ms, 296043 bytes unescape time = 70625.518ms, 296043 bytes Is it possible that you are relying on an old (like 7.3) libpq? I find this in the CVS logs: 2003-06-11 21:17 momjian * src/interfaces/libpq/fe-exec.c: 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. ... 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. |
#7
| |||
| |||
|
|
I note in the PHP 4 sources that the PQunescapeBytea function seems to have been copied there, "for the benefit of PostgreSQL 7.2 users". It says that it comes from 7.3 but I don't see any sscanf call. There is no PQunescapeBytea call in the whole source that I can see, so my guess is that the libpq function is not called at all. So this may be a PHP bug rather than a Postgres bug. |
#8
| |||
| |||
|
|
On Thu, Feb 09, 2006 at 12:46:46PM -0300, Alvaro Herrera wrote: I note in the PHP 4 sources that the PQunescapeBytea function seems to have been copied there, "for the benefit of PostgreSQL 7.2 users". It says that it comes from 7.3 but I don't see any sscanf call. There is no PQunescapeBytea call in the whole source that I can see, so my guess is that the libpq function is not called at all. So this may be a PHP bug rather than a Postgres bug. The OP claimed to be using PHP 5.1.2, which does have a call to PQunescapeBytea(), although it also has the old code you're seeing and a HAVE_PQUNESCAPEBYTEA macro that determines which to use. Interesting that the command line php and the Apache module behave differently. I wonder if ldd would show the php executable and libphp5.so linked against different versions of libpq; that would add weight to Tom's suggestion that an old libpq might be responsible. |
![]() |
| Thread Tools | |
| Display Modes | |
| |