about me:oracle ace,optimistic,passionate and harmonious. focus on oracle programming,peformance tuning,db design, j2ee,linux/aix,web2.0 tech,etc
全部博文(145)
分类: oracle
2023-05-04 17:14:44
drop table t1;
create table t1 as select to_char(trunc(dbms_random.value(10000000000, 20000000000 ))) phone_no, trunc(dbms_random.value(0, 30 )) ext, lpad(rownum,10) v1, rpad('x',100) padding from dual connect by level <= 1000000; drop table t2; create table t2 as select to_char(trunc(dbms_random.value(10000000, 20000000000 ))) phone_no, trunc(dbms_random.value(0, 30 )) ext, lpad(rownum,10) v1, rpad('x',100) padding from dual connect by level <= 1000000; exec dbms_stats.gather_table_stats(ownname=>user,tabname=>'t1',no_invalidate=>false); exec dbms_stats.gather_table_stats(ownname=>user,tabname=>'t2',no_invalidate=>false); |
select phone_no,ext,v1,padding
from t1 where substr(t1.phone_no,1,8) in (select t2.phone_no from t2 where length(t2.phone_no)=8) or substr(t1.phone_no,1,9) in (select t2.phone_no from t2 where length(t2.phone_no)=9) or substr(t1.phone_no,1,10) in (select t2.phone_no from t2 where length(t2.phone_no)=10) or substr(t1.phone_no,1,11) in (select t2.phone_no from t2 where length(t2.phone_no)=11); |
execution plan
---------------------------------------------------------- plan hash value: 2055931425 --------------------------------------------------------------------------- | id | operation | name | rows | bytes | cost (%cpu)| time | --------------------------------------------------------------------------- | 0 | select statement | | 1 | 127 | 4970m (1)|999:59:59 | |* 1 | filter | | | | | | | 2 | table access full| t1 | 1000k| 121m| 5086 (1)| 00:01:02 | |* 3 | table access full| t2 | 1 | 12 | 4995 (1)| 00:01:00 | |* 4 | table access full| t2 | 1 | 12 | 4995 (1)| 00:01:00 | |* 5 | table access full| t2 | 1 | 12 | 4995 (1)| 00:01:00 | |* 6 | table access full| t2 | 1 | 12 | 4995 (1)| 00:01:00 | --------------------------------------------------------------------------- predicate information (identified by operation id): --------------------------------------------------- 1 - filter( exists (select 0 from "t2" "t2" where length("t2"."phone_no")=8 and "t2"."phone_no"=substr(:b1,1,8)) or exists (select 0 from "t2" "t2" where length("t2"."phone_no")=9 and "t2"."phone_no"=substr(:b2,1,9)) or exists (select 0 from "t2" "t2" where length("t2"."phone_no")=10 and "t2"."phone_no"=substr(:b3,1,10)) or exists (select 0 from "t2" "t2" where length("t2"."phone_no")=11 and "t2"."phone_no"=substr(:b4,1,11))) 3 - filter(length("t2"."phone_no")=8 and "t2"."phone_no"=substr(:b1,1,8)) 4 - filter(length("t2"."phone_no")=9 and "t2"."phone_no"=substr(:b1,1,9)) 5 - filter(length("t2"."phone_no")=10 and "t2"."phone_no"=substr(:b1,1,10)) 6 - filter(length("t2"."phone_no")=11 and "t2"."phone_no"=substr(:b1,1,11)) |
select t1.phone_no,t1.ext,t1.v1,t1.padding
from t1,(select distinct phone_no from t2 where length(t2.phone_no) between 8 and 11) t22 where t1.phone_no like t22.phone_no||'%' and substr(t1.phone_no,1,8)=substr(t22.phone_no,1,8); |
execution plan ---------------------------------------------------------- plan hash value: 1674805607 ---------------------------------------------------------------------------------- | id | operation | name | rows | bytes | cost (%cpu)| time | ---------------------------------------------------------------------------------- | 0 | select statement | | 50 | 4950 | 10198 (2)| 00:02:03 | | 1 | view | vm_nwvw_1 | 50 | 4950 | 10198 (2)| 00:02:03 | | 2 | hash unique | | 50 | 6950 | 10198 (2)| 00:02:03 | |* 3 | hash join | | 50 | 6950 | 10197 (2)| 00:02:03 | |* 4 | table access full| t2 | 2500 | 30000 | 4995 (1)| 00:01:00 | | 5 | table access full| t1 | 1000k| 121m| 5082 (1)| 00:01:01 | ---------------------------------------------------------------------------------- predicate information (identified by operation id): --------------------------------------------------- 3 - access(substr("t1"."phone_no",1,8)=substr("phone_no",1,8)) filter("t1"."phone_no" like "phone_no"||'%') 4 - filter(length("t2"."phone_no")>=8 and length("t2"."phone_no")<=11) |