skip to Main Content

I need to get catalogs from database using Laravel query, so I write simply:

   $catalogs = Catalog::where('shop_id', $shop->id)->latest()->get(['id','title', 'created_at', 'shop_id', 'cover_bg', 'frontpage', 'pdf', 'clicks', 'finished']);

In a catalog table I have more than 100 columns – 2 of them are with type longtext. Catalog currently contain around 14000 records and fetching data is very slow:

Here is phpMyAdmin execution time

enter image description here

Here is Laravel query execution time:
enter image description here

How I can speed up my query? I think 14 000 records are not big table. Also as you can see I try to avoid my longtext columns so I didnt fetch them.

Is it problem with a server performance or something else?

Also CPU very low:
enter image description here

2

Answers


  1. Try switching to using raw query, not Eloquent by using DB::select(DB::raw('...'))

    Login or Signup to reply.
  2. This is because something called N+1 Query Issue that rapidly increases the total queries ..

    I recommend you to read this article

    https://laravel-news.com/laravel-n1-query-problems

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search