My best suggestion is looking at indexes. How are they now? Did you test it with explain?
Mar 1, 2022
10
Level 3
Is there a way to make this query faster?
This is the same query from my previous posts:
DB::table('items')->select('items_to_list.user_id', 'items.item_code')
->distinct('items_to_list.user_id')
->leftJoin('items_to_list','user_id', '=', 'items.id')
->where('items_to_list.status', '=', 0)
->where('items.deleted', '=', 0)
->get()
If items_to_list table has 100,000 rows, this query takes about 0.8 seconds. Then with the additional code, it totals for slightly over 1 second to fetch this data.
Is there a way to optimize this query and make it run faster?
Thanks!
Please or to participate in this conversation.