I restored 2 databases from 1 backup. One is for Firebird 2.5, and the other is for Firebird 5.0.3 (the latest version).
Then I executed a query.
SELECT CON.ID
FROM INV_CARD C
LEFT JOIN INV_BALANCE M ON C.ID = M.CARDKEY
INNER JOIN GD_CONTACT CON ON M.CONTACTKEY = CON.ID
WHERE M.BALANCE <> 0
AND C.USR$FA_INVCARDKEY > 0
In Firebird 2.5, everything works correctly.
In Firebird 5.0.3, it ignores the condition (the primary key) and retrieves all the data. The result of the execution is correct, but the speed is tens of times slower.
Execution plan for Firebird 2.5:

Execution plan for Firebird 5.0.3 (latest version):

Additionally:
If I change the join to a LEFT JOIN, everything starts to work as it should.
Modified query:
SELECT CON.ID
FROM INV_CARD C
LEFT JOIN INV_BALANCE M ON C.ID = M.CARDKEY
LEFT JOIN GD_CONTACT CON ON M.CONTACTKEY = CON.ID
WHERE M.BALANCE <> 0
AND C.USR$FA_INVCARDKEY > 0
AND CON.ID IS NOT NULL
Execution plan for the modified query on Firebird 5.0.3:

P.S. The indexes have been recomputed.
I restored 2 databases from 1 backup. One is for Firebird 2.5, and the other is for Firebird 5.0.3 (the latest version).
Then I executed a query.
In Firebird 2.5, everything works correctly.
In Firebird 5.0.3, it ignores the condition (the primary key) and retrieves all the data. The result of the execution is correct, but the speed is tens of times slower.
Execution plan for Firebird 2.5:
Execution plan for Firebird 5.0.3 (latest version):
Additionally:
If I change the join to a LEFT JOIN, everything starts to work as it should.
Modified query:
Execution plan for the modified query on Firebird 5.0.3:
P.S. The indexes have been recomputed.