-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Improve pagination performance by using ROW_NUMBER() and handling default orderBys.
yajra
changed the title
Update compileTableExpression in OracleGrammar.php
feat: improve pagination performance
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 |
yajra
reviewed
Aug 8, 2024
@@ -174,7 +174,18 @@ protected function compileTableExpression($sql, $constraint, $query) | |||
return "select * from ({$sql}) where rownum {$constraint}"; | |||
} | |||
|
There was a problem hiding this comment.
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); |
This will be implemented via #879. Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improve pagination performance by using ROW_NUMBER() and handling default orderBys.
Fix: #870