Can someone give me any insight into how to go about using indexes in MySQL?
I use php/mysql to run my illustration agency's website (have a look if you want). The user can currently select keywords from five select boxes (artist, subject ,etc) and return pages of thumbnails.
The site works fine (we've had a lot of positive comment in the industry), but there are getting to be quite a lot of images on the site now, and I think it's needs some tuning up.
I know pretty much nothing about indexes :bemused: except primary keys. I have a couple of books, have read some tutorials, but can't seem to get a good 'handle' on them. I usually find how to implement them, but not where or when.
Has any one got any good ways to explain how I can use them (effectively)?
For example, is there a way I could speed things up using indexes on the scheme below?
Suppose we only were considering the following relationships (I've tried to simplify it down to the essentials for this question ... they are more involved than this!!) ...
Each artist can have many images
Each image has only one artist
Each image can have many subjects
Each subject can have many images
[/list=1]
So, I've got the following tables ...
artist: id (p), name
image: id (p), artist_id (f)
subject: id (p), value
image_subject: image_id (f), subject_id (f)
... where (p) means primary and (f) means foreign.
Then, given a user selecting subject no. 24 (car) from the selection box, I would use the following simply SQL query to get the thumbnail id's.
SELECT image.id, artist.name
FROM image, image_subject, artist
WHERE image.artist_id = artist.id
AND image.id = image_subject.image_id
AND image_subject.subject_id = 24
ORDER BY img_id
(Notice I don't use the subject table directly in this query, but do for others).
So, would indexes help me at all? What sort? Should I apply them to the 'name'/'value' fields or the foriegn fields, or both?
If more info is needed, let me know.
Cheers,
Paul.