This tip mainly focuses on improving the memory usage of your application when dealing with large datasets. If your application needs to process a large set of records, instead of retrieving them all at once, you can retrieve a subset of results and process them in groups. This approach will make more database queries but highly memory efficient.

15m read timeFrom hamidafghan.me
Post cover image
Table of contents
1. Retrieving large datasets2. Select only the columns you need3. Use pluck when you need exactly one or two columns from the database4. Count rows using query instead of collection5. Avoid N+1 queries by eager loading relationship6. Eager load nested relationship7. Do not load belongsTo relationship if you just need its id8. Avoid unnecessary queries9. Merge similar queries together10. Add index to frequently queried columns11. Use simplePaginate instead of Paginate12. Avoid using leading wildcards(LIKE keyword)13. avoid using SQL functions in where clause14. avoid adding too many columns to a table15. separate columns with text data type into their own table16. Better way to retrieve latest rows from a table17. optimize mysql inserts18. Inspect and optimize queries
3 Comments

Sort: