I want to creating a website where users can sign up in website and upload 20 images to their account. (planning to allow users to upload unlimited images in future)
I have two tables in database.
One for keeping user data
Table name – members
Fields- userid, username, password, email.
Other for saving image path
Table name- images
Fields – userid, imagepath
So I can display images of a user in his page searching image path from table ‘images’
Things are working fine. But if the number of users grow this will become slower.
For example – If there is 50000 users I should check all the rows to find images uploaded by a single user
ie;
50000 userid * 20 images/user = 1000000 scans for table rows
This will make the system slow and make overload.
What I should do to avoid this?
Create index on userid field in second table.
Syntax:
http://dev.mysql.com/doc/refman/5.0/en/create-index.html
What are the biggest benefits of using INDEXES in mysql?