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

Filtered records count taking a long time #1516

Closed
lainga9 opened this issue Nov 21, 2017 · 12 comments
Closed

Filtered records count taking a long time #1516

lainga9 opened this issue Nov 21, 2017 · 12 comments

Comments

@lainga9
Copy link

lainga9 commented Nov 21, 2017

Summary of problem or feature request

When calculating the total filtered records in a datatable of ~1M record the count is taking up to 40s whereas the query to display the records is only taking 10ms.

Is there any way to disable the filtered records count?

I know there is a method setTotalRecords() which disables the count of the total number of records but would it be possible to add something similar to prevent the count taking place in the filterRecords() method in DataTableAbstract?

System details

  • Operating System MacOS Sierra
  • PHP Version 7.1.6
  • Laravel Version 5.5
  • Laravel-Datatables Version ~8.0
@yajra
Copy link
Owner

yajra commented Nov 23, 2017

Afaik, disabling filtered counts is not yet supported. Will try to dig this option when I got the chance.

On the other hand, have you tried optimizing your queries using indexes and other db optimization tricks?

@lainga9
Copy link
Author

lainga9 commented Nov 23, 2017

Great thanks!

Yeah I've tried to optimise as best I can. We have a table with roughly 50M rows which is well indexed and the select queries are fine, it just seems to be the count that takes ages.

@gmatkowski
Copy link

I agree this might be a huge improvement, looking forward to set filtered count manually.

@patrickwarner
Copy link
Contributor

Yes, this is a big problem for me as well.

@mahmutbest
Copy link

Yes, I am too need setFilteredCount for big tables.
Could you add feature, please

@patrickwarner
Copy link
Contributor

patrickwarner commented May 16, 2018

For anyone interested, I've circumvented this issue temporarily. I have a branch on my fork that adds a function setFilteredRecords() for the query builder datatable. This will allow you to manually set that count. My strategy to deal with large (many millions of rows) Innodb tables is to manually query the count and cache it to a unique key derived from the query that was executed. The query will take a long time to execute the first time around but any subsequent requests are instant.

If you want to include it via a VCS repo in your composer file be sure to make use of an alias so that other package dependencies don't throw versioning errors.

"yajra/laravel-datatables-oracle": "dev-filtered-count as 8.0.x-dev",

@yajra
Copy link
Owner

yajra commented May 17, 2018

@forgottencreature I just saw your changes and I think it's a good implementation for this issue. Would you mind submitting a PR?

BTW, this line is required and a fix added on v8.5.1.

@patrickwarner
Copy link
Contributor

@yajra Sure thing. I'll submit the PR tomorrow.

patrickwarner added a commit to patrickwarner/laravel-datatables that referenced this issue May 17, 2018
@patrickwarner
Copy link
Contributor

PR submitted!

patrickwarner added a commit to patrickwarner/laravel-datatables that referenced this issue May 17, 2018
yajra added a commit that referenced this issue May 18, 2018
[8.0] Add support for manual setting of filtered count (#1516)
yajra added a commit that referenced this issue May 18, 2018
* 8.0:
  Bump v8.6.0 🚀
  Add support for manual setting of filtered count (#1516)
@kamrava
Copy link

kamrava commented May 23, 2018

With this PR, Is it possible to completely disable the filtered count?

@patrickwarner
Copy link
Contributor

I considered adding support for that in this PR but I wasn't sure what that would look like given you need a count otherwise it won't know how many pages to display.

@kamrava
Copy link

kamrava commented May 23, 2018

@forgottencreature You're right.
What if count the Total Records and Filtered Records in PHP rather than SQL? Does it have better performance?

@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants