views:

243

answers:

3

Hi guys,

I know PRIMARY key is to have unique value, what about INDEX? What is the function of a table column with INDEX?

+5  A: 

INDEX columns are exactly that. They're indexed to make it faster to look up information using that column. MySQL typically stores Indexes in B-Trees or R-Trees. An appropriate case for the use of an index would be if you're using a where clause on a particular column (or group of columns) regularly.

Indexes are a topic worthy of whole chapters in database books, a good place to start looking for more information might be the mysql reference manual.

Vertis
It might be appropriate to point out that "faster" in this context can mean "a hell of a lot faster."
Ori Pessach
And by 'a hell of a lot faster' can often mean a hundred or a thousand or even a million times faster. Seriously!
staticsan
If my data is not very huge, should I still use index??
roa3
Yes, with indexes selects will be a lot faster. In order to find an item using index database will not read all data. It'll just look in index and read the item you need.
zihotki
+1  A: 

Please look at this good description of indexes in databases

zihotki
+1  A: 

An INDEX in MySQL, performs the same kind of function an INDEX does at the end of a book. It enables faster lookup for your information when you do a query like:

SELECT * FROM MY-DB-WITH-INDEXES> WHERE <INDEX_FIELD=foo_bar>

Good choice of the columns used to form an index always makes a good database design.

Amit