About me:Oracle ACE pro,optimistic,passionate and harmonious. Focus on ORACLE,MySQL and other database programming,peformance tuning,db design, j2ee,Linux/AIX,Architecture tech,etc
全部博文(172)
分类: 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) |