我正在开发 Oracle 10gR2
我有一个表 TBL_CUSTOMER 的 MERGE 语句。TBL_CUSTOMER 包含一列 USERNAME,其中包含电子邮件地址。此表中存储的数据不区分大小写,如传入数据可以是大写、小写或任意大小写组合。
在合并数据时,我必须确保在不考虑大小写的情况下比较数据。我已经创建了一个基于 USERNAME 列的函数索引作为 UPPER(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 条件,则使用索引,但由于复杂的业务逻辑,我无法删除它。
如何强制使用该索引?