I have got an big query that basically just adds a couple of with()'s, whereBetween() and orderBy. At the end i use a simplePaginate(500) because i don't want to call all 30mil records obviously.
Problem is that whenever i use a join than it will take couple minutes to load it, but when i dont use it than it only takes 2 seconds.
my query->join:
$query
->join('balance_accounts', 'balances.balanceable_id','=', 'balance_accounts.id')
->join('currencies', 'currencies.id', "=", 'balance_accounts.currency_id')
->join('balance_types', 'balance_types.id', "=", 'balance_accounts.balance_type_id')
->select("balances.*", "currencies.short_name", "balance_types.name");
i have put indexes on every column. Maybe im putting indexes wrong because it's foreign, i have no idea..
here are my index that i have put on table 'balances':
here are my index that i have put on table 'balance_accounts':