I am a relatively new developer in PL-SQL Oracle11g. As part of my studies, I am in a debate with the lecturer regarding the effectiveness of the UPDATE operation on a table.
In the following code, I argue that the part of WHERE EXISTS should be added, because it optimizes the operation and prevents an unnecessary update in case no values were found in the placement, i.e. SET c.text = NULL
UPDATE customer c
SET c.text =
(SELECT tmp.offer_desc
FROM tmp_main tmp
WHERE c.o_id = tmp.o_id
AND c.c_id = tmp.c_id)
** WHERE EXISTS (SELECT 1
FROM tmp_main tmp tmp
WHERE c.o_id = tmp.o_id
AND c.c_id = tmp.c_id)**;
It should be noted that the operation affects millions of records, so the runtime and resource usage is critical.
On the other hand, my lecturer claims that it is unnecessary, and the very fact that I perform a SELECT operation twice in this run is pointless and the WHERE EXISTS code segment should be removed.
I am completely confused. I also use Oracle execution plan to verify both ways, and it is clearly seen that the cost is lower when using the aforementioned WHERE EXISTS. But my lack of experience may be misleading me..?
So what should/better/effective?
mergeto avoid the repetitive code, and possibly the argument...