Likely bottleneck: Finding the most recent payment per loan requires a sort or correlated subquery on 50 million payment rows. - Recommendation: Create an index on loan_payments(loan_id, payment_date DESC) to enable efficient retrieval of the most recent payment per loan. Consider a lateral join or