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
Here is Laravel query execution time:
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?
2
Answers
Try switching to using raw query, not Eloquent by using
DB::select(DB::raw('...'))
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