select account_no from accounts a where account_name = 'HARRY' and sub_account_name not in ( select account_name from accounts where account_no = a.old_account_no and status is not null);
顾问建议如下:
1- RestrUCture SQL finding (see plan 1 in eXPlain plans section) ---------------------------------------------------------------- The optimizer could not unnest the subquery at line ID 1 of the execution plan. Recommendation -------------- Consider replacing "NOT IN" with "NOT EXISTS" or ensure that columns used on both sides of the "NOT IN" Operator are declared "NOT NULL" by adding either "NOT NULL" constraints or "IS NOT NULL" predicates. Rationale --------- A "FILTER" operation can be very expensive because it evaluates the subquery for each row in the parent query.The subquery, when unnested can drastically improve the execution time because the "FILTER" operation is converted into a join.Be aware that "NOT IN" and "NOT EXISTS" might produce different results for "NULL" values.
这一次顾问不会建议任何结构上的更改(如索引),但会通过用 NOT EXISTS 取代 NOT IN的方式很聪明地猜测到调整查询的正确方式。由于两种构造相似但不相同,顾问给出了这种改变的基本原理,并把决定权留给 DBA 或应用程序开发人员,由他们决定该建议是否对环境有效。