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

[11.x] Paginator total override #46410

Merged
merged 2 commits into from
Mar 25, 2023

Conversation

browner12
Copy link
Contributor

Resubmission to master of #46336

This allows the user to declare the total number of results a query returns. If the user provides this argument, the paginate() method will skip running its query to determine the total row count. to be clear, this does not change the number of actual results available, just how many the paginator thinks exist.

Why would we want to set this value when we can use a query to determine it?

Performance.

select count(*) as aggregate from `table_name` where `table_name`.`deleted_at` is null

can be terribly slow on large tables, depending on your database and table engine.

For example, on MySQL with an InnoDB engine, a table with 500,000 rows can take 300ms. Eliminating this query can save a considerable chunk on the entire request time.

You might ask, "why not use the simple paginator or cursor paginator to achieve this?". That would eliminate the extra query, but the downside is you lose the ability to quickly navigate directly to pages.

Users are free to calculate or choose this number any way they like. You could assume your users will never care about more than 100k records back from the most current, and use that if you like. Surprisingly, assuming your have an auto-incremented id field and rows are either never deleted or soft-deleted, you can run

select * from `table_name` order by `id` desc limit 1

to retrieve the last ID, and this query is significantly faster.

browner12 and others added 2 commits March 3, 2023 00:05
this allows the user to set the total number of results a query returns.  If the user provides this argument, the `paginate()` method will skip running its query to determine the total row count.
@browner12 browner12 changed the title Ab paginator total override [11.x] Paginator total override Mar 9, 2023
@taylorotwell taylorotwell merged commit a05ce6d into laravel:master Mar 25, 2023
@browner12 browner12 deleted the AB-paginator-total-override branch March 26, 2023 00:16
browner12 added a commit to browner12/docs that referenced this pull request Mar 26, 2023
GromNaN added a commit to GromNaN/laravel-mongodb-fork that referenced this pull request Jul 4, 2024
GromNaN added a commit to GromNaN/laravel-mongodb-fork that referenced this pull request Jul 5, 2024
GromNaN added a commit to GromNaN/laravel-mongodb-fork that referenced this pull request Jul 5, 2024
GromNaN added a commit to GromNaN/laravel-mongodb-fork that referenced this pull request Jul 5, 2024
GromNaN added a commit to GromNaN/laravel-mongodb-fork that referenced this pull request Jul 9, 2024
GromNaN added a commit to GromNaN/laravel-mongodb-fork that referenced this pull request Jul 9, 2024
GromNaN added a commit to mongodb/laravel-mongodb that referenced this pull request Jul 9, 2024
CDouglas1029 added a commit to CDouglas1029/laravel_MongoDB that referenced this pull request Nov 15, 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.

2 participants