How do I efficiently sort videos that users have uploaded?
I am storing the actual videos in a separate file, and their info in a MySQL database.
Say I want to sort by “date uploaded”, how do I go about doing this?
I have a column for date uploaded. There could potentially be millions of records to sort, but I will only probably display the top 10 on the website.
It’s better and faster to just select the fields you need:
Make sure you put an index on
date_uploaded.If you use InnoDB, put an index on filenames as well, because then InnoDB can use a covering index and does not need to read the database itself.
Links:
http://dev.mysql.com/doc/refman/5.5/en/select.html
http://php.about.com/od/mysqlcommands/g/Limit_sql.htm
http://dev.mysql.com/doc/refman/5.5/en/mysql-indexes.html
http://www.mysqlperformanceblog.com/2006/11/23/covering-index-and-prefix-indexes/