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 performance 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?).
What are two rules of thumb for choosing indexes for relational databases? Index ALL primary keys; Index ALL foreign keys columns; Create more indexes ONLY if: 1)Queries are slow and 2) data volume is going to increase significantly. Consider indexing columns frequently used in Where clauses and for joins.
1) Record of key (only primary index) 2) Key and pointer to record of key. 3) Key and list of pointers to the records containing the key (for non-unique keys). keys (B) in every disk block.
Some of my rules of thumb:
If a query is slow, look at the execution plan and:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With