Req #66794 [NEW]: dba_fetch() skip parameter is inefficient when accessing cdbs
From: doug at opendns dot com
Operating system: Any
PHP version: Irrelevant
Package: DBM/DBA related
Bug Type: Feature/Change Request
Bug description:dba_fetch() skip parameter is inefficient when accessing cdbs
Description:
------------
---
From manual page: http://www.php.net/function.dba-fetch
---
This is in reference to this bit of the source, which dates back to
2002, so it's applicable to pretty much any version of php since 4.3:
https://github.com/php/php-src/blob/master/ext/dba/dba_cdb.c#L160
When you pass a value for $skip to dba_fetch() when reading a cdb
database, it'll do $skip reads to bypass those entries. Since a common
use case is to do this in a loop (see script below) to read an
indeterminate number of duplicate keys from a database, If there end up
being 100 entries, you're actually doing several thousand disk
operations.
Test script:
---------------
<?php
// Write a sample cdb to demo on
$values = array_fill(0, 100, 'test value');
$cdb = dba_open('test.cdb', 'n', 'cdb');
foreach($values as $value) dba_insert('test key', $value, $cdb);
dba_close($cdb);
// Now actually show the issue (see attached dtruss link for what's
happening)
$cdb = dba_open('test.cdb', 'r', 'cdb');
$cdbSkip = 0;
while ($result = dba_fetch('test key', $cdbSkip, $cdb)) {
$cdbSkip++;
}
Expected result:
----------------
I'd expect approximately 100 read requests against the cdb from the
latter half of the script
Actual result:
--------------
See this output from dtruss:
https://gist.github.com/tabacco/86bd9f4b1fd267a62be2
Note the high number of seek and read operations to fetch 100 rows.
--
Edit bug report at https://bugs.php.net/bug.php?id=66794&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66794&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66794&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66794&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66794&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66794&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66794&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66794&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66794&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66794&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66794&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66794&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66794&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66794&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66794&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66794&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66794&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66794&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66794&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66794&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66794&r=mysqlcfg
Thread (3 messages)
- doug at opendns dot com