-
Sep19
模糊查询like '%XX%' 的优化一例
Posted in DB性能优化, Oracle, 数据库管理, 1,884 views
-
sql中的like '%xx%'模糊查询无法走索引,影响执行速度。经测试itpub版主ifree的index_ffs+rowid方法比较有效,记录一下。
这里是示例:
scott@ORCL> CREATE INDEX SCOTT.i_dept_name
2 ON SCOTT.DEPT(DNAME)
3 ;Index created.
scott@ORCL> Analyze Table SCOTT.DEPT Compute Statistics ;
Table analyzed.
scott@ORCL> select * from scott.dept where
2 rowid in (
3 select /*+ index_ffs(a i_dept_dname) */
4 rowid from scott.dept a where dname like '%A%')
5 ;这个方法要求like查询出的记录不能太多,在我的应用中,这一方法使sql效率提高了近10倍。
Blogged with the Flock BrowserTags: sql, 优化, turning, like, 模糊查询
Related posts:

Leave a comment | Trackback 这篇文章还没有评论.