cvs: php4 /pear/DB oci8.php
| From: | Thomas V.V.Cox | Date: | Thu, 27 Dec 2001 11:46:47 +0000 |
| Subject: | cvs: php4 /pear/DB oci8.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-1707@lists.php.net to get a copy of this message | ||
cox Thu Dec 27 06:46:47 2001 EDT
Modified files:
/php4/pear/DB oci8.php
Log:
Changes to modifyLimitQuery:
- Don't move the ORDER BY clausule it may alter the final result
- Restrict the first subquery to speed up the row fetching
- Introduce the FIRST_ROWS Oracle query optimizer (yet disabled)
(thanks to John Lim for the recommendations)
Index: php4/pear/DB/oci8.php
diff -u php4/pear/DB/oci8.php:1.39 php4/pear/DB/oci8.php:1.40
--- php4/pear/DB/oci8.php:1.39 Tue Dec 11 10:31:18 2001
+++ php4/pear/DB/oci8.php Thu Dec 27 06:46:46 2001
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: oci8.php,v 1.39 2001/12/11 15:31:18 sebastian Exp $
+// $Id: oci8.php,v 1.40 2001/12/27 11:46:46 cox Exp $
//
// Database independent query interface definition for PHP's Oracle 8
// call-interface extension.
@@ -520,27 +520,28 @@
*/
function modifyLimitQuery($query, $from, $count)
{
- // Put the "Order by" statement at the end of the final query
- if (preg_match('/\s+ORDER\s+BY\s+.*/is', $query, $match)) {
- $orderby = $match[0];
- $query = substr($query, 0, -1 * strlen($orderby));
- } else {
- $orderby = '';
- }
// Let Oracle return the name of the columns instead of
- // being coding a "home" SQL parser
+ // coding a "home" SQL parser
$q_fields = "SELECT * FROM ($query) WHERE NULL = NULL";
if (!$result = OCIParse($this->connection, $q_fields)) {
return $this->oci8RaiseError();
}
- if (!$success = OCIExecute($result, OCI_DEFAULT)) {
+ if (!OCIExecute($result, OCI_DEFAULT)) {
return $this->oci8RaiseError($result);
}
$ncols = OCINumCols($result);
+ $cols = array();
for ( $i = 1; $i <= $ncols; $i++ ) {
$cols[] = OCIColumnName($result, $i);
}
- $fields = implode(',', $cols);
+ $fields = implode(', ', $cols);
+ // XXX Test that (tip by John Lim)
+ //if(preg_match('/^\s*SELECT\s+/is', $query, $match)) {
+ // // Introduce the FIRST_ROWS Oracle query optimizer
+ // $query = substr($query, strlen($match[0]), strlen($query));
+ // $query = "SELECT /* +FIRST_ROWS */ " . $query;
+ //}
+
// Construct the query
// more at: http://marc.theaimsgroup.com/?l=php-db&m=99831958101212&w=2
// Perhaps this could be optimized with the use of Unions
@@ -548,8 +549,8 @@
$query = "SELECT $fields FROM".
" (SELECT rownum as linenum, $fields FROM".
" ($query)".
- " ) ".
- "WHERE linenum BETWEEN $from AND ". ($from + $count) . $orderby;
+ " WHERE rownum <= ". ($from + $count) .
+ ") WHERE linenum >= $from";
return $query;
}