Does Oracle have a filtered index concept?

后端 未结 4 1881
慢半拍i
慢半拍i 2020-12-10 13:29

Similar to SQLServer where I can do the following

create index TimeSeriesPeriodSs1 on TimeSeriesPeriod (validationStatus, completionStatus)
where completionS         


        
4条回答
  •  一个人的身影
    2020-12-10 13:48

    You might be able to use a function-based index for this, though it isn't very pleasant for this scenario:

    create index TimeSeriesPeriodSs1 on TimeSeriesPeriod (
        case when validationStatus= N'Pending' and completionStatus= N'Complete' then validationStatus else null end,
        case when validationStatus= N'Pending' and completionStatus= N'Complete' then completionStatus else null end);
    

    You'd have to make the query's where clause match exactly to make it use the index though.

    select 
    from TimeSeriesPeriod
    where case when validationStatus= N'Pending' and completionStatus= N'Complete' then validationStatus else null end = N'Pending'
    and case when validationStatus= N'Pending' and completionStatus= N'Complete' then completionStatus else null end = N'Complete';
    

    This would be a lot neater if you can define (deterministic) functions to do the case. See here for some further info and examples. Or this, from a quick Google.

提交回复
热议问题