我想創建一個基於應用函數的結果的索引,我必須提取一個數字。如何制定確定性功能?
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