Laravel eloquont query takes long time to fetch data

  eloquent, laravel, laravel-8

I have a query just to retrieve the data, when I try to fetch 10k data from below query it will take more than 1.7mins. It that reasonable or how can I improve this time.

Vehicles::leftJoin('vehicle_details', 'vehicle_details.id', 'vehicles.vehi_details_id')
        ->leftJoin('vehicle_extras', 'vehicle_extras.vehicle_id','vehicles.id')
        ->leftJoin('reasons', 'reasons.vehicle_id', 'vehicles.id')
        ->leftJoin('revised_vehicles', 'revised_vehicles.vehicle_id','vehicles.id')
        ->leftJoin('makes', 'makes.model_id', 'vehicle_details.model_id')
        ->leftJoin('bidder_invoices', 'bidder_invoices.vehicle_id', '=', 'vehicles.id')
        ->leftJoin('bidding_views', 'bidding_views.vehicle_id', '=', 'vehicles.id')
        ->leftJoin('bidder_prs', 'bidder_prs.vehicle_id', '=', 'vehicles.id')
        ->leftJoin('bidder_remarks', 'bidder_remarks.vehicle_id', '=', 'vehicles.id')
        ->leftJoin('vehicle_pins', 'vehicle_pins.vehicle_id', '=', 'vehicles.id')
        ->leftJoin('translations', 'translations.vehicle_id', '=', 'vehicles.id')
        ->whereNull('vehicles.deleted_at')
        ->where(function ($query) {
            $query->where('vehicles.multiple_po', 0)
                ->orWhereNull('vehicles.multiple_po');
        })
        ->where(function ($query) {
            $query->where('vehicles.approve', '=', 1)
                ->orWhereNull('vehicles.approve');
        })
        ->orderBy('vehicles.site', 'ASC')
        ->orderBy('vehicles.auc_time', 'ASC')
        ->select([
            'vehicles.*',
            'vehicle_details.color as vehi_color',
            'vehicle_details.grade as vehi_grade',
            'vehicle_details.images',
            'makes.model_name',
            'vehicle_extras.id as extra_details_id',
            'vehicle_extras.ic_remarks',
            'vehicle_extras.bidder_adj',
            'reasons.fob_issue',
            'reasons.fob_approve',
            'reasons.decline_remark',
            'reasons.tc_issue',
            'reasons.fob_overruling_remark',
            'bidder_invoices.invoice_name',
            'bidding_views.reason as bidder_reason',
            'bidder_prs.bidder_mb as bidder_mb',
            'bidder_remarks.bidder_remarks as bidder_remarks_daily',
            'revised_vehicles.old_mb_round',
            'translations.assigned_translator'
        ])
        ->paginate(10000);

I have also added index for every join colums.

Source: Laravel

Leave a Reply