oracle全文索引优化like
oracle全文索引优化like最近一个业务,本来调的差不多了,但是新问题又来了,发现两条LIKE '%XXX%',看到这个,心碎了,表记录现在大约11W吧,全表扫描啊,你妹的,这种SQL其实业务就不改让上,直接打回去重写好了。可是,现在只能从我这边做优化了,问了问开发,只能是完全模糊查询,'%xxx'和'xxx%'都不行啊,'xxx%'大家知道,一般都可以用到索引,'%xxx'这个其实也好优化,用reverse呗,之后又想了想,用正则REGEXP_LIKE?用instr????,都不行,因为百分号中间那玩意是个变量。这可如何是好,想想还是用全文索引看看如何吧,完了做了把实验,效果还可以。粗略步骤如下:conn /as sysdba@?/ctx/admin/catctx.sql ctxsys tbs_ctxsys temp unlock这里指定了用户名,表空间,临时表空间,并且解锁创建ctxsys用户grant execute on ctx_ddl to yypt;conn yypt/xxxxxxxxxbeginctx_ddl.create_preference ('YYPT_CHINESE_LEXER', 'chinese_vgram_lexer');end;/exec ctx_ddl.drop_preference('YYPT_CHINESE_LEXER');CREATE INDEX IDX_bookinfo_keyword ON book_info(keyword)INDEXTYPE IS CTXSYS.CONTEXT PARAMETERS ('LEXER YYPT_CHINESE_LEXER');CREATE INDEX IDX_bookinfo_name ON book_info(name)INDEXTYPE IS CTXSYS.CONTEXT PARAMETERS ('LEXER YYPT_CHINESE_LEXER');CREATE INDEX IDX_bookinfo_author ON book_info(author)INDEXTYPE IS CTXSYS.CONTEXT PARAMETERS ('LEXER YYPT_CHINESE_LEXER');这里如果在创建索引的时候出现DRG-10700错误,请参考一下用CTXSYS用户登陆@?/ctx/admin/defaults/dr0defin.sql "AMERICAN";SQL> explain plan for SELECT A.AUTHOR,2 A.ID BOOK_ID,3 A.NAME BOOK_NAME,4 A.FEE,5 A.AN_NAME,6 A.IS_USE,7 A.BOOK_STYLE,8 DECODE(b.sum,NULL,0,b.sum) num9 FROM BOOK_INFO A, BOOK_HISTORY_DOWNLOAD B10 WHERE 1 = 111 AND A.ID = B.BOOKID(+)12 AND A.S_LEVEL <= 213 AND A.BOOKSTATE = 114 AND (A.KEYWORD LIKE '%三国%' OR A.NAME LIKE '%三国%' OR A.AUTHOR LIKE '%三国%')15 ORDER BY num DESC;Explained.Elapsed: 00:00:00.01SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT------------------------------------------------------------------------------------------------------------------------Plan hash value: 2129267741-------------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |-------------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 3866 | 400K| 6528 (1)| 00:01:19 || 1 | SORT ORDER BY | | 3866 | 400K| 6528 (1)| 00:01:19 || 2 | NESTED LOOPS OUTER | | 3866 | 400K| 6527 (1)| 00:01:19 ||* 3 | TABLE ACCESS FULL | BOOK_INFO | 3866 | 366K| 1442 (1)| 00:00:18 || 4 | TABLE ACCESS BY INDEX ROWID| BOOK_HISTORY_DOWNLOAD | 1 | 9 | 3 (0)| 00:00:01 ||* 5 | INDEX RANGE SCAN | IDX_HISTORY_DOWNLOAD | 1 | | 1 (0)| 00:00:01 |-------------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------3 - filter("A"."BOOKSTATE"=1 AND ("A"."KEYWORD" LIKE '%三国%' OR "A"."NAME" LIKE '%三国%' OR"A"."AUTHOR" LIKE '%三国%') AND "A"."S_LEVEL"<=2)5 - access("A"."ID"="B"."BOOKID"(+))SQL> explain plan for SELECT A.AUTHOR,2 A.ID BOOK_ID,3 A.NAME BOOK_NAME,4 A.FEE,5 A.AN_NAME,6 A.IS_USE,7 A.BOOK_STYLE,8 DECODE(b.sum,NULL,0,b.sum) num9 FROM BOOK_INFO A, BOOK_HISTORY_DOWNLOAD B10 WHERE 1 = 111 AND A.ID = B.BOOKID(+)12 AND A.S_LEVEL <= 213 AND A.BOOKSTATE = 114 AND (contains(A.KEYWORD,'三国')>0 OR contains(A.name,'三国')>0 OR contains(A.author,'三国')>0)15 ORDER BY num DESC;Explained.Elapsed: 00:00:00.10SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT------------------------------------------------------------------------------------------------------------------------Plan hash value: 4091324736------------------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |------------------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 41 | 4838 | 110 (1)| 00:00:02 || 1 | SORT ORDER BY | | 41 | 4838 | 110 (1)| 00:00:02 || 2 | NESTED LOOPS OUTER | |上一个:创建oracle练习表
下一个:LOGMNR挖掘日志与DUMP日志对比
- 更多Oracle疑问解答:
- 运行exp备份oracle数据库提示oracle-12154错误
- 有没有,生产Oracle Rman 备份脚本的工具啊!
- 初学orcle,希望有大大帮忙解说一下详细步骤,从登录oracle到创建表的过程
- oracle语句问题:一张user表,三个字段,id,name,time,插入记录比如:张三2007,李四2008,张三2011
- 如何写一个ORACLE触发器同步两个表中的数据?
- oracle 如何查看一个服务器上有多少个数据库.
- oracle 创建包的时候错误 求解
- oracle 重复列的问题
- oracle 中如何查处2星期前的数据
- 请教oracle数据库安装中的问题
- 请问谁能提供给我标准的oracle ERP的数据库表结构并详细说明各表主要的作用?
- 安装oracle遇到的问题 invalid entry CRC (expected 0x3e12e795 but got 0x9db0e9fd)
- 我的是ORACLE 10G,在RMAN中如何按指定的时间恢复数据文件啊?
- oracle为什么没有自动增长列
- oracle快捷键都有哪些啊?