I've read that in composite indexes, you should order the columns with the most specific first, however my thought is that the most optimal route would be for least specific indexes to be covered first due to my understanding (or lack there of) on how mapping over indexes would work in memory. visual aid
For example, if I have a table, vehicles
with three columns, vehicle
, type
and driver
.
vehicle
can be filtered to 3 possible values car
, bike
, helicopter
type
can be filtered to 6 values, petrol/automatic
, petrol/manual
, diesel/automatic
, diesel/manual
,, electric/automatic
, electric/manual
driver
is the driver's name (an indeterminate number of values)
--
If filtering by vehicle
can return 1000 results, by type
500 results, and by driver
say, 3 results, shouldn't the optimal index be vehicle, type, driver
? Because if the index is starts with driver
wouldn't that mean scanning over a giant index before further filtering by type
then vehicle
?
Could someone please clear this up for me, and explain to me, if I should order columns with the most specific first, why, and how it works?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…