Commit 8e8a2c06 authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-93 - Optimize performance of OraclePlatform::modifyLimitQuery(), thanks cicovec

parent f22e7c65
...@@ -597,7 +597,7 @@ LEFT JOIN all_cons_columns r_cols ...@@ -597,7 +597,7 @@ LEFT JOIN all_cons_columns r_cols
$limit = (int) $limit; $limit = (int) $limit;
$offset = (int) $offset; $offset = (int) $offset;
if (preg_match('/^\s*SELECT/i', $query)) { if (preg_match('/^\s*SELECT/i', $query)) {
if ( ! preg_match('/\sFROM\s/i', $query)) { if (!preg_match('/\sFROM\s/i', $query)) {
$query .= " FROM dual"; $query .= " FROM dual";
} }
if ($limit > 0) { if ($limit > 0) {
...@@ -605,13 +605,11 @@ LEFT JOIN all_cons_columns r_cols ...@@ -605,13 +605,11 @@ LEFT JOIN all_cons_columns r_cols
$column = '*'; $column = '*';
if ($offset > 0) { if ($offset > 0) {
$min = $offset + 1; $min = $offset + 1;
$query = 'SELECT b.'.$column.' FROM ('. $query = 'SELECT * FROM (SELECT a.' . $column . ', rownum AS doctrine_rownum FROM (' .
'SELECT a.*, ROWNUM AS doctrine_rownum FROM (' $query .
. $query . ') a '. ') a WHERE rownum <= ' . $max . ') WHERE doctrine_rownum >= ' . $min;
') b '.
'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max;
} else { } else {
$query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max; $query = 'SELECT a.' . $column . ' FROM (' . $query . ') a WHERE ROWNUM <= ' . $max;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment