I recently translated part of the code into production in an oracle database, where one of the more experienced developers who reviewed this said that I had too many exists and not exists statements and that there should be a way to delete them, but it took too long. since he had to use it and didn’t remember much about how it works. Currently, I’ll be back and make part of the code more convenient, as it can be changed several times in the following years as the business logic / requirements change, and I would like to continue and optimize it, making it more convenient for maintenance.
I tried looking for it, but all I can find is recommendations for replacing not in with not exists and not returning valid results.
As such, I wonder what can be done to optimize exists / not exists or if there is a way to write exists / not exists so that the oracle optimizes it internally (probably with better than I can).
For example, how can you optimize the following?
UPDATE SCOTT.TABLE_N N SET N.VALUE_1 = 'Data!' WHERE N.VALUE_2 = 'Y' AND EXISTS ( SELECT 1 FROM SCOTT.TABLE_Q Q WHERE N.ID = Q.N_ID ) AND NOT EXISTS ( SELECT 1 FROM SCOTT.TABLE_W W WHERE N.ID = W.N_ID )
source share