substr(a.object_name, 1, length(b.object_name)) = b.object_name 优化
来源:互联网 发布:大疆飞控算法 编辑:程序博客网 时间:2024/05/29 19:19
今早在ITPUB上面看到一贴,思路不错记录下来。
http://www.itpub.net/thread-1376537-1-1.html
SQL> select a.*,b.object_name from test1 a,test2 b where substr(a.object_name,1,length(b.object_name)) = b.object_name;27618 rows selected.Execution Plan----------------------------------------------------------Plan hash value: 3862800485-----------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |-----------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 78405 | 16M| 142K (1)| 00:28:29 || 1 | NESTED LOOPS | | 78405 | 16M| 142K (1)| 00:28:29 || 2 | TABLE ACCESS FULL | TEST1 | 28954 | 4467K| 288 (1)| 00:00:04 ||* 3 | INDEX FAST FULL SCAN| IND_TEST2 | 3 | 198 | 5 (0)| 00:00:01 |-----------------------------------------------------------------------------------Predicate Information (identified by operation id):--------------------------------------------------- 3 - filter("B"."OBJECT_NAME"=SUBSTR("A"."OBJECT_NAME",1,LENGTH("B"."OBJE CT_NAME")))Note----- - dynamic sampling used for this statement (level=2)Statistics---------------------------------------------------------- 0 recursive calls 0 db block gets 585568 consistent gets 0 physical reads 0 redo size 693251 bytes sent via SQL*Net to client 20774 bytes received via SQL*Net from client 1843 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 27618 rows processed
SQL> select a.*, b.object_name 2 from test1 a, test2 b 3 where substr(a.object_name, 1, length(b.object_name)) = b.object_name 4 and substr(a.object_name, 1, 4) = substr(b.object_name, 1, 4) 5 and length(b.object_name) > 3 6 union all 7 select a.*, b.object_name 8 from test1 a, test2 b 9 where substr(a.object_name, 1, length(b.object_name)) = b.object_name 10 and length(b.object_name) < 4;27618 rows selected.Execution Plan----------------------------------------------------------Plan hash value: 1525591892------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 3751 | 820K| 50193 (100)| 00:10:03 || 1 | UNION-ALL | | | | | ||* 2 | HASH JOIN | | 754 | 164K| 302 (3)| 00:00:04 ||* 3 | INDEX FAST FULL SCAN| IND_TEST2 | 4378 | 282K| 7 (0)| 00:00:01 || 4 | TABLE ACCESS FULL | TEST1 | 28954 | 4467K| 288 (1)| 00:00:04 || 5 | NESTED LOOPS | | 2997 | 655K| 49891 (1)| 00:09:59 ||* 6 | INDEX FAST FULL SCAN| IND_TEST2 | 174 | 11484 | 7 (0)| 00:00:01 ||* 7 | TABLE ACCESS FULL | TEST1 | 17 | 2686 | 287 (1)| 00:00:04 |------------------------------------------------------------------------------------Predicate Information (identified by operation id):--------------------------------------------------- 2 - access(SUBSTR("A"."OBJECT_NAME",1,4)=SUBSTR("B"."OBJECT_NAME",1,4)) filter("B"."OBJECT_NAME"=SUBSTR("A"."OBJECT_NAME",1,LENGTH("B"."OBJEC T_NAME"))) 3 - filter(LENGTH("B"."OBJECT_NAME")>3) 6 - filter(LENGTH("B"."OBJECT_NAME")<4) 7 - filter("B"."OBJECT_NAME"=SUBSTR("A"."OBJECT_NAME",1,LENGTH("B"."OBJEC T_NAME")))Note----- - dynamic sampling used for this statement (level=2)Statistics---------------------------------------------------------- 13 recursive calls 0 db block gets 183117 consistent gets 0 physical reads 0 redo size 1006639 bytes sent via SQL*Net to client 20774 bytes received via SQL*Net from client 1843 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 27618 rows processed这里由于将数据分片,引入了谓词substr(a.object_name, 1, 4) = substr(b.object_name, 1, 4),从而可以使用HASH JOIN。当然这里的4是根据具体情况来确定的。总得原则就是根据实际情况确定此值的大小,使得结果集大的部分可以做HASH_JOIN,而小的结果集交给NL.
0 0
- substr(a.object_name, 1, length(b.object_name)) = b.object_name 优化
- SQL中OBJECT_ID,OBJECT_NAME,OBJECT_DEFINITION的用法
- SQL中OBJECT_ID,OBJECT_NAME,OBJECT_DEFINITION的用法
- SQL中OBJECT_ID,OBJECT_NAME,OBJECT_DEFINITION的用法
- 126 You executed the following commands in a database session: SQL> SELECT object_name, original_nam
- Error 3724:Cannot drop the table 'object_name' because it is being used for replication.
- Error 3724:Cannot drop the table 'object_name' because it is being used for replication.
- 将object_name 按每列18条数据,6列存储
- 数组逆序关键是 b[i]=a[a.length-1-i]
- A^B = B^A
- A^B = B^A
- A^B = B^A
- A^B=B^A
- Python a,b=b,a+b
- 5-2-1 数组变量-直接初始化数组-length优势-int[] b=a-a让b共同管理数组-复制数组
- a,b=b,a+b 与 a=b,b=a+b
- a = b + (b = a) * 0;
- SGU 112 a^b - b^a 大数+二进制优化
- C语言经典算法100例-003-加100是完全平方数
- 最后一个寒假结束
- android 绘制折线图(AChartEngine)Linechart 动态更新横轴为获取的当前时间
- 关键技术汇总
- SQLServer数据库约束(1)_表内约束(单表的五类约束)_附自增属性以及全局唯一性标识符类型作为主键
- substr(a.object_name, 1, length(b.object_name)) = b.object_name 优化
- poj 1837 DP
- test
- Protel中的元器件旋转
- Vim多文件搜索特定内容
- 回调函数
- RESTEasy使用httpclient上传文件
- mysql_free_result&bool mysqli_close
- ecshop模版设置添加广告不成功