数値を抽出する必要がある列に関数を適用した結果に基づいてインデックスを作成しようとしています。
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を返すため、決定論的であると思いますが、式が複雑すぎて使用できないかどうかはわかりません。コードを関数に移動しようとしましたが、同じです。キーはこの決定論的なもの(間違っていますか?)および/または元の列に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;
しかし、それは問題ではないようです。