php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36278 extremely slow bytea extraction from pgsql
Submitted: 2006-02-03 21:34 UTC Modified: 2006-02-03 22:51 UTC
From: support at kalador dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.1.2 OS: redhat linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: support at kalador dot com
New email:
PHP Version: OS:

 

 [2006-02-03 21:34 UTC] support at kalador dot com
Description:
------------
I tried 3 ways to store big images (500K) in database and display in browser.  lo works fast, as does using a "text" column and converting the image to base64 (and back for display). However, using bytea with escaping is very slow.

Adding to the database is fine (it is fast), retrieving is the problem.



Reproduce code:
---------------
This code consumed my CPU and took 77 seconds to run for a 400K image:

<?php
 // Connect to the database
 $dbconn = pg_connect('dbname=imagedb');

 // Get the bytea data
 $res = pg_query("SELECT data FROM image WHERE name='big.gif'");

 // Convert to binary and send to the browser
 header('Content-type: image/gif');
 echo pg_unescape_bytea( pg_fetch_result($res,'data') );
?>


Expected result:
----------------
This should take less than 1 second.  Using a text column and base64 escaping rather than a bytea column and pg_unescape_bytea takes less than 1 second on the same data.

Actual result:
--------------
Actually result - 77 seconds.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-03 22:17 UTC] tony2001@php.net
What version of libpq are you using? 
 [2006-02-03 22:38 UTC] support at kalador dot com
libpq is 3.2

Using postgresql 8.0.1 btw
 [2006-02-03 22:51 UTC] tony2001@php.net
With libpq > 7.3 pg_unescape_bytea() is just a wrapper for PQunescapeBytea().
If this function is slow - sorry, we can do nothing about it. 
Please report it to PG developers.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Apr 10 07:01:23 2020 UTC