I have asked questions about what is best approach to create a search system without libraries such as lucene, sphinx, solr, etc.
People keep on telling me things like you can create an index, that I can emulate indexing inside mysql using dedicated table for index, that searching through many tables is not a good idea. much better to have an index. index can be a single structured database table or external engine like sphinx or lucene which I won’t use.
Please explain me what actually does indexing mean? I just know that I should assign PRIMARY KEY for ID and make it auto increment, PRIMARY KEY will make it UNIQUE so ID numbers won’t be same. Are these index-es that people telling me directly associated with INDEX next to PRIMARY KEY or what?
I could never find an explanation anywhere in internet, so I’d be very thankful if somebody helps me out.
MySQL is really just a very complex and powerful string parsing engine at the end of the day. All of the data you send it is stored as a string-like value in a file. MySQL is built in C and that is what manages the processing to do all of the queries that you run.
An index is a list of the data in a table of yours mapped in a different manner than the mapping of a primary ID. The basic goal of an index is to allow the MySQL engine you are using to search your table much more quickly. This is because in practice an index is able to rule out huge sections of your table where it is known the records your looking for do not exist. A Primary Key is an index of the id value, but you can create indexes on arbitrary columns as followed:
A table can have multiple indexes on it for different things and that is okay. Often you will find that you are referencing a table by different values and maybe you will want to create an index for each of those. It is important to index wisely as it is possible that indexing the wrong columns will slow your queries down. You will have to read this entire link to gain a good understanding of what is going on, but remember an index is basically a file that allows lookups via a column in one of your tables to happen more quickly:
http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html