【问题标题】:Oracle catsearch and CTXSYS.CTXCAT index are not working as expectedOracle catsearch 和 CTXSYS.CTXCAT 索引未按预期工作
【发布时间】:2017-06-14 13:39:25
【问题描述】:

我在 Oracle 数据库中有一张表,其中包含数百万条记录, 在这张表上正在执行的 DML 命令主要是 INSERT(没有 DELETE / UPDATE), 此表正在由特定列上的文本参数查询, 我尝试通过添加 CTXSYS.CTXCAT 索引来调整此查询的性能,并使用如下 catsearch 函数, 但实际上 catsearch 函数并没有返回预期的结果:

--首先,创建一个带有dept列和一个随机搜索字符串的emp表

create table emp as
select rownum id , 'Employee ' || to_char(rownum) name , MOD(rownum,20) + 1 dept , dbms_random.string('A', 50) search_string
from dual
connect by level <= 1000000;

-- 然后,创建 2 个索引 - 一个用于 catsearch 函数,另一个用于常规索引

begin
  ctx_ddl.create_index_set('emp_iset');
  ctx_ddl.add_index('emp_iset','dept'); /* sub-index A */
end;

CREATE INDEX EMP_FULLTEXT_IDX ON emp(search_string) 
  INDEXTYPE IS CTXSYS.CTXCAT 
  PARAMETERS ('index set emp_iset');

create index emp_search_string_idx on emp(search_string);

现在,我希望以下查询将返回相同的结果,但不幸的是,它们不会:

select count(*) from emp where dept = 10 and lower(search_string) like '%test%';

select count(*) from emp where catsearch(search_string, 'test', 'dept = 10') > 0;

此外,查询的 2 个选项之间的减号查询返回一些结果:

select * from emp where dept = 10 and lower(search_string) like '%test%'
minus
select * from emp where catsearch(search_string, 'test', 'dept = 10') > 0;

我尝试查找 catsearch 函数和 CTXSYS.CTXCAT 索引的文档,但还没有运气, 任何帮助将不胜感激。

【问题讨论】:

    标签: oracle indexing plsql


    【解决方案1】:

    您可以使用通配符。

    select count(*) from emp where catsearch(search_string, '**test*', 'dept = 10') > 0;
    

    【讨论】:

      猜你喜欢
      • 2014-05-29
      • 2020-08-06
      • 1970-01-01
      • 2023-02-22
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 2013-08-06
      • 2013-06-02
      相关资源
      最近更新 更多