← Back to team overview

openerp-expert-framework team mailing list archive

Re: Database indexes for foreign keys

 

On 04/16/2014 03:23 PM, Alexandre Fayolle wrote:
Hello,

I came across this while analyzing pg logs with pgbadger : postgreSQL
does not automatically create indexes for foreign key columns, and I was
surprised when I noticed that the ORM in OpenERP does not do this by
default. Has anyone been doing some analysis on this and concluded that
manual creation of such indexes was the correct thing to do because the
read-time gains were nullified by the write-time costs ?

Sometimes I had to manually create indexes for foreign keys, especially when pg logs reported very slow queries.
This increased the performances.



My gut feeling is that in most cases we want such index to be created,
and that select should default to True for m2o fields (and then we could
always explicitely disable index creation for the few fields for which
this would cause harm).

In general, the queries based on foreign keys (like JOIN) are very selective, so it is advised to have indexes on them.

So, +1


--
Lorenzo Battistini
Tel (CH): +41 91 210 23 40
Tel (IT): +39 011 198 25481
http://www.agilebg.com



References