Using a query with a table and a View, however if i change the where column the speed drastically changes. What can be the problem? its quite hard to google "performance changes on where clause" since all exemples are not even close to this.
SELECT ADRE.*
FROM INVOICE N
INNER JOIN ENTRY_INVOICE NAF
ON NAF.COMPANY = N.COMPANY
AND NAF.ID_INVOICE = N.ID_INVOICE
INNER JOIN UV_ENTRY_ALL ADRE
ON ADRE.COMPANY = NAF.COMPANY
AND ADRE.ID_ENTRY = NAF.ID_ENTRY
WHERE
NAF.COMPANY = 1
/*
AND NAF.ID_INVOICE = 113806
=> 40 SECONDS
AND NAF.ID_ENTRY = 387473
=> 0,6 SECONDS
AND EXISTS (SELECT 1 FROM ENTRY_INVOICE WHERE COMPANY = 1 AND ID_INVOICE=113806)
=> 1,6 SECONDS
*/
ENTRY_INVOICE IT HAS AT MOST 2 RECORDS FOR EACH INVOICE.
COMPANY | ID_INVOICE | ID_ENTRY |
---|---|---|
1 | 113706 | 387224 |
1 | 113706 | 387225 |
1 | 113707 | 387226 |
1 | 113806 | 387473 |
PLAN EXPLANATION https://exists-stack.tiiny.site/
As questioned, even if remove the table INVOICE, and select especific columns, it wont change the speed.