This question has been flagged
1 Reply
6404 Views

We are going to add some indexes to certain fields (Odoo 10). But I'm not 100% sure that this is the best approach. So currently I'm inheriting for example sale.order.line to add an index to product_id.  Any side effect to this? If I uninstall the module it will not remove the field (that's good) but the index will stay. 

class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

product_id = fields.Many2one('product.product', string='Product', domain=[('sale_ok', '=', True)], change_default=True, ondelete='restrict', required=True, index=True)
Avatar
Discard

I would love to know the answer to this question. I, too, am considering adding an index to a core field.

nobody answered until now on this ? I don't understand why Odoo didn't add indexes on a lot of ID fields as well, so I want to do this at least for a couple of them ...

Best Answer

database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space to maintain the index data structure. Indexes are used to quickly locate data without having to search every row in a database table every time said table is accessed. Indexes can be created using one or more columns of a database table, providing the basis for both rapid random lookups and efficient access of ordered records.


Indexes are a common way to enhance database performance. An index allows the database server to find and retrieve specific rows much faster than it could do without an index. But indexes also add overhead to the database system as a whole, so they should be used sensibly.


Avatar
Discard