Jump to content

phpMyAdmin / MySQL Indexes


johnsmith153

Recommended Posts

If I had a table with 15 fields (so it is worth creating an index) and I currently have an auto-incremented 'uid' field as the Primary Key, which of the fields below (if any) would I create an index on?

 

I would like an answer so I can test my knowledge of indexes.

 

(1) 15 fields total, some of which are Name, Username, Password, uid (primary key) etc. (index would be worth creating as lots of other fields)

 

(2) I regularly do:

SELECT Username FROM table WHERE uid='$_POST["username"]' && Password='$_POST["Password"]'

 

So what index should I create?

 

This is just a test. If it was a users' table you probably wouldn't have 15 fields etc.

 

I would normally escape data and structure the SQL query fully of course.

 

Please don't guess at the answer. I would rather have no answers than wrong ones. Thanks anyway.

Link to comment
https://forums.phpfreaks.com/topic/208591-phpmyadmin-mysql-indexes/
Share on other sites

You should create such indexes, that will bring benefits for your queries. There's no point creating an index for each field in a table, because many of them will never be used. In your case if the table is InnoDB, then a multi-column index created on (Username,Password) might yield really good results. Also a multi-column index on (uid, Password) is worth trying out.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.