user7325973
user7325973

Reputation: 182

How to handle large database in Laravel application faster?

What is the best way to process large mysql database faster in laravel application. I have a table which has round 6,00,000 records. What could be best practices to handle this data to select or query this table in optimised and faster way.

Upvotes: 1

Views: 7051

Answers (1)

user1436631
user1436631

Reputation:

If you are trying to retrieve a specific row or set of rows. you need not to worry. It will be faster. but if you are trying to retrieve all the rows from the table and manipulate its data, its better to use chunk

Model::chunk(100, function ($chunked_results) {
   //do your work here
});

This will retrieve 100 rows each time and pass them to the callback function.

if you have relations with them, it is better to eager load them as

Model::with('relations')->chunk(100, function ($chunked_results) {
   //do your work here
});

see chunk

Upvotes: 4

Related Questions