I wrote a query in Laravel which is:
$policy = DB::table('policies')-> join('customers','policies.customer_id','=','customers.id')-> join('cities','customers.city_id','=','cities.id')-> join('policy_motors','policies.id','=','policy_motors.policy_id')-> join('vehicle_makes','policy_motors.vehicle_make','=','vehicle_makes.id')-> join('vehicle_models','policy_motors.vehicle_model','=','vehicle_models.id')-> select('policies.policy_number','policies.insurance_premium','policies.commission', 'policies.effective_start_date', 'policies.effective_end_date','customers.name_en', 'customers.address1','customers.address2','cities.name_en','policy_motors.policy_type', 'vehicle_makes.name_en','vehicle_models.name_en')-> where('policies.policy_number','=','DB202017036583')->first(); This query worked perfectly on my Mac. However, when my colleague ran the same query on his Windows machine, it was taking forever. So he wrote one himself, that is:
$policy = Policy::with('customer', 'motor', 'user')-> where('policy_number', 'RK202117017053')->first(); His query worked perfectly on his Windows and my Mac.
Questions: 1. Although my query is selecting only required columns, it is taking forever. But his query, which takes all the columns of the joined table executes faster. Why is that happening?
2. What difference does it make to run a query on different machines, the time difference should be that significant?