
Originally Posted by
Ryan Mortier
I seem to be getting confused on how it knows which foreign key is the "first name" or "last name".
sorry to have confused you
let's use your example instead of firstname and lastname
here's the sample data --
Code:
category_id commodity_id
36 20453
42 20735
26 20876
55 20945
15 20784
25 20599
33 20594
26 20735
okay, now let's look at your indexes
the first index, the composite index, looks like this --
Code:
category_id commodity_id
15 20784
25 20599
26 20735
26 20876
33 20594
36 20453
42 20735
55 20945
naturally, an index also contains a pointer (not shown) which identifies where these rows are on the disk
the second index, the one on commodities, looks like this --
Code:
commodity_id
20453
20594
20599
20735
20784
20876
20945
again, each index entry contains a pointer to where the row is on the disk
finally, the third index --
Code:
category_id
15
25
26
33
36
42
55
thus, if you were going to write a query to return something for a specific category, you could use either the first index (the composite one) or the third one
the second index is ~not~ redundant, because neither the first one nor the third one can be used to find a specific commodity
Bookmarks