Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.1

Re-indexing my Rails DB


I understand the basics of how indexing helps boost performance, and how to index my DB, but Im confused about how often to re-index. Also, when I re-index my database, do I need ot first removed the initial index, or can I just re-index as if I am indexing for the first time.


Solution

  • This is not a rails question its a DBMS question. What, where, when and how you re-index depends on your database DBMS but as a general rule re indexing is rarely needed unless there is database corruption of some description or you have a massive amount of changes to data that is included in the indexes. By changes I mean updates and deletes.

    For example if you use Postgres then this link might help http://www.postgresql.org/docs/9.1/static/routine-reindex.html. Also have a look through stackexchange. Questions and answers like this https://dba.stackexchange.com/questions/1937/is-reindex-dangerous may enlighten you.

    If you use MySQL then this is a very good explanation http://dev.mysql.com/doc/refman/5.0/en/rebuilding-tables.html

    Lookup whatever DBMS you are using and check the official documentation on how and when to re-index. The requirement to re-index is also likely to be different depending on the table types used like InnoDB and MyISAM for MySQL may well have different requirements and csv may well not have any indexing at all