You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I altered the generated query in OracleGrammar.php and got the query down from 5-12 seconds to 5-20 milliseconds:
/**
* Compile a common table expression for a query.
*
* @param string $sql
* @param string $constraint
* @param Builder $query
* @return string
*/
protected function compileTableExpression($sql, $constraint, $query)
{
if ($query->limit == 1 && is_null($query->offset)) {
return "select * from ({$sql}) where rownum {$constraint}";
}
if (!is_null($query->limit && !is_null($query->offset))) {
$start = $query->offset + 1;
$finish = $query->offset + $query->limit;
return "select t2.* from ( select rownum AS \"rn\", t1.* from ({$sql}) t1 where rownum <= {$finish}) t2 where t2.\"rn\" >= {$start}";
}
return "select t2.* from ( select rownum AS \"rn\", t1.* from ({$sql}) t1 ) t2 where t2.\"rn\" {$constraint}";
}
Here's an image album containing screenshots from query execution both in SQL Developer and in laravel, as shown by debugbar. Please note I did not screencap "cold" queries, so the values here are somewhat faster than they normally would be for first requests:
Sorry for late reply. I'm definitely open to improving the pagination and will give your suggestions a try. Also, please do not hesitate to submit a PR for optimizations/suggestions. Thanks!
* 8.x:
Bump v8.2.1 🚀
Add model insert tests.
Add test for single insert.
Fix binding values.
Add failing tests for #558.
Bump v8.2.0 🚀
Fix cs.
Fix pagination tests.
Enhance pagination as suggested on #563.
Fix docs.
Bump v8.1.3 🚀
Apply fixes from StyleCI
Compare using actual db count.
Use lower column name on column listing.
Fix test suffix.
Add failing tests for #596.
Summary of problem or feature request
When paginating a query with a result set of nearly a million records, the query executes very slowly (>10 seconds).
Testing the generated query on Oracle SQL Developer, the query takes about 8 seconds.
A modification to the pagination query makes the query nearly instant, by using a combination of
rownum >= $start
andrownum <= $end
instead ofrownum between $start and end
. This is the pagination method explained here: https://blogs.oracle.com/oraclemagazine/on-rownum-and-limiting-results which was tested to be the fastest pagination option by https://stackoverflow.com/a/6536249I altered the generated query in
OracleGrammar.php
and got the query down from 5-12 seconds to 5-20 milliseconds:Here's an image album containing screenshots from query execution both in SQL Developer and in laravel, as shown by debugbar. Please note I did not screencap "cold" queries, so the values here are somewhat faster than they normally would be for first requests:
https://imgur.com/a/c0vzsTE
Note how the
between
method does not make use of the STOPKEY operation, which makes it much slower.I'm unsure if this behavior is the same on more recent versions of oracle. If anyone can test the changes on later versions I'd appreciate it.
System details
The text was updated successfully, but these errors were encountered: