我想创建一个基于应用函数的结果的索引,我必须提取一个数字。如何制定确定性功能?
Example String: ...someText...&idDocunet=799493...someText...
[799493] <- Note the number
The function: replace(regexp_substr(parametros, '&idDocunet=\d+'), 'idDocunet=', NULL)
The index: create index example on MY_TABLE (replace(regexp_substr(parametros, '&idDocunet=\d+'), 'idDocunet=', NULL));
但是当我运行此查询:
SELECT *
FROM my_table
WHERE replace(regexp_substr(parametros, '&idDocunet=\d+'), 'idDocunet=', NULL) IS NOT NULL.
或者这一个
SELECT *
FROM my_table
WHERE replace(regexp_substr(parametros, '&idDocunet=\d+'), 'idDocunet=', NULL) = 799493
或作出加入...
索引不使用,它执行每次都进行全表扫描。我相信索引是确定性的,因为它总是会返回数字,或者为null,但我不知道表达式是否太复杂以至于无法使用。我也尝试将代码移到一个函数中,但它是一样的。我相信关键在于这个确定性的东西(我做错了吗?)和/或原始列上具有空值的表。我怎样才能保证索引被使用?这是功能:
create or replace function extraer_doc_id(viParam VARCHAR2) return varchar2 is
begin
RETURN replace(regexp_substr(viParam, '&idDocunet=\d+'), 'idDocunet=', NULL);
end extraer_doc_id;
我也执行该
ANALYZE TABLE my_table COMPUTE STATISTICS;
但它似乎并不重要。
嗨,对于“parametros”的事情,我忘了更新这个例子,当我用“my_column”在这里写的时候,我真的用同样的函数测试过,但索引没有被使用。我将用我的函数中的确定性子句进行测试,但它应该与查询一起工作,对吧? – Roger