Sales invoice save "Request Timed Out"


I’ve just migrated my database to a new server (v14 Intel to v14 AMD). I’m suddenly experiencing extremely slow Sales Invoice save/submits. The offending db query seems to be the one below. It takes about 540 seconds to execute. I haven’t created any additional indexes but I didn’t have them on my previous server either. Any help would be greatly appreciated. Thanks!

			'Journal Entry' as reference_type, as reference_name,
			t1.remark as remarks, t2.credit_in_account_currency as amount, as reference_row,
			t2.reference_name as against_order, t2.exchange_rate
			`tabJournal Entry` t1, `tabJournal Entry Account` t2
		where = t2.parent and t2.account = 'Debtors - LPEB'
			and t2.party_type = 'Customer' and = '<party_name>'
			and t2.is_advance = 'Yes' and t1.docstatus = 1
			and credit_in_account_currency > 0  and ( (t2.reference_type = 'Sales Order' and coalesce(t2.reference_name, '') in ('SO-PEB-2223-026')))
		order by t1.posting_date

Installed Apps

ERPNext: v14.5.1 (version-14)
Frappe Framework: v14.14.1 (version-14)
Frappe HR: v1.0.0 (develop)
India Compliance: v14.0.2 (version-14)
Payments: v0.0.1 (develop)

Seems to have resolved itself overnight. I can see using EXPLAIN that the query is now using the index (type index_merge/eq_ref), whereas earlier it was showing type SIMPLE. Does it take time to build the indexes after restoring a site from a backup?