If I have a table with a multi-column index (OrderId, OrderType) and my where clause is using the first column of the index, is the index useful?
Is the index slightly less efficient than if I had an index(OrderId), perhaps where there's a very large number of rows?
My understanding is the multicolumn index is useful when using where criteria on the first column, even if I'm not returning the second column in select or using in where. However, my experience with Oracle is less than other DB engines, and I've been told the multi-column index is not used unless I'm referencing both columns in my query. Additionally, a plan analyzer is recommending creating the single column index on OrderId, when there's already a index(OrderId, OrderType). So it feels like creating a single column index(OrderId) is redundant.
Not looking to analyze my query. Just trying to establish whether I'm misunderstanding something fundamental with multicolumn indexes in Oracle.
Asked another way:
If I already have index (OrderId, OrderType), would there ever be a situation where it would be beneficial to also create a index (OrderId)?
select OrderId, Amount
from Orders
where OrderDate > i_startSearchDate and OrderDate < i_endSearchDate
and OrderId in (
select OrderFk from Items where ItemType = 1
);