Eloquent, APIs & Database Design - All Forum

Database Indexes: Improve Queries Without Indexing Everything

Indexes help a database find rows efficiently, but every index adds storage and makes writes more expensive. The goal is to index real query patterns rather than add an index to every column.Start with the slow query and inspect its filter conditions, joins, sort order, and execution plan. An index may help columns used in selective WHERE clauses or join keys. Composite index order matters: an ind...

  • 0
  • 0
Designing Eloquent Relationships Without N+1 Queries

Eloquent relationships make application code expressive, but a page can become slow when each row triggers another database query. This is the classic N+1 query problem.Suppose a page lists twenty topics and displays each author's name. Loading topics and then reading topic->user inside a loop may issue one query for the topics plus one query per author. Use eager loading with Topic::with('user')-...

  • 0
  • 0

We may use cookies or any other tracking technologies when you visit our website, including any other media form, mobile website, or mobile application related or connected to help customize the Site and improve your experience. learn more

Allow