[IMP] account,*: performance on Foreign Keys
On deletion of records, foreign keys are updated. For larger tables (like account.move, account.bank.statement.line) this could take some time. adding a "not null btree index" on sparsely populated many2one fields significantly improves performance. In the analysis of deleting a bank statement line. Before: 7.4s to delete the bank statement line (missing index on suspense_statement_line_id consuming 99% of the execution time) 3.8s to delete the corresponding account move After: With the indexes, a 700x performance improvement was found. This opportunity is taken to add an index on all many2one fields to account.move & bank.statement.line. Issue report by @tsb-odoo closes odoo/odoo#145643 X-original-commit: f10b87991cc72f5e16b587b6c9ede7e338ec79ac Related: odoo/enterprise#52466 Signed-off-by: William André (wan) <wan@odoo.com> Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
This commit is contained in:
@@ -44,6 +44,7 @@ class AccountBankStatementLine(models.Model):
|
||||
comodel_name='account.move',
|
||||
auto_join=True,
|
||||
string='Journal Entry', required=True, readonly=True, ondelete='cascade',
|
||||
index='btree_not_null',
|
||||
check_company=True)
|
||||
statement_id = fields.Many2one(
|
||||
comodel_name='account.bank.statement',
|
||||
|
||||
@@ -174,6 +174,7 @@ class AccountMove(models.Model):
|
||||
string="Statement Line",
|
||||
copy=False,
|
||||
check_company=True,
|
||||
index='btree_not_null',
|
||||
)
|
||||
statement_id = fields.Many2one(
|
||||
related="statement_line_id.statement_id"
|
||||
@@ -226,6 +227,7 @@ class AccountMove(models.Model):
|
||||
comodel_name='account.move',
|
||||
string='First recurring entry',
|
||||
readonly=True, copy=False,
|
||||
index='btree_not_null',
|
||||
)
|
||||
hide_post_button = fields.Boolean(compute='_compute_hide_post_button', readonly=True)
|
||||
to_check = fields.Boolean(
|
||||
|
||||
@@ -19,7 +19,7 @@ class AccountPartialReconcile(models.Model):
|
||||
full_reconcile_id = fields.Many2one(
|
||||
comodel_name='account.full.reconcile',
|
||||
string="Full Reconcile", copy=False)
|
||||
exchange_move_id = fields.Many2one(comodel_name='account.move')
|
||||
exchange_move_id = fields.Many2one(comodel_name='account.move', index='btree_not_null')
|
||||
|
||||
# ==== Currency fields ====
|
||||
company_currency_id = fields.Many2one(
|
||||
|
||||
@@ -16,6 +16,7 @@ class AccountPayment(models.Model):
|
||||
move_id = fields.Many2one(
|
||||
comodel_name='account.move',
|
||||
string='Journal Entry', required=True, readonly=True, ondelete='cascade',
|
||||
index='btree_not_null',
|
||||
check_company=True)
|
||||
|
||||
is_reconciled = fields.Boolean(string="Is Reconciled", store=True,
|
||||
|
||||
@@ -6,7 +6,7 @@ from odoo import models, fields, api, _
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
debit_origin_id = fields.Many2one('account.move', 'Original Invoice Debited', readonly=True, copy=False)
|
||||
debit_origin_id = fields.Many2one('account.move', 'Original Invoice Debited', readonly=True, copy=False, index='btree_not_null')
|
||||
debit_note_ids = fields.One2many('account.move', 'debit_origin_id', 'Debit Notes',
|
||||
help="The debit notes created for this invoice")
|
||||
debit_note_count = fields.Integer('Number of Debit Notes', compute='_compute_debit_count')
|
||||
|
||||
@@ -18,7 +18,7 @@ class AccountEdiDocument(models.Model):
|
||||
_description = 'Electronic Document for an account.move'
|
||||
|
||||
# == Stored fields ==
|
||||
move_id = fields.Many2one('account.move', required=True, ondelete='cascade')
|
||||
move_id = fields.Many2one('account.move', required=True, ondelete='cascade', index='btree_not_null')
|
||||
edi_format_id = fields.Many2one('account.edi.format', required=True)
|
||||
attachment_id = fields.Many2one(
|
||||
comodel_name='ir.attachment',
|
||||
|
||||
@@ -22,7 +22,7 @@ class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
l10n_id_tax_number = fields.Char(string="Tax Number", copy=False)
|
||||
l10n_id_replace_invoice_id = fields.Many2one('account.move', string="Replace Invoice", domain="['|', '&', '&', ('state', '=', 'posted'), ('partner_id', '=', partner_id), ('reversal_move_id', '!=', False), ('state', '=', 'cancel')]", copy=False)
|
||||
l10n_id_replace_invoice_id = fields.Many2one('account.move', string="Replace Invoice", domain="['|', '&', '&', ('state', '=', 'posted'), ('partner_id', '=', partner_id), ('reversal_move_id', '!=', False), ('state', '=', 'cancel')]", copy=False, index='btree_not_null')
|
||||
l10n_id_attachment_id = fields.Many2one('ir.attachment', readonly=True, copy=False)
|
||||
l10n_id_csv_created = fields.Boolean('CSV Created', compute='_compute_csv_created', copy=False)
|
||||
l10n_id_kode_transaksi = fields.Selection([
|
||||
|
||||
@@ -24,7 +24,7 @@ class AccountAnalyticLine(models.Model):
|
||||
timesheet_invoice_type = fields.Selection(TIMESHEET_INVOICE_TYPES, string="Billable Type",
|
||||
compute='_compute_timesheet_invoice_type', compute_sudo=True, store=True, readonly=True)
|
||||
commercial_partner_id = fields.Many2one('res.partner', compute="_compute_commercial_partner")
|
||||
timesheet_invoice_id = fields.Many2one('account.move', string="Invoice", readonly=True, copy=False, help="Invoice created from the timesheet")
|
||||
timesheet_invoice_id = fields.Many2one('account.move', string="Invoice", readonly=True, copy=False, help="Invoice created from the timesheet", index='btree_not_null')
|
||||
so_line = fields.Many2one(compute="_compute_so_line", store=True, readonly=False,
|
||||
help="Sales order item to which the time spent will be added in order to be invoiced to your customer. Remove the sales order item for the timesheet entry to be non-billable.")
|
||||
# we needed to store it only in order to be able to groupby in the portal
|
||||
|
||||
@@ -62,6 +62,7 @@ class StockLandedCost(models.Model):
|
||||
copy=False, readonly=True, tracking=True)
|
||||
account_move_id = fields.Many2one(
|
||||
'account.move', 'Journal Entry',
|
||||
index='btree_not_null',
|
||||
copy=False, readonly=True)
|
||||
account_journal_id = fields.Many2one(
|
||||
'account.journal', 'Account Journal',
|
||||
|
||||
Reference in New Issue
Block a user