If I have
Select *
from tbl_x x
left join tbl_y y on x.a = y.a
where y.b = 'iwantthisvalue'
should I create separate index for each idx(y.a) and idx2(y.b) or should I create only one with 2 columns idx(y.a, y.b)?
If I have
Select *
from tbl_x x
left join tbl_y y on x.a = y.a
where y.b = 'iwantthisvalue'
should I create separate index for each idx(y.a) and idx2(y.b) or should I create only one with 2 columns idx(y.a, y.b)?
If there are multiple rows with same value in y.a
and multiple rows with same value in y.b
- you can create one index for both create index on y(a asc, b asc)
. The executor will look up first for join
and then for where
in joined result. If there are aggregate functions in select
- add other columns in include
of the index. The group by
columns could also be "added" (not "included") to the index if it is used in the query. So the executor will look up for join
after that for where
, for group by
and for select
of "included".