What are some best practises and "rules of thumb" for creating database indexes?

Posted by Ash on Stack Overflow See other posts from Stack Overflow or by Ash
Published on 2009-03-26T23:55:10Z Indexed on 2010/05/20 22:50 UTC
Read the original article Hit count: 321

I have an app, which cycles through a huge number of records in a database table and performs a number of SQL and .Net operations on records within that database (currently I am using Castle.ActiveRecord on PostgreSQL).

I added some basic btree indexes on a couple of the feilds, and as you would expect, the peformance of the SQL operations increased substantially. Wanting to make the most of dbms performance I want to make some better educated choices about what I should index on all my projects.

I understand that there is a detrement to performance when doing inserts (as the database needs to update the index, as well as the data), but what suggestions and best practices should I consider with creating database indexes? How do I best select the feilds/combination of fields for a set of database indexes (rules of thumb)?

Also, how do I best select which index to use as a clustered index? And when it comes to the access method, under what conditions should I use a btree over a hash or a gist or a gin (what are they anyway?).

© Stack Overflow or respective owner

Related posts about database-design

Related posts about database