[FIX] base: speedup access rights check query
Since #84736 the access right check queries were merged into one Unfortunately the query plan for cases of a group with tons of users can be suboptimal. Using a subselect will force the query plan in order to avoid an index only scan on res_groups_users_rel. Performances where tested in production, this new query being around 300 and 1000 times faster for two tests cases (res.partner and account.payment.term) closes odoo/odoo#99747 X-original-commit: c7f6a88466878698a78ba26ceeb18247df6dc955 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
This commit is contained in:
@@ -1772,10 +1772,18 @@ class IrModelAccess(models.Model):
|
||||
self._cr.execute("""SELECT BOOL_OR(perm_{mode})
|
||||
FROM ir_model_access a
|
||||
JOIN ir_model m ON (m.id = a.model_id)
|
||||
LEFT JOIN res_groups_users_rel gu ON (gu.gid = a.group_id)
|
||||
WHERE m.model = %s
|
||||
AND (a.group_id IS NULL OR gu.uid = %s)
|
||||
AND a.active IS TRUE""".format(mode=mode),
|
||||
AND a.active IS TRUE
|
||||
AND (
|
||||
a.group_id IS NULL OR
|
||||
-- use subselect fo force a better query plan. See #99695 --
|
||||
a.group_id IN (
|
||||
SELECT gu.gid
|
||||
FROM res_groups_users_rel gu
|
||||
WHERE gu.uid = %s
|
||||
)
|
||||
)
|
||||
""".format(mode=mode),
|
||||
(model, self._uid,))
|
||||
r = self._cr.fetchone()[0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user