0
I have two tables:
Sale > 100 Records Primary key fields: Invoice
Payments > 200,000 Records Primary key fields: Id, Invoice, Type, Document.
I have the following SQL:
Select V.FATURA, P.ID
From Venda V
Left Join Pagamentos P on p.FATURA = V.FATURA
Where v.DTEMI between '25.09.2018' and '25.09.2018'
But it is very slow. What can I do to improve the performance?
The field
Fatura
tablepagamentos
is foreign table keyvenda
?? Put the structure of your two tables in the question to facilitate understanding!– Matheus Ribeiro
No, I don’t have a foreign key connecting these tables. It’s an old legacy system. As I put up there the Sale table has the primary key field: invoice only. The Payments table has four primary key fields. @Matheusribeiro
– Jack
Did my answer help you? Feedback is always welcome!
– Matheus Ribeiro
I added the index, but I didn’t see any improvement. The foreign key helped, but I can’t create it without deleting the duplicate items first, so it’s not viable for me. I haven’t had time to look for other solutions, but something put here
– Jack