I understand that a multi-column index is required and that index order matters in requests such as
SELECT product_id
FROM order_detail
WHERE order_id in (1, 2, 3)
However, I can't figure out the necessity of multi-column indexes and index order when there is no value in the WHERE
clause.
I believe multi-column index is only used when a value is specified in the WHERE clause (I may be wrong). Therefore, in order to "optimize" the table order_detail and for the request below, should I create a multi-column index on product_id and order_id or should I create two separate indexes, one on order_id and one on product_id:
SELECT O.order_id, P.product_name FROM order_detail OD, order O, product P WHERE OD.order_id = O.order_id AND P.product_id = OD.product_id
If a multi-column index is still required when search is proceeded on two columns in the
WHERE
clause even if there is no value in it, what is the proper order to give to the multi column index then? Regarding the example above for the table order_detail, should I use (order_id, product_id) or should I use (product_id, order_id)? Does the order matter when there is no value in theWHERE
clause?
Many thanks for your help.