From: vda at ilport dot com dot ua
Operating system: Linux
PHP version: 4.3.10
PHP Bug Type: *General Issues
Bug description: pg_query fetches ALL rows, using lots of memory
Description:
------------
Seen on php-4.3.4RC2. Since I was just testing how good
PG fares compared to Oracle, and I am not feeling any
real pain from this (IOW: not my itch to scratch),
I do not research this in depth, apart from submitting
bug report. Sorry.
Symptom: even the simplest query
$result = pg_query($db, "SELECT * FROM big_table");
eats enormous amounts of memory on server
(proportional to table size).
I think this is a problem with PostgreSQL client libs.
php's source is included for easy reference.
PHP_FUNCTION(pg_query)
{
...
pgsql_result = PQexec(pgsql, Z_STRVAL_PP(query));
if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) !=
CONNECTION_OK) {
PQclear(pgsql_result);
PQreset(pgsql);
pgsql_result = PQexec(pgsql, Z_STRVAL_PP(query));
}
if (pgsql_result) {
status = PQresultStatus(pgsql_result);
} else {
status = (ExecStatusType) PQstatus(pgsql);
}
switch (status) {
case PGRES_EMPTY_QUERY:
case PGRES_BAD_RESPONSE:
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Query
failed: %s.", PQerrorMessage(pgsql));
PQclear(pgsql_result);
RETURN_FALSE;
break;
case PGRES_COMMAND_OK: /* successful command that did not
return rows */
default:
if (pgsql_result) {
pg_result = (pgsql_result_handle *)
emalloc(sizeof(pgsql_result_handle));
pg_result->conn = pgsql;
pg_result->result = pgsql_result;
pg_result->row = 0;
ZEND_REGISTER_RESOURCE(return_value,
pg_result, le_result);
} else {
PQclear(pgsql_result);
RETURN_FALSE;
}
break;
}
}
--
Edit bug report at http://bugs.php.net/?id=33587&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33587&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=33587&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=33587&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33587&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33587&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33587&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33587&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33587&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33587&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33587&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=33587&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=33587&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33587&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33587&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33587&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33587&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33587&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33587&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33587&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33587&r=mysqlcfg