- 最后登录
- 2018-11-1
- 在线时间
- 377 小时
- 威望
- 29
- 金钱
- 6866
- 注册时间
- 2011-10-12
- 阅读权限
- 200
- 帖子
- 891
- 精华
- 4
- 积分
- 29
- UID
- 1
|
3#
发表于 2012-12-28 14:28:55
- SQL> create table x(id int,name varchar2(200));
- Table created.
- SQL> create table y(name varchar2(200));
- Table created.
- SQL> select * from x where x.id in (select id from y);
- no rows selected
- SQL> alter system flush shared_pool;
- System altered.
- SQL> analyze table x compute statistics;
- Table analyzed.
- SQL> analyze table y compute statistics;
- Table analyzed.
- SQL> alter session set events '10053 trace name context forever,level 1';
- Session altered.
- SQL> select * from x where x.id in (select id from y);
- no rows selected
- SQL> oradebug setmypid
- Statement processed.
- SQL> oradebug tracefile_name
- /u01/app/oracle/diag/rdbms/cdb1/cdb1/trace/cdb1_ora_21249.trc
- JPPD: Applying transformation directives
- query block SEL$1 (#1) unchanged
- FPD: Considering simple filter push in query block SEL$1 (#1)
- EXISTS (SELECT 0 FROM "Y" "Y")
- FPD: Considering simple filter push in query block SEL$2 (#2)
- :B1=:B2
- try to generate transitive predicate from check constraints for query block SEL$2 (#2)
- finally: :B1=:B2
- try to generate transitive predicate from check constraints for query block SEL$1 (#1)
- finally: EXISTS (SELECT 0 FROM "Y" "Y")
- Final query after transformations:******* UNPARSED QUERY IS *******
- SELECT "X"."ID" "ID", "X"."NAME" "NAME"
- FROM "SYS"."X" "X"
- WHERE EXISTS (SELECT 0 FROM "SYS"."Y" "Y" WHERE "X"."ID" = "X"."ID")
-
-
-
-
-
-
-
-
-
-
- 10053 后可以看到
-
- select * from x where x.id in (select id from y); 实际转换为
-
-
- SELECT "X"."ID" "ID", "X"."NAME" "NAME"
- FROM "SYS"."X" "X"
- WHERE EXISTS (SELECT 0 FROM "SYS"."Y" "Y" WHERE "X"."ID" = "X"."ID")
-
复制代码 即Oracle实际把select id from y这里的ID 理解为 X.ID,因为这个字段标示 仅在X表上有, 当指定Y.ID时因为实际Y表上不存在该字段所以报 ORA-00904错误 |
|