对CLOB字段执行全文检索的比较

来源:未知 责任编辑:责任编辑 发表时间:2013-08-27 15:59 点击:

    sns.t_news 表的content_txt 字段为 CLOB类型,共3683行数据。分析见下:
--1.使用like:
SQL> select * from sns.t_news t  where t.content_txt  like '%广东%';
执行计划
| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |        |     6 |  7662 |    11   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T_NEWS |     6 |  7662 |    11   (0)| 00:00:01 |
----------------------------------------------------------------------------
统计信息
          3  recursive calls
          0  db block gets
       5092  consistent gets
       2525  physical reads
          0  redo size
   10517580  bytes sent via SQL*Net to client
    7056514  bytes received via SQL*Net from client
       6110  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
        906  rows processed
        
--2. 使用dbms_lob.instr:      
SQL> select * from sns.t_news t  where  dbms_lob.instr(t.content_txt,'广东',1,1) > 0;         
执行计划
| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |        |     7 |  8939 |    10   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T_NEWS |     7 |  8939 |    10   (0)| 00:00:01 |
----------------------------------------------------------------------------
统计信息
        656  recursive calls
          0  db block gets
       6358  consistent gets
       2548  physical reads
          0  redo size
       其余同上       
--3. 使用  instr函数:
SQL> select * from sns.t_news t  where  instr(t.content_txt,'广东',1,1) > 0;
执行计划
| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |        |     7 |  8939 |    11   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T_NEWS |     7 |  8939 |    11   (0)| 00:00:01 |
----------------------------------------------------------------------------
统计信息
          1  recursive calls
          0  db block gets
       5091  consistent gets
       2525  physical reads
          0  redo size
    其余同上    
        
--4. 使用域索引:
--建域索引使用92.5秒
SQL>  CREATE INDEX idx_content_txt ON sns.t_news(content_txt) INDEXTYPE IS CTXSYS.CONTEXT;
SQL> select * from sns.t_news t  WHERE contains (t.content_txt, '广东') > 0;
执行计划
| Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU)| Time  |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |               |     1 |  1277 |     4(0)| 00:00:01 |
|   1 | TABLE ACCESS BY INDEX ROWID| T_NEWS         |     1 |  1277 |     4(0)| 00:00:01 |
|*  2 | DOMAIN INDEX              | IDX_CONTENT_TXT |       |       |     4(0)| 00:00:01 |
--------------------------------------------------------------------------------
统计信息
         11  recursive calls
          0  db block gets
       3064  consistent gets
       2054  physical reads
          0  redo size
   其余同上  

--直观的比较:
                      like   dbms_lob.instr    instr     contains  
  recursive calls       3       656               1           11
  db block gets         0         0               0            0
  consistent gets    5092      6358            5091         3064
  physical reads     2525      2548            2525         2054
  redo size             0         0               0            0
     总结不用说了,上面的一目了然,顺便提下测试时要从远程数据库取数据,用下面的语句报错
 select * from t_news@SNS.US.ORACLE.COM  t;
 ORA-22992: 无法使用从远程表选择的 LOB 定位符
 --使用下面的可以
 create table t_news_back as select * from  t_news@SNS.US.ORACLE.COM  t;  
 
  --注释: 统计列         解释
     db block gets      从buffer cache中读取的block的数量
     consistent gets    从 buffer cache中读取的undo数据的block的数量
     physical reads     从磁盘读取的block的数量
     redo size          DML生成的redo的大小
     sorts (memory)     在内存执行的排序量
     sorts (disk)       在磁盘上执行的排序量  
     recursive calls    递归调用        
        

本文出自 “srsunbing” 博客,请务必保留此出处http://srsunbing.blog.51cto.com/3221858/800328

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Request.ServerVariables 参数大全
    • 执行全文索引时出现权限不足的解决方法
    • 导入excel文件处理流程节点的解决方案
    • 查看sql修改痕迹(SQL Change Tracking on Table)
    • MongoDB安装为Windows服务方法与注意事项
    • App数据层设计及云存储使用指南
    • PostgreSQL启动过程中的那些事三:加载GUC参数
    • Percolator与分布式事务思考(二)
    • 写给MongoDB开发者的50条建议Tip1
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1