2

私はOracle 10gR2に取り組んでいます

テーブル TBL_CUSTOMER の MERGE ステートメントがあります。TBL_CUSTOMER には、メール アドレスを含む列 USERNAME が含まれています。このテーブルに格納されているデータは、大文字、小文字、または大文字と小文字の任意の組み合わせを受信データに使用できるため、大文字と小文字が区別されません。

データをマージするときは、大文字と小文字を区別せずにデータを比較する必要があります。UPPER(USERNAME) として USERNAME 列に関数ベースのインデックスを作成しました。

MERGE INTO tbl_customer t
      USING (SELECT /*+ dynamic_sampling(a 2) */  NVL(
                                                      (x.username||decode((x.cnt+x.rn-1),0,null,(x.cnt+x.rn-1))),
                                                      t1.cust_username
                                                     ) community_id
                               ,DECODE (source_system_name,'SYS1', t1.cust_firstname,t1.cust_username) display_name
                               ,t1.cust_username
                              ,t1.cust_id cust_id
                              ,t1.cust_account_no cust_account_no
                              ,t1.cust_creation_date
                              ,t1.source_system_name
                              ,t1.seq_no
                              ,nvl(t1.cust_email,'NULLEMAIL') cust_email
                              ,t1.file_name
                              ,t1.diakey
                              ,t1.sourcetupleidcustmer
                              ,DECODE (source_system_name,'SYS1','DefaultPassword',t1.cust_password) cust_password
             FROM   gtt_customer_data t1,
                    (SELECT a.username,
                            cust_id,
                            row_number() over(partition by lower(a.username) order by  seq_no) rn,
                            (SELECT count(community_id)FROM TBL_customer where regexp_like (lower(community_id) ,'^'||lower(a.username)||'[0-9]*$'))cnt
                     FROM   gtt_cust_count_name a  
                    ) x
             WHERE  t1.cust_status = 'A'
             AND    x.cust_id(+)  = t1.cust_id
             AND    nvl(t1.op_code,'X') <> 'D'
             AND    t1.cust_id is not null
             AND    cust_email is not null
            ) a
      ON    ( 
             (a.sourcetupleidcustmer = t.source_tuple_id AND a.source_system_name =t.created_by)
             OR 
             ( upper(a.cust_email) = upper(t.username) AND a.source_system_name ='SYS2' )
            )

実行計画を確認すると、USERNAME の関数ベースのインデックスが使用されていません。OR 条件を削除すると、インデックスが使用されることに気付きましたが、ビジネス ロジックが複雑なため、それを削除することはできません。

そのインデックスを強制的に使用するにはどうすればよいですか?

4

1 に答える 1

2

Oracle では、関数ベースのインデックスを作成できますupper(username)。クエリでヒントを試すこともできINDEXますが、あなたの場合、関数ベースのインデックスの方がはるかに優れたソリューションだと思います。

通常、インデックス フィールドが関数の引数である場合、BTree インデックスは使用されません (関数がWHEREカバリング インデックスではない場合)。たとえば、 ではWHERE trunc(date_field) = trunc(sysdate())index on を使用しませんが、 index ondate_fieldを使用します(trunc(date_field))

于 2011-11-18T16:54:18.960 に答える