用下面的 case 在 Oracle 11.2 上执行,发现 Oracle 实现的 NAAJ 算法有正确性 bug。不知最新版本修复了没有?
CREATE TABLE FF1 (A1 INT, B1 INT);
CREATE TABLE FF2 (A2 INT, B2 INT);
INSERT INTO FF1 SELECT LEVEL,LEVEL FROM DUAL CONNECT BY LEVEL <= 10;
INSERT INTO FF2 SELECT LEVEL,LEVEL FROM DUAL CONNECT BY LEVEL <= 66;
INSERT INTO FF2 SELECT 1,1 FROM DUAL CONNECT BY LEVEL <= 10;
INSERT INTO FF2 SELECT 2,2 FROM DUAL CONNECT BY LEVEL <= 10;
SELECT /*+ monitor*/ COUNT(*) FROM FF2 WHERE B2 NOT IN (SELECT L.A1 FROM FF1 L RIGHT JOIN FF2 R ON R.A2 = L.A1 AND L.A1 IS NOT NULL );
尽管有错,但 Oracle 有一点做得特别好:
这个网址里列出了所有已知的 Oracle 正确性 bug:https://oracleblog.org/working-case/bug-issues-known-to-cause-wrong-results/