Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve pagination performance #878

Closed
wants to merge 1 commit into from

Conversation

alexc-jeromes
Copy link

@alexc-jeromes alexc-jeromes commented Aug 7, 2024

Improve pagination performance by using ROW_NUMBER() and handling default orderBys.
Fix: #870

Improve pagination performance by using ROW_NUMBER() and handling default orderBys.
@yajra yajra changed the title Update compileTableExpression in OracleGrammar.php feat: improve pagination performance Aug 7, 2024
@yajra
Copy link
Owner

yajra commented Aug 7, 2024

I tried the patch on my starter app and got a 904 error:

Error Code    : 904
Error Message : ORA-00904: "PERMISSIONS"."ID": invalid identifier
Position      : 77
Statement     : select * from (
                    select t1.*, row_number() over (order by "PERMISSIONS"."ID" asc) as row_num
                    from (select * from "PERMISSIONS" where "RESOURCE" in (:p0, :p1, :p2, :p3, :p4) order by "PERMISSIONS"."ID" asc) t1
                ) where row_num between 1 and 1000
Bindings      : [Users,Roles,Permissions,Authorizations,System]

Need to adjust the order clause and use the table alias t1 instead:

order by "PERMISSIONS"."ID" asc

-- TO --

order by t1."ID" asc

@@ -174,7 +174,18 @@ protected function compileTableExpression($sql, $constraint, $query)
return "select * from ({$sql}) where rownum {$constraint}";
}

Copy link
Owner

@yajra yajra Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the codes below seems to fix 904 issues from migration to actual app execution:

Suggested change
$orders = $query->orders;
foreach($orders as $key => $order) {
if (isset($order['sql'])) {
[$column, $direction] = explode(' ', $order['sql']);
if (Str::contains($column, '.')) {
[$table, $column] = explode('.', $column);
$orders[$key]['sql'] = 't1.'.$column.' '.$direction;
}
continue;
}
if (isset($order['column']) && Str::contains($order['column'], '.')) {
[,$column] = explode('.', $order['column']);
$orders[$key]['column'] = 't1.'.$column;
}
}
// Apply ROW_NUMBER() for pagination
$orderBy = $this->compileOrders($query, $orders);

@yajra
Copy link
Owner

yajra commented Aug 9, 2024

This will be implemented via #879. Thanks!

@yajra yajra closed this Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improving pagination performance
2 participants