PEAR:DB_Oracle optimizations
| From: | Mikael Johansson | Date: | Mon, 08 Mar 2004 15:01:05 +0000 |
| Subject: | PEAR:DB_Oracle optimizations | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-26202@lists.php.net to get a copy of this message | ||
Just a note. The getAll(), getCol() and limitQuery() could be optimized by
using OCIFetchStatement such as:
OCIFetchStatement($stmt, $rows, $offset,
null!=$limit?$limit:-1, OCI_ASSOC|OCI_FETCHSTATEMENT_BY_ROW);
or for getCol() as:
OCIFetchStatement($stmt, $rows, $offset, null!=$limit?$limit:-1,
(is_numeric($colName)?OCI_NUM:OCI_ASSOC)|OCI_FETCHSTATEMENT_BY_COLUMN);
It seems OCIFetchStatement can also do limit/offset as seen above, when
benchmarking this against the traditional query rewriting technique it
would speed up some queries by 4-5x. Offset=0 Limit=-1 fetches all rows.
Furthermore OCI8 apparently sets the rowbuffer to 1 for queries, which
means that it will retreive the rows one by one from the database instead
of using larger chunks. This can be set with OCISetPretech as:
OCISetPrefetch($stmt, (null!=$limit?$limit:$prefetch)+1);
resulting in a speedup of about 2x for some queries. Especially in
situations where we know how many rows we are going to get.
Ref:
http://www.php.net/manual/sv/function.ocisetprefetch.php
http://www.php.net/manual/sv/function.ocifetchstatement.php
//mikael
--
Mikael Johansson
Chalmers Lindholmen University College, Computer Service
Email: mikael@chl.chalmers.se Phone: (+46) 031-772 5912